提交 91014d40 authored 作者: 贺阳's avatar 贺阳

1、将选中的提单以提单号命名下载尾程交接POD文件,若文件有多个则以提单-1/-2进行命名下载,若选择多个提单,则将所有文件打包成zip,zip命名则以POD进行命名

2、预览和确认的优化
上级 ee754777
......@@ -3,6 +3,9 @@
import json
import logging
from datetime import timedelta
import base64
import io
import zipfile
import pytz
from odoo import models, fields, api, _
......@@ -737,6 +740,45 @@ 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)])
if not files:
continue
total = len(files)
idx = 0
for f in files:
idx += 1
base = bl.bl_no or str(bl.id)
ext = 'pdf'
if f.attachment_name and '.' in f.attachment_name:
ext = f.attachment_name.split('.')[-1]
name = f"{base}.{ext}" if total == 1 else f"{base}-{idx}.{ext}"
res.append((name, f.file))
return res
def action_download_pod(self):
files = self._get_pod_files()
if not files:
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'})
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()
with zipfile.ZipFile(buf, 'w', compression=zipfile.ZIP_DEFLATED) as zf:
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'})
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):
......@@ -1179,7 +1221,7 @@ class CcBL(models.Model):
'view_mode': 'form',
'res_model': 'batch.get.pod.info.wizard',
'context': {'active_id': self.ids, 'default_action_type': '获取尾程POD信息'},
'view_id': self.env.ref('ccs_base.view_batch_get_pod_info_wizard_form').id,
'views': [[self.env.ref('ccs_base.view_batch_get_pod_info_wizard_form').id, "form"]],
'target': 'new',
}
......@@ -1198,6 +1240,22 @@ class CcBL(models.Model):
}
def action_batch_download_pod(self):
"""
将选中的提单以提单号命名下载尾程交接POD文件,若文件有多个则以提单-1/-2进行命名下载,若选择多个提单,则将所有文件打包成zip,zip命名则以POD进行命名
"""
# 检查是否有选中的提单
if not self:
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)])
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):
# 模型名称
......
......@@ -329,7 +329,7 @@
<field name="res_model">cc.bl</field>
<field name="view_mode">tree,form,pivot,graph,calendar</field>
<field name="domain">[('bl_type','=','tk')]</field>
<field name="context">{'search_default_filter_state_not_finished':1}</field>
<field name="context">{'search_default_filter_state_not_finished':1,'default_bl_type':'tk'}</field>
<field name="view_id" ref="tree_cc_bl_view"/>
<field name="help" type="html">
<p>
......@@ -337,52 +337,12 @@
</field>
</record>
<!--
<record model="ir.ui.view" id="tree_temu_cc_bl_view">
<field name="name">tree.temu.cc.bl</field>
<field name="model">cc.bl</field>
<field name="arch" type="xml">
<tree string="Temu Bill of Loading" decoration-warning="is_cancel==True" js_class="cc_temu_bl_tree">
<field optional="show" name="state" string="Status" widget="badge" decoration-info="state=='draft'"
decoration-primary="state=='ccing'" decoration-success="state=='done'"/>
<field optional="show" name="customs_clearance_status" string="Customs Clearance Status"/>
<field optional="show" name="bl_no" string="Bill of Loading No."/>
<field optional="show" name="bl_date" string="B/L Date"/>
<field optional="show" name="last_mile_provider_ids" string="Last Mile Providers"
widget="many2many_tags"/>
<field optional="hide" name="transfer_bl_no" string="Transfer Bill of Loading No."/>
<field optional="show" name="customer_id" string="Customer"/>
<field optional="show" name="customs_bl_no" string="Customs Bill of Loading No."/>
<field optional="hide" name="big_package_sell_country" string="Sell Country"/>
<field optional="hide" name="billing_weight" string="Billing Weight"/>
<field optional="hide" name="actual_weight" string="Actual Weight"/>
<field optional="hide" name="big_package_qty" string="Big Package"/>
<field optional="hide" name="bl_total_big_qty" string="Receive Big Package"/>
<field optional="hide" name="bl_ship_package_qty" string="Receive Ship Package"/>
<field optional="hide" name="bl_total_qty" string="Receive Goods Qty"/>
<field optional="show" name="bl_total_amount" string="Total Amount"/>
<field optional="show" name="cc_company_id" string="CC Company"/>
<field optional="show" name="cc_country_id" string="CC Country"/>
<field optional="show" name="cc_deadline" string="CC Deadline"/>
<field optional="show" name="trade_type" string="Trade Type"/>
<field optional="hide" name="transport_tool_code" string="Transport Tool Code"/>
<field optional="hide" name="transport_tool_name" string="Transport Tool Name"/>
<field optional="show" name="start_port_code" string="Start Port Code"/>
<field optional="show" name="eta" string="ETA"/>
<field optional="show" name="end_port_code" string="End Port Code"/>
<field optional="show" name="etd" string="ETD"/>
<field optional="show" name="is_cancel" string="Is Cancel"/>
<field optional="hide" name="cancel_reason" string="Cancel Reason"/>
<field optional="show" name="create_date"/>
</tree>
</field>
</record> -->
<record model="ir.actions.act_window" id="action_temu_bl">
<field name="name">TEMU Bill of Loading</field>
<field name="res_model">cc.bl</field>
<field name="view_mode">tree,form,pivot,graph,calendar</field>
<field name="domain">[('bl_type','=','temu')]</field>
<field name="context">{'default_bl_type':'temu'}</field>
<field name="view_id" ref="tree_cc_bl_view"/>
<!-- <field name="view_id" ref="tree_temu_cc_bl_view"/> -->
<field name="context">{'search_default_filter_state_not_finished':1}</field>
......@@ -468,9 +428,9 @@
</record>
<!-- 批量创建temu提单 -->
<record id="bl_create_temu_bl_server_action" model="ir.actions.server">
<field name="name">Batch Create BL</field>
<!-- 下载POD -->
<record id="bl_download_pod_server_action" model="ir.actions.server">
<field name="name">Batch Download POD</field>
<field name="model_id" ref="model_cc_bl"/>
<field name="binding_model_id" ref="model_cc_bl"/>
<field name="state">code</field>
......@@ -478,7 +438,7 @@
<field name="groups_id" eval="[(4, ref('ccs_base.group_clearance_of_customs_user'))]"/>
<field name="code">
if records:
action = records.action_batch_get_pod_info()
action = records.action_batch_download_pod()
</field>
</record>
......
......@@ -131,7 +131,9 @@
<!-- 确认按钮:使用已处理的文件数据进行回写 -->
<!-- 如果有失败的文件(show_error_message不为空),需要勾选generate_successful_processed才显示;如果全部成功,直接显示 -->
<button string="Confirm" type="object" name="confirm" class="btn-primary"
attrs="{'invisible': ['|', ('get_last_mile_pod','=',True), '|', '|', ('pdf_file', '=', False), ('show_error_message', '!=', False), ('generate_successful_processed', '=', False)]}"/>
attrs="{'invisible': [('get_last_mile_pod','=',True)]}"/>
<button string="Confirm" type="object" name="confirm" class="btn-primary"
attrs="{'invisible': ['|', ('pdf_file', '=', False), '&amp;', ('show_error_message', '!=', False), ('generate_successful_processed', '=', False)]}"/>
<button string="Close" special="cancel"/>
</footer>
</sheet>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论