提交 a0778f4e authored 作者: 贺阳's avatar 贺阳

1、同步货站Pod和同步尾程的优化

上级 7b39af6c
...@@ -426,9 +426,9 @@ ...@@ -426,9 +426,9 @@
</field> </field>
</record> </record>
<!-- 获取尾程快递POD --> <!-- 下载货站提货POD-->
<record id="bl_get_delivery_pod_info_server_action" model="ir.actions.server"> <record id="bl_download_pod_server_action" model="ir.actions.server">
<field name="name">Batch Get Last Mile POD Info</field> <field name="name">Batch Download PickUp POD</field>
<field name="model_id" ref="model_cc_bl"/> <field name="model_id" ref="model_cc_bl"/>
<field name="binding_model_id" ref="model_cc_bl"/> <field name="binding_model_id" ref="model_cc_bl"/>
<field name="state">code</field> <field name="state">code</field>
...@@ -436,13 +436,13 @@ ...@@ -436,13 +436,13 @@
<field name="groups_id" eval="[(4, ref('ccs_base.group_clearance_of_customs_user'))]"/> <field name="groups_id" eval="[(4, ref('ccs_base.group_clearance_of_customs_user'))]"/>
<field name="code"> <field name="code">
if records: if records:
action = records.action_batch_get_last_mile_pod_info() action = records.action_batch_download_pod('货站提货POD')
</field> </field>
</record> </record>
<!-- 下载货站提货POD--> <!-- 获取尾程快递POD -->
<record id="bl_download_pod_server_action" model="ir.actions.server"> <record id="bl_get_delivery_pod_info_server_action" model="ir.actions.server">
<field name="name">Batch Download PickUp POD</field> <field name="name">Batch Get Last Mile POD Info</field>
<field name="model_id" ref="model_cc_bl"/> <field name="model_id" ref="model_cc_bl"/>
<field name="binding_model_id" ref="model_cc_bl"/> <field name="binding_model_id" ref="model_cc_bl"/>
<field name="state">code</field> <field name="state">code</field>
...@@ -450,7 +450,7 @@ ...@@ -450,7 +450,7 @@
<field name="groups_id" eval="[(4, ref('ccs_base.group_clearance_of_customs_user'))]"/> <field name="groups_id" eval="[(4, ref('ccs_base.group_clearance_of_customs_user'))]"/>
<field name="code"> <field name="code">
if records: if records:
action = records.action_batch_download_pod('货站提货POD') action = records.action_batch_get_last_mile_pod_info()
</field> </field>
</record> </record>
......
...@@ -349,7 +349,6 @@ class BatchGetPodInfoWizard(models.TransientModel): ...@@ -349,7 +349,6 @@ class BatchGetPodInfoWizard(models.TransientModel):
if action_type == '获取货站提货POD信息': if action_type == '获取货站提货POD信息':
if self.sync_last_mile_pod and successful_processed_files: if self.sync_last_mile_pod and successful_processed_files:
self._sync_last_mile_pod(successful_processed_files) self._sync_last_mile_pod(successful_processed_files)
# 同步推送匹配节点 # 同步推送匹配节点
if self.sync_match_node and successful_processed_files: if self.sync_match_node and successful_processed_files:
# 且需先对比小包当前节点的操作时间是否小于提取时间(同时区对比)若大于则不能推送, # 且需先对比小包当前节点的操作时间是否小于提取时间(同时区对比)若大于则不能推送,
...@@ -726,25 +725,34 @@ class BatchGetPodInfoWizard(models.TransientModel): ...@@ -726,25 +725,34 @@ class BatchGetPodInfoWizard(models.TransientModel):
Sync pickup POD information # 同步货站提货POD信息 Sync pickup POD information # 同步货站提货POD信息
:param processed_files: 处理后的文件数组 :param processed_files: 处理后的文件数组
""" """
# return False#测试 先不同步 redis_conn = self.env['common.common'].sudo().get_redis()
# 同步货站提货POD信息 if not redis_conn or redis_conn == 'no':
is_fail = [] # 同步失败 raise ValidationError('未连接redis,无法同步货站提货POD,请联系管理员')
bl_ids = []
for file_info in processed_files: for file_info in processed_files:
if not file_info['bl']: bl = file_info.get('bl')
if not bl:
continue continue
bl = file_info['bl']
# 查找清关文件并执行同步
clearance_file = file_info.get('clearance_file') clearance_file = file_info.get('clearance_file')
if clearance_file: if not clearance_file:
try: continue
clearance_file.action_sync() # 同步货站提货POD bl_ids.append(bl.id)
except Exception as e:
logging.info('_sync_last_mile_pod:%s' % e) if not bl_ids:
is_fail = True return
break
_logger.info(f"Successfully synced POD for BL {bl.bl_no}") payload = {
if is_fail: 'ids': bl_ids,
raise ValidationError('本次同步失败,请重试!') 'action_type': 'sync_last_mile_pod',
'user_login': self.env.user.login,
'file_type': '货站提货POD'
}
try:
redis_conn.lpush('mail_push_package_list', json.dumps(payload))
except Exception as e:
logging.info('sync_last_mile_pod redis error:%s' % e)
raise ValidationError('推送货站提货POD同步任务到redis失败,请重试或联系管理员')
def _check_target_texts_exist(self, pdf_binary, bl_no): def _check_target_texts_exist(self, pdf_binary, bl_no):
""" """
......
...@@ -31,8 +31,11 @@ class Order_dispose(object): ...@@ -31,8 +31,11 @@ class Order_dispose(object):
try: try:
data = json.loads(data) data = json.loads(data)
logging.info('mail_push_data: %s', data) logging.info('mail_push_data: %s', data)
action_type = data.get('action_type')
if action_type == 'sync_last_mile_pod':
self._sync_last_mile_pod_from_queue(data)
return res_data
ship_packages = eval(data['ship_packages']) if data.get('ship_packages') else [] # 小包 ship_packages = eval(data['ship_packages']) if data.get('ship_packages') else [] # 小包
action_type = data.get('action_type') # 类型
utc_time = data.get('utc_time') utc_time = data.get('utc_time')
bl_obj = self.odoo_db.env['cc.bl'] bl_obj = self.odoo_db.env['cc.bl']
if action_type and not utc_time: if action_type and not utc_time:
...@@ -52,6 +55,32 @@ class Order_dispose(object): ...@@ -52,6 +55,32 @@ class Order_dispose(object):
logging.error('mail_auto_push error:%s' % str(ex)) logging.error('mail_auto_push error:%s' % str(ex))
return res_data return res_data
def _sync_last_mile_pod_from_queue(self, data):
bl_ids = data.get('ids') or []
if not bl_ids:
return
try:
bl_model = self.odoo_db.env['cc.bl']
clearance_model = self.odoo_db.env['cc.clearance.file']
bl_records = bl_model.browse(bl_ids)
non_temu_ids = [bl.id for bl in bl_records if getattr(bl, 'bl_type', False) != 'temu']
if not non_temu_ids:
return
clearance_ids = clearance_model.search([
('bl_id', 'in', non_temu_ids),
('file_name', '=', data.get('file_type')),
])
if not clearance_ids:
return
clearance_records = clearance_model.browse(clearance_ids)
for clearance_file in clearance_records:
try:
clearance_file.action_sync()
except Exception as ex:
logging.error('sync_last_mile_pod action_sync error:%s' % str(ex))
except Exception as ex:
logging.error('sync_last_mile_pod_from_queue error:%s' % str(ex))
try: try:
pool = redis.ConnectionPool(**config.redis_options) pool = redis.ConnectionPool(**config.redis_options)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论