提交 931c3503 authored 作者: 贺阳's avatar 贺阳

优化修改理货的接口

上级 7827b5d6
......@@ -43,10 +43,10 @@ class AddExceptionInfoWizard(models.TransientModel):
'action_type': action_type,
'big_package_ids': [(6, 0, big_package_ids)],
'exception_ids': [(6, 0, exception_ids)],
'send_email': True,
'send_email': send_email,
'email_language': email_language,
}
return vals
return self.create(vals)
def confirm(self):
for record in self:
......
......@@ -127,169 +127,137 @@ class OrderController(http.Controller):
if kwargs.get('bl_no') and action_type and (
kwargs.get('big_package_arr') or kwargs.get('ship_package_arr') or kwargs.get('pallet_arr')):
bl_no = kwargs['bl_no']
# bl_obj = request.env['cc.bl'].sudo().search([('bl_no', '=', bl_no)]) # 提单
state_arr = ['draft', 'ccing']
tally_time = ''
bl_obj = request.env['cc.bl'].sudo().deal_bl_no(bl_no) # 提单号去掉杠和空格,并转换为小写
if bl_obj:
if bl_obj.state in state_arr:
ship_package_ids = []
big_package_exception_arr = {}
ship_package_exception_arr = {}
# 小包
if kwargs.get('ship_package_arr'):
ship_package_arr = kwargs['ship_package_arr']
error_no_arr = [] # 不存在小包的物流订单号
for package_item in ship_package_arr:
logistic_order_no = package_item.get('logistic_order_no') # 物流订单号
exception_cause_ids = package_item.get('exception_cause_ids') # 异常原因id数组
ship_package_obj = request.env['cc.ship.package'].sudo().search(
[('logistic_order_no', '=', logistic_order_no)]) # 大包号
if ship_package_obj:
ship_package_ids.append(ship_package_obj)
if bl_obj and bl_obj.state in state_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数组
if package_type == 'pallet':
package_obj = request.env['cc.big.package'].sudo().search(
[('pallet_number', '=', package_no), ('bl_id', '=', bl_obj.id)]) # 多个
else:
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:
ship_package_exception_arr[excep_item] = [ship_package_obj.id]
ship_package_obj.update_exception_info(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].append(package_obj.id)
else:
if excep_item not in big_package_exception_arr:
big_package_exception_arr[excep_item] = []
big_package_exception_arr[excep_item].append(package_obj.id)
# package_obj.update_exception_info(exception_cause_ids) # 修改异常信息
tally_time = package_item.get('tally_time')
if package_type == 'ship':
ship_packages.append({
'id': package_obj,
'tally_time': tally_time})
else:
error_no_arr.append(logistic_order_no)
if len(error_no_arr) > 0:
error_no_str = ','.join(list(set(error_no_arr)))
noexist_msg_dic = {
'en': 'Ship package number [%s] does not exist' % error_no_str,
'zh': '小包物流订单号[%s]不存在' % error_no_str
}
res['message'] = noexist_msg_dic[pda_lang]
ship_packages += [{
'id': ship_package,
'tally_time': tally_time} for ship_package in package_obj.ship_package_ids
if ship_package.tally_state == 'unprocessed_goods'] # 小包
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:
res['state'] = 200
# 大包
if kwargs.get('big_package_arr'):
big_package_arr = kwargs['big_package_arr']
# 该箱号的大包存在, 且状态为已扫, 则提示已扫;
# 该箱号的大包不存在, 则提示该箱号在系统中不存在;
error_no_arr = [] # 不存在大包号
for package_item in big_package_arr:
big_package_no = package_item.get('big_package_no') # 大包号
tally_state = package_item.get('tally_state') # 理货状态
tally_user_id = package_item.get('tally_user_id') # 理货人
tally_time = package_item.get('tally_time') # 理货时间
exception_cause_ids = package_item.get('exception_cause_ids') # 异常原因id数组
big_package_obj = request.env['cc.big.package'].sudo().search(
[('big_package_no', '=', big_package_no)]) # 大包号
if big_package_obj:
if exception_cause_ids:
for excep_item in exception_cause_ids:
big_package_exception_arr[excep_item] = [big_package_obj.id]
big_package_obj.update_exception_info(exception_cause_ids) # 修改异常信息
if big_package_obj.tally_state == 'unprocessed_goods':
ship_package_ids += big_package_obj.ship_package_ids # 小包
big_package_obj.update_big_package_info(action_type=action_type,
tally_state=tally_state,
tally_user_id=tally_user_id,
tally_time=tally_time) # 修改理货信息
error_no_set.add(package_no)
return error_no_set
else:
error_no_arr.append(big_package_no)
if len(error_no_arr) > 0:
error_no_str = ','.join(list(set(error_no_arr)))
noexist_msg_dic = {
'en': 'Big package number [%s] does not exist' % error_no_str,
'zh': '大包号[%s]不存在' % error_no_str
}
res['message'] = noexist_msg_dic[
pda_lang] # _('Big package number [%s] does not exist',','.join(list(set(error_no_arr)))) # 大包号[%s]不存在
else:
res['state'] = 200
error_msg_arr = []
# 处理小包、大包和托盘
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('pallet_arr'):
pallet_arr = kwargs['pallet_arr']
error_no_arr = []
for pallet_item in pallet_arr:
pallet_number = pallet_item.get('pallet_number') # 托盘号
tally_state = pallet_item.get('tally_state') # 理货状态
tally_user_id = pallet_item.get('tally_user_id') # 理货人
tally_time = pallet_item.get('tally_time') # 理货时间
exception_cause_ids = package_item.get('exception_cause_ids') # 异常原因ids
# 找出该提单下托盘号对应的所有大包
big_package_obj = request.env['cc.big.package'].sudo().search(
[('pallet_number', '=', pallet_number), ('bl_id', '=', bl_obj.id)])
if big_package_obj:
for big_package_item in big_package_obj:
if exception_cause_ids:
for excep_item in exception_cause_ids:
big_package_exception_arr[excep_item].append(big_package_item.id)
big_package_item.update_exception_info(exception_cause_ids) # 修改异常信息
if big_package_item.tally_state == 'unprocessed_goods':
big_package_item.update_big_package_info(action_type=action_type,
tally_state=tally_state,
tally_user_id=tally_user_id,
tally_time=tally_time) # 修改理货信息
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
else:
error_no_arr.append(pallet_number)
if len(error_no_arr) > 0:
error_no_str = ','.join(list(set(error_no_arr)))
noexist_msg_dic = {
'en': 'Tray number [%s] does not have a corresponding big package' % error_no_str,
'zh': '托盘[%s]没有对应的大包' % error_no_str
}
res['message'] = noexist_msg_dic[pda_lang]
else:
res['state'] = 200
# 同一批异常原因的,同一种类型(大包/小包)发送一封邮件,发送给异常原因上配置的邮箱。
logging.info('big:%s' % big_package_exception_arr)
logging.info('ship:%s' % ship_package_exception_arr)
lang = 'zh_CN' if pda_lang == 'zh' else 'en_US' # 语言
for exception_id, big_package_ids in big_package_exception_arr.items():
if big_package_ids:
# Create the wizard record for big packages
big_wizard_obj = request.env[
'add.exception.info.wizard'].sudo().create_add_exception_wizard('big package',
big_package_ids,
[exception_id],
True, lang)
big_wizard_obj.confirm() # 发送邮件
if kwargs.get('pallet_arr'):
error_no_arr = process_packages(kwargs['pallet_arr'], 'pallet', ship_packages)
if error_no_arr:
res['message'] = {
'en': 'Tray number [%s] does not have a corresponding big package' % ','.join(
error_no_arr),
'zh': '托盘[%s]没有对应的大包' % ','.join(error_no_arr)
}[pda_lang]
return res
# 修改异常原因,发送异常邮件
logging.info('big:%s' % big_package_exception_arr)
logging.info('ship:%s' % ship_package_exception_arr)
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'}).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_ids in ship_package_exception_arr.items():
if ship_package_ids:
# Create the wizard record for ship packages
ship_wizard_obj = request.env[
'add.exception.info.wizard'].sudo().create_add_exception_wizard('ship package',
ship_package_ids,
[exception_id],
True, lang)
ship_wizard_obj.confirm() # 发送邮件
# 该大包变为已理货/尾程交接后,为大包关联的小包和扫描到的小包,符合条件的小包进度变更为对应的清关节点
# (根据配置清关节点上对应的大包状态为已理货/尾程交接,若配置了多个,则生成多条,按照节点次序,扫码的时间间隔加20分钟作为下一条节点的操作时间)
# 且小包当前的状态需在生成对应节点状态前。
# 需生成同步日志,并推送TIKTOK,同步包裹状态。
tally_state = 'checked_goods' if action_type == 'tally' else 'handover_completed'
node_obj = request.env['cc.node'].sudo().search([
('node_type', '=', 'package'),
('tally_state', '=', tally_state) # Check for both states
], order='seq asc') # Order by sequence and creation date ascending
if node_obj:
for index, node in enumerate(node_obj):
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'}).create_add_exception_wizard(
'ship package', [exception_id], ship_package_ids=ship_package, send_email=True,
email_language=lang)
ship_wizard_obj.confirm() # 发送邮件
# 更新小包状态
tally_state = 'checked_goods' if action_type == 'tally' else 'handover_completed'
node_obj = request.env['cc.node'].sudo().search([
('node_type', '=', 'package'),
('tally_state', '=', tally_state) # Check for both states
], order='seq asc') # Order by sequence and creation date ascending
if node_obj:
for index, node in enumerate(node_obj):
for ship_package_dict in ship_packages:
ship_package = ship_package_dict['id']
tally_time = ship_package_dict['tally_time']
operation_time = (fields.Datetime.from_string(tally_time) + timedelta(
minutes=20 * index)) if tally_time else fields.Datetime.now() + timedelta(
minutes=20 * index) # Increment time by 20 minutes for each node
# Update the ship packages based on the node's state and operation time
for ship_package in ship_package_ids:
state_node_obj = request.env['cc.node'].sudo().search(
[('node_type', '=', 'package'), ('name', '=', ship_package.state)], limit=1)
if state_node_obj.seq < node.seq: # Ensure the current state is valid
ship_package.write(
{'state': node.id,
'process_time': operation_time, 'state_explain': node.desc,
'is_sync': True if node.is_default else False})
# 调用同步
is_ok = bl_obj.package_callback_func(ship_package)
# 如果提单有小包变成了清关开始,提单状态变为清关中
if bl_obj.state == 'draft' and bl_obj.ship_package_ids.filtered(
lambda line: line.state.tk_code == 'cb_imcustoms_start'):
bl_obj.ccing_func()
else:
res['message'] = bill_state_msg_dic[pda_lang] # 没有在系统中找到未完成清关的该提单信息
state_node_obj = request.env['cc.node'].sudo().search(
[('node_type', '=', 'package'), ('name', '=', ship_package.state)], limit=1)
if state_node_obj.seq < node.seq: # Ensure the current state is valid
ship_package.write({
'state': node.id,
'process_time': operation_time,
'state_explain': node.desc,
'is_sync': True if node.is_default else False
})
is_ok = bl_obj.package_callback_func(ship_package)
if bl_obj.state == 'draft' and bl_obj.ship_package_ids.filtered(
lambda line: line.state.tk_code == 'cb_imcustoms_start'):
bl_obj.ccing_func()
else:
res['message'] = bill_noexist_msg_dic[pda_lang] # 提单不存在
else:
......
......@@ -429,18 +429,31 @@ class CcBigPackage(models.Model):
"""
理货 tally/尾程交接 handover
"""
action_type = kwargs.get('action_type')
for item in self:
if action_type == 'tally' and item.tally_state == 'unprocessed_goods':
# 更新理货信息
self._update_info(item, kwargs, 'tally')
elif action_type == 'handover' and item.tally_state != 'handover_completed':
# 更新交接信息
self._update_info(item, kwargs, 'handover')
def _update_info(self, item, kwargs, action_type):
"""
更新信息的通用方法
"""
if action_type == 'tally':
if self.tally_state == 'unprocessed_goods':
if kwargs.get('tally_state'):
self.tally_state = kwargs['tally_state']
if kwargs.get('tally_user_id'):
self.tally_user_id = kwargs['tally_user_id']
if kwargs.get('tally_time'):
self.tally_time = kwargs['tally_time']
if kwargs.get('tally_state'):
item.tally_state = kwargs['tally_state']
if kwargs.get('tally_user_id'):
item.tally_user_id = kwargs['tally_user_id']
if kwargs.get('tally_time'):
item.tally_time = kwargs['tally_time']
elif action_type == 'handover':
if self.tally_state != 'handover_completed':
if kwargs.get('tally_user_id'):
self.delivery_user_id = kwargs['tally_user_id']
if kwargs.get('tally_time'):
self.delivery_time = kwargs['tally_time']
if kwargs.get('tally_state'):
item.tally_state = kwargs['tally_state']
if kwargs.get('tally_user_id'):
item.delivery_user_id = kwargs['tally_user_id']
if kwargs.get('tally_time'):
item.delivery_time = kwargs['tally_time']
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论