提交 0d9e8a71 authored 作者: 刘擎阳's avatar 刘擎阳

1.pod文件获取优化

上级 3b209303
...@@ -117,9 +117,18 @@ class OrderStateChangeRule(models.Model): ...@@ -117,9 +117,18 @@ class OrderStateChangeRule(models.Model):
def upload_pod_attachment(self, bl_obj, name, data): def upload_pod_attachment(self, bl_obj, name, data):
"""尾程交接POD(待大包数量和箱号) 文件上传与同步""" """尾程交接POD(待大包数量和箱号) 文件上传与同步"""
file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'), arr = [
('bl_id', 'in', bl_obj.ids)]) {
'file_name': '尾程交接POD(待大包数量和箱号)',
'file': base64.encodebytes(data),
'attachment_name': name,
'is_upload': False,
'bl_id': bl.id
} for bl in bl_obj
]
# file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'),
# ('bl_id', 'in', bl_obj.ids)])
file_objs = self.env['cc.clearance.file'].sudo().create(arr)
# 最大重试次数 # 最大重试次数
max_retries = 2 max_retries = 2
for file_obj in file_objs: for file_obj in file_objs:
...@@ -127,9 +136,9 @@ class OrderStateChangeRule(models.Model): ...@@ -127,9 +136,9 @@ class OrderStateChangeRule(models.Model):
while retries <= max_retries: while retries <= max_retries:
try: try:
# 设置文件内容 # 设置文件内容
file_obj.file = base64.encodebytes(data) # file_obj.file = base64.encodebytes(data)
file_obj.attachment_name = name # file_obj.attachment_name = name
file_obj.is_upload = False # 确保文件状态是未上传 # file_obj.is_upload = False # 确保文件状态是未上传
# 尝试上传操作 # 尝试上传操作
file_obj.action_sync() file_obj.action_sync()
# 检查是否上传成功,假设 is_upload 为 False 表示上传失败 # 检查是否上传成功,假设 is_upload 为 False 表示上传失败
...@@ -201,7 +210,8 @@ class OrderStateChangeRule(models.Model): ...@@ -201,7 +210,8 @@ class OrderStateChangeRule(models.Model):
text_arr = self.find_final_email_text(email_body) text_arr = self.find_final_email_text(email_body)
logging.info('data_arr: %s' % text_arr) logging.info('data_arr: %s' % text_arr)
attachment_arr = kwargs['attachment_arr'] attachment_arr = kwargs['attachment_arr']
attachment_tuple = attachment_arr[0] if attachment_arr else [] # attachment_tuple = attachment_arr[0] if attachment_arr else []
attachment_tuple_arr = attachment_arr if attachment_arr else []
# order_obj_arr = [] # order_obj_arr = []
try: try:
text_arr = [i.replace('-', '').replace(' ', '') for i in text_arr] text_arr = [i.replace('-', '').replace(' ', '') for i in text_arr]
...@@ -210,9 +220,13 @@ class OrderStateChangeRule(models.Model): ...@@ -210,9 +220,13 @@ class OrderStateChangeRule(models.Model):
result = self._cr.fetchall() result = self._cr.fetchall()
ids = [i[0] for i in result] ids = [i[0] for i in result]
bl_objs = self.env['cc.bl'].sudo().search([('id', 'in', ids)]) if result else False bl_objs = self.env['cc.bl'].sudo().search([('id', 'in', ids)]) if result else False
if bl_objs and attachment_tuple: if bl_objs and attachment_tuple_arr:
attachment_name, attachment_data = attachment_tuple file_objs = self.env['cc.clearance.file'].sudo().search([('file_name', '=', '尾程交接POD(待大包数量和箱号)'),
self.upload_pod_attachment(bl_objs, attachment_name, attachment_data) ('bl_id', 'in', bl_objs.ids)])
file_objs.unlink()
for attachment_tuple in attachment_tuple_arr:
attachment_name, attachment_data = attachment_tuple
self.upload_pod_attachment(bl_objs, attachment_name, attachment_data)
# redis_conn = self.env['common.common'].sudo().get_redis() # redis_conn = self.env['common.common'].sudo().get_redis()
# if redis_conn == 'no': # if redis_conn == 'no':
# raise ValidationError('未连接redis') # raise ValidationError('未连接redis')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论