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

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

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