提交 6ea60517 authored 作者: 刘擎阳's avatar 刘擎阳

1.优化下载名称

上级 6d65fdd8
......@@ -433,7 +433,7 @@ class CcClearanceFile(models.Model):
file = fields.Binary(string='File')
# 文件名
file_name = fields.Char(string='File Name')
attachment_name = fields.Char(string='File Name')
# 是否同步
is_upload = fields.Boolean(string='Is Sync', default=False)
# 同步时间
......
......@@ -136,7 +136,7 @@ class FetchmailServer(models.Model):
filename, encoding = decode_header(filename)[0]
if isinstance(filename, bytes):
filename = filename.decode(encoding if encoding else "utf-8")
attachment_arr.append(part.get_payload(decode=True))
attachment_arr.append((filename, part.get_payload(decode=True)))
for part in msg.walk():
# 如果ture的话内容是没用的
if not part.is_multipart():
......
......@@ -106,18 +106,20 @@ class OrderStateChangeRule(models.Model):
data_arr = data_re.findall(email_body)
return data_arr
def upload_cds_attachment(self, bl_obj, data):
def upload_cds_attachment(self, bl_obj, name, data):
file_obj = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '海关CDS申报单(import和授权方式检查拉齐等)'),
('bl_id', '=', bl_obj.id)], limit=1)
file_obj.file = base64.encodebytes(data)
file_obj.attachment_name = name
file_obj.is_upload = False
file_obj.action_sync()
def fetch_mail_dlv_attachment(self, **kwargs):
attachment_arr = kwargs['attachment_arr']
for attachment in attachment_arr:
for attachment_tuple in attachment_arr:
try:
order_no, date_str = self.read_pdf(attachment)
attachment_name, attachment_data = attachment_tuple
order_no, date_str = self.read_pdf(attachment_data)
if order_no:
# 转换为 datetime 对象
local_time = datetime.strptime(date_str, '%d/%m/%Y %H:%M:%S')
......@@ -133,7 +135,7 @@ class OrderStateChangeRule(models.Model):
bl_obj = self.env['cc.bl'].sudo().search([('id', '=', result[0][0])]) if result else False
logging.info('order_no:%s, bl_obj: %s' % (order_no, bl_obj))
if bl_obj:
self.upload_cds_attachment(bl_obj, attachment)
self.upload_cds_attachment(bl_obj, attachment_name, attachment_data)
if bl_obj and bl_obj.state != 'done':
redis_conn = self.env['common.common'].sudo().get_redis()
if redis_conn == 'no':
......
......@@ -11,10 +11,11 @@
<tree string="Clearance File" decoration-success="is_upload == 1" editable="bottom">
<field name="bl_id" string="Bill of Loading" invisible="1"/>
<field name="file_name" string="File Name" required="1"/>
<field name="file" string="PDF File" required="1"/>
<field name="file" string="PDF File" required="1" filename="attachment_name"/>
<field name="is_upload" readonly="1"/>
<field name="upload_time"/>
<button name="action_sync" string="SyncTo.." type="object" icon="fa-upload"/>
<field name="attachment_name" invisible="1"/>
</tree>
</field>
</record>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论