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

增加修改尾程快递的大包理货信息的接口

上级 2ffcf83d
......@@ -90,7 +90,6 @@ class OrderController(http.Controller):
def bl_info(self):
"""
查看提单以及大包,小包和托盘信息
:param kwargs:
:return:
"""
kwargs = json.loads(request.httprequest.data)
......@@ -299,6 +298,152 @@ class OrderController(http.Controller):
logging.info('res:%s' % res)
return res
@http.route('/api/update/pro/big/package/tally/detail', type='json', auth='public', methods=['GET', 'POST'],
csrf=False)
def update_pro_big_package_tally_detail(self):
"""
修改尾程快递的理货信息
:return:
"""
kwargs = json.loads(request.httprequest.data)
pda_lang = kwargs.get('pda_lang') or 'zh'
res = {'state': 201, 'message': ''}
action_type = kwargs.get('action_type') or 'tally' # tally / handover
try:
logging.info('update_pro_big_package_tally_detail kw:%s' % kwargs)
if action_type and (kwargs.get('big_package_arr') or kwargs.get('ship_package_arr')):
ship_packages = []
big_package_exception_arr = {}
ship_package_exception_arr = {}
# 处理包裹信息
def process_packages(package_arr, package_type, ship_packages):
error_no_set = set() # 使用集合来存储错误信息
for package_item in package_arr:
file_str = 'big_package_no' if package_type == 'big' else (
'logistic_order_no' if package_type == 'ship' else 'pallet_number') # 大包号/物流订单号
package_no = package_item.get(file_str) # 包裹号
exception_cause_ids = package_item.get(
'exception_cause_ids') # 异常原因id数组
package_obj = request.env[f'cc.{package_type}.package'].sudo().search(
[(file_str, '=', package_no)]) # 小包/大包 1个
if package_obj:
if exception_cause_ids:
for excep_item in exception_cause_ids:
if package_type == 'ship':
if excep_item not in ship_package_exception_arr:
ship_package_exception_arr[excep_item] = [
]
ship_package_exception_arr[excep_item] += package_obj.ids
else:
if excep_item not in big_package_exception_arr:
big_package_exception_arr[excep_item] = [
]
big_package_exception_arr[excep_item] += package_obj.ids
package_obj.update_exception_info(
exception_cause_ids) # 修改异常信息
tally_time = package_item.get('tally_time')
if (action_type == 'tally' and package_item.get('tally_state') == 'checked_goods') or (
action_type == 'handover' and package_item.get(
'tally_state') == 'handover_completed'):
if package_type == 'ship':
ship_packages.append({
'id': [package_obj.id],
'bl_id': package_obj.bl_id.id,
'tally_time': tally_time})
else:
for package in package_obj:
if (
action_type == 'tally' and package.tally_state == 'unprocessed_goods') or (
action_type == 'handover' and package.tally_state in (
'unprocessed_goods', 'checked_goods')):
ship_packages.append({
'id': package.ship_package_ids.ids,
'bl_id': package.bl_id.id,
'tally_time': tally_time
}) # 小包
package_obj.update_big_package_info(action_type=action_type,
tally_state=package_item.get(
'tally_state'),
tally_user_id=package_item.get(
'tally_user_id'),
tally_time=tally_time) # 修改理货信息
else:
error_no_set.add(package_no)
return error_no_set
# 处理小包、大包
if kwargs.get('ship_package_arr'):
error_no_arr = process_packages(
kwargs['ship_package_arr'], 'ship', ship_packages)
if error_no_arr:
res['message'] = {
'en': 'Ship package number [%s] does not exist' % ','.join(error_no_arr),
'zh': '小包物流订单号[%s]不存在' % ','.join(error_no_arr)
}[pda_lang]
return res
if kwargs.get('big_package_arr'):
error_no_arr = process_packages(
kwargs['big_package_arr'], 'big', ship_packages)
if error_no_arr:
res['message'] = {
'en': 'Big package number [%s] does not exist' % ','.join(error_no_arr),
'zh': '大包号[%s]不存在' % ','.join(error_no_arr)
}[pda_lang]
return res
# 修改异常原因,发送异常邮件
lang = 'zh_CN' if pda_lang == 'zh' else 'en_US' # 语言
for exception_id, big_package in big_package_exception_arr.items():
if big_package:
big_wizard_obj = request.env[
'add.exception.info.wizard'].sudo().with_context({'active_id': big_package,
'active_name': 'cc.big.package',
'not_update_ex': True}).create_add_exception_wizard(
'big package', [exception_id], big_package_ids=big_package, send_email=True,
email_language=lang)
big_wizard_obj.confirm() # 发送邮件
for exception_id, ship_package in ship_package_exception_arr.items():
if ship_package:
ship_wizard_obj = request.env[
'add.exception.info.wizard'].sudo().with_context({'active_id': ship_package,
'active_name': 'cc.ship.package',
'not_update_ex': True}).create_add_exception_wizard(
'ship package', [exception_id], ship_package_ids=ship_package, send_email=True,
email_language=lang)
ship_wizard_obj.confirm() # 发送邮件
res['state'] = 200
logging.info(
'update_big_package_tally_detail ship_packages:%s' % len(ship_packages))
# 有小包 就更新小包状态和同步
if ship_packages:
redis_conn = request.env['common.common'].sudo().get_redis()
if redis_conn and redis_conn != 'no':
# redis_conn.lpush('push_ship_package_state', json.dumps(
# {'bl_id': bl_obj.id, 'ship_package_ids': ship_package_ids}))
bl_ids = [ship_package.get('bl_id') for ship_package in ship_packages]
logging.info('bl_ids:%s' % bl_ids)
redis_conn.lpush('mail_push_package_list', json.dumps(
{'ids': list(set(bl_ids)), 'ship_packages': str(ship_packages), 'action_type': action_type}))
else:
null_msg_dic = {
'en': 'The bill of lading number and action type must be provided; at least one of the following is required: big package data or ship package data.',
'zh': '类型必须提供;大包数据或小包数据至少需要提供一个。'
}
res['message'] = null_msg_dic[pda_lang]
except Exception as e:
logging.info('update_pro_big_package_tally_detail error:%s' % e)
exceptions_msg_dic = {
'en': 'System parsing error, the reason for the error is %s' % e,
'zh': '系统解析错误,错误原因是%s' % e
}
res['message'] = exceptions_msg_dic[pda_lang]
logging.info('res:%s' % res)
return res
@http.route('/api/exceptions/info', type='json', auth='public', methods=['GET', 'POST'], csrf=False)
def exceptions_info(self):
"""
......@@ -396,7 +541,6 @@ class OrderController(http.Controller):
group_dict[key]['ship_package_arr'] = []
group_dict[key]['count'] += 1
group_dict[key]['big_package_arr'].append(pkg.search_big_package_info(pda_lang=pda_lang, type=tally_state))
print('pkg.ship_package_ids:%s' %pkg.ship_package_ids)
group_dict[key]['ship_package_arr'].extend(
[ship_package_item.search_ship_package_info(pda_lang=pda_lang) for ship_package_item in
pkg.ship_package_ids])
......
# -*- coding: utf-8 -*-
import asyncio
import json
import logging
import ssl
from datetime import timedelta, datetime
import json
import aiohttp
import certifi
import pytz
......@@ -606,19 +607,22 @@ class CcBl(models.Model):
# package_order = self.env['cc.ship.package'].sudo().browse(package_id)
if response_data['code'] != 0:
# package_order.is_sync = False
update_false_arr.append(package_id) # 更新 is_sync为 False
update_false_arr.append(package_id) # 更新 is_sync为 False
error_msg = response_data['msg']
request_id = response_data['requestID']
create_api_log_value_arr.append((tracking_no, utc_time, '小包状态轨迹回传:' + error_msg, False, data_text, request_id, '推出', utc_time))
create_api_log_value_arr.append((tracking_no, utc_time, '小包状态轨迹回传:' + error_msg, False,
data_text, request_id, '推出', utc_time))
is_ok = False
else:
# 回传成功
update_true_arr.append(package_id) # 更新 is_sync为 True
state_arr = package_node_result_dict.get(state, [])
tk_code = state_arr[1] if state_arr else ''
create_sync_log_value_arr.append((package_id, utc_time, 'Tiktok', tk_code, process_time, state_explain, user_id))
create_sync_log_value_arr.append(
(package_id, utc_time, 'Tiktok', tk_code, process_time, state_explain, user_id))
request_id = response_data['requestID']
create_api_log_value_arr.append((tracking_no, utc_time, '', True, data_text, request_id, '推出', utc_time))
create_api_log_value_arr.append(
(tracking_no, utc_time, '', True, data_text, request_id, '推出', utc_time))
if update_false_arr:
update_false_ids = '(%s)' % str(update_false_arr)[1:-1]
sql = "update cc_ship_package set is_sync=False where id in %s" % update_false_ids
......@@ -831,10 +835,10 @@ class CcBl(models.Model):
item.push_clear_customs_start(before_utc_time)
user_obj = self.env['res.users'].search([('login', '=', mail_db_user)], limit=1)
# 尝试调用 callback_track
if self.try_callback_track(user_obj=user_obj):
if item.try_callback_track(user_obj=user_obj):
item.push_clear_customs_end(utc_time)
# 再次尝试调用 callback_track
if not self.try_callback_track(user_obj=user_obj):
if not item.try_callback_track(user_obj=user_obj):
logging.error(f"Failed to push item after {3} attempts.")
else:
logging.error(f"Failed to start process for item after {3} attempts.")
......@@ -914,7 +918,7 @@ class CcBl(models.Model):
self.env.cr.execute(sql)
self._cr.commit() # 提交事务
self.try_callback_track(max_retries=2, ship_package_ids=ship_package_ids,
item.try_callback_track(max_retries=2, ship_package_ids=ship_package_ids,
user_obj=user_obj)
# 理货或尾程交接的节点
# 预先获取所有状态节点
......@@ -960,7 +964,7 @@ class CcBl(models.Model):
self.env.cr.execute(sql)
self._cr.commit() # 提交事务
self.try_callback_track(max_retries=2, ship_package_ids=ship_package_ids,
item.try_callback_track(max_retries=2, ship_package_ids=ship_package_ids,
user_obj=user_obj)
return True
......
......@@ -37,7 +37,11 @@ class Order_dispose(object):
bl_obj = self.odoo_db.env['cc.bl']
if action_type and not utc_time:
bl_obj = self.pda_odoo_db.env['cc.bl']
bl_record = bl_obj.browse(data['id'])
bl_ids = data.get('ids')
if bl_ids:
bl_record = bl_obj.browse(bl_ids)
else:
bl_record = bl_obj.browse(data['id'])
# utc_time = datetime.strptime(data['utc_time'], "%Y-%m-%d %H:%M:%S")
utc_time = data.get('utc_time')
user_login = data.get('user_login')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论