提交 3b57bdd7 authored 作者: 刘擎阳's avatar 刘擎阳

1.导出清关文件

上级 963de709
...@@ -157,3 +157,26 @@ class ExportBlAndPackageXlsx(http.Controller): ...@@ -157,3 +157,26 @@ class ExportBlAndPackageXlsx(http.Controller):
] ]
response = http.request.make_response(zip_buffer.getvalue(), headers=headers) response = http.request.make_response(zip_buffer.getvalue(), headers=headers)
return response return response
@http.route(['/export/flight_png/xls/<string:arr>'], type='http', auth="public")
def export_flight_png_xls(self, arr):
arr = json.loads(arr)
flight_objs = http.request.env['cc.bl'].sudo().search([('id', 'in', arr)], order='id')
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, 'w', zipfile.ZIP_DEFLATED) as zip_file:
for flight in flight_objs:
bl_attachment_objs = flight.bl_attachment_ids
for bl_attachment_obj in bl_attachment_objs:
# 获取图片数据
image_data = base64.b64decode(bl_attachment_obj.datas)
# 创建文件名,前缀为单据号
file_name = f"{flight.bl_no}.png"
# 将图片添加到 ZIP 文件
zip_file.writestr(file_name, image_data)
zip_buffer.seek(0)
headers = [
('Content-Type', 'application/x-zip-compressed'),
('Content-Disposition', 'attachment; filename="customs_clearance_data.zip"'),
]
response = http.request.make_response(zip_buffer.getvalue(), headers=headers)
return response
...@@ -797,6 +797,11 @@ msgstr "出口HSCode" ...@@ -797,6 +797,11 @@ msgstr "出口HSCode"
msgid "Export customs declaration data" msgid "Export customs declaration data"
msgstr "导出报关数据" msgstr "导出报关数据"
#. module: ccs_base
#: model:ir.actions.server,name:ccs_base.export_flight_png_server
msgid "Export customs clearance bill of lading file"
msgstr "导出清关提单文件"
#. module: ccs_base #. module: ccs_base
#. odoo-python #. odoo-python
#: code:addons/ccs_base/models/cc_bill_loading.py:0 #: code:addons/ccs_base/models/cc_bill_loading.py:0
......
...@@ -470,6 +470,15 @@ class CcBL(models.Model): ...@@ -470,6 +470,15 @@ class CcBL(models.Model):
('bl_no_uniq', 'unique(bl_no)', 'The Bill of Loading No. must be unique.') ('bl_no_uniq', 'unique(bl_no)', 'The Bill of Loading No. must be unique.')
] ]
# 导出清关提单文件
def export_bl_attachment_png(self):
arr = [item.id for item in self]
return {
'type': 'ir.actions.act_url',
'url': '/export/flight_png/xls/%s' % arr,
'target': 'new',
}
@api.depends('big_package_ids', 'big_package_ids.tally_state', 'big_package_ids.is_cancel') @api.depends('big_package_ids', 'big_package_ids.tally_state', 'big_package_ids.is_cancel')
def cal_tally_big_package_qty(self): def cal_tally_big_package_qty(self):
""" """
......
...@@ -335,4 +335,15 @@ ...@@ -335,4 +335,15 @@
</field> </field>
</record> </record>
<record id="export_flight_png_server" model="ir.actions.server">
<field name="name">Export customs clearance bill of lading file</field>
<field name="model_id" ref="model_cc_bl"/>
<field name="binding_model_id" ref="model_cc_bl"/>
<field name="state">code</field>
<field name="code">
if records:
action = records.export_bl_attachment_png()
</field>
</record>
</odoo> </odoo>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论