提交 8e3149d6 authored 作者: 贺阳's avatar 贺阳

增加按托盘交货时检查时间是否倒挂的接口

上级 ac33047e
......@@ -616,7 +616,7 @@ class OrderController(http.Controller):
@http.route('/api/last_mile/delivery/time_check', type='json', auth='public', csrf=False)
def last_mile_delivery_time_check(self):
"""
按尾程快递交货接口,查询系统所有清关中的提单,且大包状态为已理货的数量,按下一阶段服务商名称分组,下一个阶段服务商名称匹配尾程快递传给PDA。传输字段与理货的一致。
尾程快递交货检查时间是否正常
"""
kwargs = json.loads(request.httprequest.data)
pda_lang = kwargs.get('pda_lang') or 'zh'
......@@ -650,11 +650,11 @@ class OrderController(http.Controller):
# domain=[('state', '!=', 'done')]# 1. 按托盘理货时,查非已完成状态的提单
# else:
# 先都查清关中的,如果以后要查非已完成状态的提单,再修改domain。而且查尾程快递和对应的大包或托盘信息得分两个接口
domain = [('state', '=', 'ccing')] # 1. 按尾程理货时,查所有清关中提单
bls = request.env['cc.bl'].sudo().search(domain)
# 2. 查所有大包
big_packages = request.env['cc.big.package'].sudo().search(
[('bl_id', 'in', bls.ids), ('tally_state', '=', tally_state)])
domain = [('bl_id.state', '=', 'ccing')] # 1. 按尾程理货时,查所有清关中提单
# 2. 查所有大包 如果是托盘的交货,不需要过滤理货状态
if not is_pallet or (is_pallet and tally_state == 'unprocessed_goods'):
domain += [('tally_state', '=', tally_state)]
big_packages = request.env['cc.big.package'].sudo().search(domain)
# 3. 按"下一阶段服务商名称"分组
group_dict = {}
for pkg in big_packages:
......@@ -695,17 +695,16 @@ class OrderController(http.Controller):
return {'provider_info_arr': provider_info_arr, 'state': 200,
'bl_ids': list(set(list(map(lambda x: x.bl_id.id, big_packages))))}
def _check_delivery_time_risk(self, bl_obj, pda_lang='zh'):
def _check_delivery_time_risk(self, bl_obj, pda_lang='zh', pallet_name=None):
"""
检查提单交货时间倒序风险
:param bl_obj: 提单对象
:param pda_lang: 语言设置
:param pallet_name: 托盘号
:return: 检查结果字典
"""
# 获取配置的交货操作晚于提货操作的时间参数(分钟)
config_param = request.env['ir.config_parameter'].sudo().get_param(
'delivery_time', '80' # 使用现有的delivery_time参数,默认80分钟
)
config_param = request.env['ir.config_parameter'].sudo().get_param('delivery_time', '80')
allowed_minutes = int(config_param)
# 查找该提单的PDA扫码记录,类型为理货的
pda_records = request.env['pda.scan.record'].sudo().search([
......@@ -723,10 +722,16 @@ class OrderController(http.Controller):
logging.info(f"current_time: {current_time}, operation_time: {operation_time},time_diff: {time_diff}")
# 如果时间差小于等于配置的参数,则存在风险
if time_diff <= allowed_minutes:
if pda_lang == 'en':
message = f"The bill of lading has not reached the delivery time, and there is a risk of flashback. Please scan the code after {allowed_minutes} minutes."
if pallet_name:
if pda_lang == 'en':
message = f"The pallet {pallet_name} has not reached the delivery time, and there is a risk of flashback. Please scan the code after {allowed_minutes} minutes."
else:
message = f"该托盘号{pallet_name}装载的提单未到交货时间,有风险产生倒叙,请间隔{allowed_minutes}分钟后再扫码;"
else:
message = f"该提单未到交货时间,有风险产生倒叙,请间隔{allowed_minutes}分钟后再扫码;"
if pda_lang == 'en':
message = f"The bill of lading has not reached the delivery time, and there is a risk of flashback. Please scan the code after {allowed_minutes} minutes."
else:
message = f"该提单%s未到交货时间,有风险产生倒叙,请间隔{allowed_minutes}分钟后再扫码;" % bl_obj.bl_no
return {
'has_risk': True,
......@@ -1111,3 +1116,35 @@ class OrderController(http.Controller):
)
logging.info('pallet_handover_complete res:%s' % res)
return res
@http.route('/api/pallet/delivery/time_check', type='json', auth='public', csrf=False)
def pallet_delivery_time_check(self):
"""
托盘交货检查时间是否正常
"""
kwargs = json.loads(request.httprequest.data)
pda_lang = kwargs.get('pda_lang') or 'zh'
res = {'state': 201, 'message': ''}
try:
logging.info('pallet_delivery_time_check kwargs:%s' % kwargs)
all_pallet_ids_in_request = kwargs['pallet_ids']
if all_pallet_ids_in_request:
pallet_objs = request.env['cc.pallet'].sudo().search([('id', 'in', all_pallet_ids_in_request)])
for pallet_obj in pallet_objs:
bl_objs = pallet_obj.package_ids.mapped('bl_id')
for bl_obj in bl_objs:
time_check_result = self._check_delivery_time_risk(bl_obj, pda_lang, pallet_obj.name)
if time_check_result['has_risk']:
res['state'] = 400
res['message'] = time_check_result['message']
return res
res['state'] = 200
except Exception as e:
exceptions_msg_dic = {
'en': 'System parsing error, the reason for the error is %s' % e,
'zh': '系统解析错误,错误原因是%s' % e
}
logging.info('pallet_delivery_time_check error:%s' % e)
res['message'] = exceptions_msg_dic[pda_lang]
logging.info('pallet_delivery_time_check res:%s' % res)
return res
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论