提交 0d147b3d authored 作者: 贺阳's avatar 贺阳

翻译

上级 91014d40
差异被折叠。
# 导入odoo
# 导入日志
import json
import logging
from datetime import timedelta
import base64
import io
import json
import logging
import zipfile
from datetime import timedelta
import pytz
from odoo import models, fields, api, _
......@@ -740,11 +740,14 @@ class CcBL(models.Model):
'sync_match_node': True
})
wizard_obj.confirm()
def _get_pod_files(self):
fix_name = '尾程交接POD(待大包数量和箱号)'
res = []
for bl in self:
files = self.env['cc.clearance.file'].sudo().search([('bl_id', '=', bl.id), ('file_name', '=', fix_name), ('file', '!=', False)])
files = self.env['cc.clearance.file'].sudo().search(
[('bl_id', '=', bl.id), ('file_name', '=', fix_name), ('file', '!=', False)])
files = files.filtered(lambda f: f.file not in (False, b'', ''))
if not files:
continue
total = len(files)
......@@ -765,7 +768,9 @@ class CcBL(models.Model):
return {'type': 'ir.actions.act_window_close'}
if len(self) == 1 and len(files) == 1:
name, data_b64 = files[0]
att = self.env['ir.attachment'].sudo().create({'name': name, 'datas': data_b64, 'res_model': 'cc.bl', 'res_id': self.id, 'mimetype': 'application/pdf'})
att = self.env['ir.attachment'].sudo().create(
{'name': name, 'datas': data_b64, 'res_model': 'cc.bl', 'res_id': self.id,
'mimetype': 'application/pdf'})
url = f"/web/content/ir.attachment/{att.id}/datas/{att.name}?download=true"
return {'type': 'ir.actions.act_url', 'url': url, 'target': 'self'}
buf = io.BytesIO()
......@@ -773,13 +778,12 @@ class CcBL(models.Model):
for name, data_b64 in files:
zf.writestr(name, base64.b64decode(data_b64))
datas = base64.b64encode(buf.getvalue())
att = self.env['ir.attachment'].sudo().create({'name': 'POD.zip', 'datas': datas, 'res_model': 'cc.bl', 'res_id': self[0].id, 'mimetype': 'application/zip'})
att = self.env['ir.attachment'].sudo().create(
{'name': 'POD.zip', 'datas': datas, 'res_model': 'cc.bl', 'res_id': self[0].id,
'mimetype': 'application/zip'})
url = f"/web/content/ir.attachment/{att.id}/datas/{att.name}?download=true"
return {'type': 'ir.actions.act_url', 'url': url, 'target': 'self'}
def action_package_pod(self, ids):
return self.browse(ids).action_download_pod()
# 增加一个can_cancel的方法,用于检查提单当前是否可以取消,返回True表示可以取消, False表示不可以取消,同时返回取消的原因
def check_cancel(self):
if self.is_cancel:
......@@ -1239,7 +1243,6 @@ class CcBL(models.Model):
'target': 'new'
}
def action_batch_download_pod(self):
"""
将选中的提单以提单号命名下载尾程交接POD文件,若文件有多个则以提单-1/-2进行命名下载,若选择多个提单,则将所有文件打包成zip,zip命名则以POD进行命名
......@@ -1249,13 +1252,13 @@ class CcBL(models.Model):
raise UserError(_('Please select at least one bill of loading.'))
# 检查是否有尾程交接POD文件
fix_name = '尾程交接POD(待大包数量和箱号)'
has_files = self.env['cc.clearance.file'].search_count([('bl_id', 'in', self.ids), ('file_name', '=', fix_name), ('file', '!=', False)])
has_files = self.env['cc.clearance.file'].search_count(
[('bl_id', 'in', self.ids), ('file_name', '=', fix_name), ('file', '!=', False)])
if not has_files:
raise UserError(_('Please configure the tail-end handover POD file of the bill of loading first.'))
return self.action_download_pod()
# 增加一个清关进度的业务对象,继承自models.Model, 用于管理业务数据.业务数据包括提单号、清关节点(业务对象)、进度日期、进度描述、更新人
class CcProgress(models.Model):
# 模型名称
......
......@@ -113,29 +113,22 @@ class BatchGetPodInfoWizard(models.TransientModel):
processed_files_data = fields.Text(string='已处理的文件数据', help='存储已处理的文件信息(JSON格式)')
def _get_bill_numbers(self, bl_objs):
# if self.action_type == '获取尾程POD信息':
# bl_objs = self.get_order()
# bill_numbers = [self.env['common.common'].sudo().process_match_str(bl.bl_no) for bl in bl_objs]
# else:
# bill_numbers = [self.env['common.common'].sudo().process_match_str(bl_no) for bl_no in
# self.bl_numbers.splitlines()]
_logger.info(f"开始预览操作,提单数量: {len(bl_objs)}")
# 调用接口获取提单pdf文件
pdf_file_arr = self._get_pdf_file_arr(bl_objs)
# 处理PDF文件,匹配提单对象
processed_files = self._match_bl_by_file_name(pdf_file_arr, bl_objs)
# 把没有匹配到文件的进行提示
error_bl = []
matched_bl_ids = [f['bl'].id for f in processed_files if f.get('bl')]
for bl in bl_objs:
if bl.id not in matched_bl_ids:
error_bl.append(bl.id)
error_bl.append(bl)
if error_bl:
logging.info('%s个提单无法找到release note文件' % len(error_bl))
if not self._context.get('is_skip_raise_error'):
self.show_error_message = _('%s bill of loading cannot find release note file') % (
', '.join(error_bl))
', '.join([bl.bl_no for bl in error_bl]))
return processed_files
def action_preview(self):
......@@ -143,6 +136,7 @@ class BatchGetPodInfoWizard(models.TransientModel):
预览操作:获取PDF、处理涂抹、合并PDF并显示
"""
action_type = self.action_type
self.show_error_message = False
try:
bl_objs = self.get_bl_objs() # 获取提单
# 处理PDF文件,匹配提单对象
......@@ -237,7 +231,8 @@ class BatchGetPodInfoWizard(models.TransientModel):
# 返回表单视图
return {
'type': 'ir.actions.act_window',
'name': _('Batch Get POD Info'),
'name': _('Batch Get POD Info') if action_type == '获取尾程POD信息' else _(
'Create TEMU Bill of Loading'),
'res_model': 'batch.get.pod.info.wizard',
'view_mode': 'form',
'res_id': self.id,
......@@ -258,47 +253,6 @@ class BatchGetPodInfoWizard(models.TransientModel):
'context': {'active_id': self._context.get('active_id', [])}
}
def get_bl_objs(self):
if self.action_type == '获取尾程POD信息':
bl_objs = self.get_order()
else:
raw_lines = [i.strip() for i in self.bl_numbers.splitlines() if i.strip()]
normalized_list = [self.env['common.common'].sudo().process_match_str(i) for i in raw_lines]
norm_to_raw = {}
for raw, norm in zip(raw_lines, normalized_list):
if norm not in norm_to_raw:
norm_to_raw[norm] = raw
normalized = sorted(set(normalized_list))
exist_set = set()
if normalized:
self._cr.execute(
"select UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
exist_set.update([r[0] for r in self._cr.fetchall()])
self._cr.execute(
"select UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) from cc_bl where transfer_bl_no is not null and UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
exist_set.update([r[0] for r in self._cr.fetchall()])
non_exist_norm = [n for n in normalized if n not in exist_set]
create_vals = [{
'customer_id': self.partner_id.id,
'bl_type': 'temu',
'bl_no': norm_to_raw[n]
} for n in non_exist_norm]
new_bl = self.env['cc.bl'].create(create_vals) if create_vals else self.env['cc.bl']
ids = []
if normalized:
self._cr.execute(
"select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
ids += [r[0] for r in self._cr.fetchall()]
self._cr.execute(
"select id from cc_bl where transfer_bl_no is not null and UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
ids += [r[0] for r in self._cr.fetchall()]
bl_objs = self.env['cc.bl'].browse(list(set(ids))) | new_bl
return bl_objs
def confirm(self):
"""
Confirm operation # 确认操作
......@@ -425,17 +379,58 @@ class BatchGetPodInfoWizard(models.TransientModel):
'context': {'default_show_error_message': self.show_error_message,
'active_id': bl_objs.ids if bl_objs else False}
}
if action_type == '创建TEMU提单':
if action_type == '创建temu提单':
return {
'type': 'ir.actions.act_window',
'res_model': 'cc.bl',
'name': _('TEMU Bill of Loading'),
'view_mode': 'list,form',
'domian': [('bl_type', '=', 'temu')],
'domain': [('bl_type', '=', 'temu')],
'context': {'default_bl_type': 'temu'},
'target': 'new',
'target': 'current',
}
def get_bl_objs(self):
if self.action_type == '获取尾程POD信息':
bl_objs = self.get_order()
else:
raw_lines = [i.strip() for i in self.bl_numbers.splitlines() if i.strip()]
normalized_list = [self.env['common.common'].sudo().process_match_str(i) for i in raw_lines]
norm_to_raw = {}
for raw, norm in zip(raw_lines, normalized_list):
if norm not in norm_to_raw:
norm_to_raw[norm] = raw
normalized = sorted(set(normalized_list))
exist_set = set()
if normalized:
self._cr.execute(
"select UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
exist_set.update([r[0] for r in self._cr.fetchall()])
self._cr.execute(
"select UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) from cc_bl where transfer_bl_no is not null and UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
exist_set.update([r[0] for r in self._cr.fetchall()])
non_exist_norm = [n for n in normalized if n not in exist_set]
create_vals = [{
'customer_id': self.partner_id.id,
'bl_type': 'temu',
'bl_no': norm_to_raw[n]
} for n in non_exist_norm]
new_bl = self.env['cc.bl'].create(create_vals) if create_vals else self.env['cc.bl']
ids = []
if normalized:
self._cr.execute(
"select id from cc_bl where UPPER(REPLACE(REPLACE(REPLACE(bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
ids += [r[0] for r in self._cr.fetchall()]
self._cr.execute(
"select id from cc_bl where transfer_bl_no is not null and UPPER(REPLACE(REPLACE(REPLACE(transfer_bl_no,' ', ''), '-', ''), '/', '')) in %s",
(tuple(normalized),))
ids += [r[0] for r in self._cr.fetchall()]
bl_objs = self.env['cc.bl'].browse(list(set(ids))) | new_bl
return bl_objs
def _validate_node_push_conditions(self, processed_files):
"""
验证节点推送条件
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论