提交 06b9d598 authored 作者: 贺阳's avatar 贺阳

检查 如果类型是create 根据提单号和大包数量查询到了数据 就不做处理

上级 ffa12d84
...@@ -286,6 +286,14 @@ class TTApi(http.Controller): ...@@ -286,6 +286,14 @@ class TTApi(http.Controller):
declare_type = kws.get('declare_type') declare_type = kws.get('declare_type')
if declare_type: if declare_type:
declare_type = declare_type.lower() declare_type = declare_type.lower()
exit_bl_obj = []
if declare_type == 'create':
# 检查 如果类型是create 根据提单号和大包数量查询到了数据 就不做处理
select_bl_sql = """select id from cc_bl where bl_no='{0}' and big_package_qty={1};""".format(
kws.get('master_waybill_no'), kws.get('big_bag_quantity'))
request._cr.execute(select_bl_sql)
exit_bl_obj = request._cr.fetchall()
logging.info('select_bl_sql:%s,exit_bl_obj:%s' % (select_bl_sql, exit_bl_obj))
if not bl: if not bl:
if declare_type == 'create': if declare_type == 'create':
bl = request.env['cc.bl'].sudo().create(bl_vals) bl = request.env['cc.bl'].sudo().create(bl_vals)
...@@ -297,59 +305,62 @@ class TTApi(http.Controller): ...@@ -297,59 +305,62 @@ class TTApi(http.Controller):
else: else:
if declare_type == 'update' and bl.state == 'draft': if declare_type == 'update' and bl.state == 'draft':
bl.write(bl_vals) bl.write(bl_vals)
# 生成cc.big.package if bl and ((declare_type == 'create' and len(exit_bl_obj) <= 0) or (
big_bag_list = kws.get('big_bag_list') declare_type == 'update' and bl.state == 'draft')):
if big_bag_list and len(big_bag_list) > 0: logging.info('-----update big')
# 删除大包数据 改为sql # 生成cc.big.package
big_package_ids = bl.big_package_ids big_bag_list = kws.get('big_bag_list')
where_sql = "" if len(big_package_ids) <= 0 else ( if big_bag_list and len(big_bag_list) > 0:
"where id=%s" % big_package_ids[0].id if len( # 删除大包数据 改为sql
big_package_ids) == 1 else "where id in {0}".format(tuple( big_package_ids = bl.big_package_ids
big_package_ids.ids))) where_sql = "" if len(big_package_ids) <= 0 else (
if where_sql and len(big_package_ids) > 0: "where id=%s" % big_package_ids[0].id if len(
del_sql = "delete from cc_big_package {0}".format(where_sql) big_package_ids) == 1 else "where id in {0}".format(tuple(
request._cr.execute(del_sql) big_package_ids.ids)))
request._cr.commit() if where_sql and len(big_package_ids) > 0:
# for package in bl.big_package_ids: del_sql = "delete from cc_big_package {0}".format(where_sql)
# package.bl_id = False request._cr.execute(del_sql)
# package.unlink() request._cr.commit()
# 本身提单的小包解除关联 # for package in bl.big_package_ids:
for ship in bl.ship_package_ids: # package.bl_id = False
ship.bl_id = False # package.unlink()
ship.big_package_id = False # 本身提单的小包解除关联
for big_bag in big_bag_list: for ship in bl.ship_package_ids:
big_bag_no = big_bag.get('big_bag_no') ship.bl_id = False
# 检查big_bag_no是否已经存在 ship.big_package_id = False
big_package_vals = dict(bl_id=bl.id, for big_bag in big_bag_list:
big_package_no=big_bag.get('big_bag_no'), big_bag_no = big_bag.get('big_bag_no')
next_provider_name=big_bag.get('next_provider_name')) # 检查big_bag_no是否已经存在
big_package = request.env['cc.big.package'].sudo().search( big_package_vals = dict(bl_id=bl.id,
[('big_package_no', '=', big_bag_no)], limit=1) big_package_no=big_bag.get('big_bag_no'),
if not big_package: next_provider_name=big_bag.get('next_provider_name'))
big_package = request.env['cc.big.package'].sudo().create(big_package_vals) big_package = request.env['cc.big.package'].sudo().search(
else: [('big_package_no', '=', big_bag_no)], limit=1)
big_package.write(big_package_vals) if not big_package:
# 生成cc.ship.package big_package = request.env['cc.big.package'].sudo().create(big_package_vals)
package_list = big_bag.get('package_list') # 大包下的小包 else:
if package_list and len(package_list) > 0: big_package.write(big_package_vals)
package_ids = [package.get('provider_order_id') for package in package_list] # 生成cc.ship.package
ship_packages = request.env['cc.ship.package'].sudo().search( package_list = big_bag.get('package_list') # 大包下的小包
[('logistic_order_no', 'in', package_ids)]) if package_list and len(package_list) > 0:
if ship_packages and len(ship_packages) > 0: package_ids = [package.get('provider_order_id') for package in package_list]
ship_packages.write( ship_packages = request.env['cc.ship.package'].sudo().search(
{'is_cancel': False, 'cancel_reason': False, 'big_package_id': big_package.id, [('logistic_order_no', 'in', package_ids)])
'bl_id': big_package.bl_id.id}) if ship_packages and len(ship_packages) > 0:
if len(package_ids) != len(ship_packages): ship_packages.write(
# 找出ship_packages没有找到的package {'is_cancel': False, 'cancel_reason': False, 'big_package_id': big_package.id,
package_ids = set(package_ids) 'bl_id': big_package.bl_id.id})
ship_package_ids = set( if len(package_ids) != len(ship_packages):
[ship_package.logistic_order_no for ship_package in ship_packages]) # 找出ship_packages没有找到的package
diff_ids = package_ids - ship_package_ids package_ids = set(package_ids)
_logger.info('diff_ids:%s' % diff_ids) ship_package_ids = set(
else: [ship_package.logistic_order_no for ship_package in ship_packages])
res['msg'] = 'Big bag [%s] not include any package. ' % big_bag.get('big_bag_no') diff_ids = package_ids - ship_package_ids
else: _logger.info('diff_ids:%s' % diff_ids)
res['msg'] = 'Big bag list is empty.' else:
res['msg'] = 'Big bag [%s] not include any package. ' % big_bag.get('big_bag_no')
else:
res['msg'] = 'Big bag list is empty.'
except Exception as e: except Exception as e:
res['code'] = 5000 res['code'] = 5000
res['msg'] = 'system error: %s' % str(e) res['msg'] = 'system error: %s' % str(e)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论