提交 2656a7c1 authored 作者: 贺阳's avatar 贺阳

提单状态

上级 44d2fe95
......@@ -670,6 +670,12 @@ class CcBL(models.Model):
# 通关文件, 关联附件对象(类型限定为image和PDF)
cc_attachment_ids = fields.One2many('cc.clearance.file', 'bl_id', string='Clearance Files')
# 提单上新增字段:关务提单状态,用英文:关联节点的配置(cc.node),节点类型过滤提单的节点名称。
customs_clearance_status = fields.Many2one('cc.node', string='Customs Clearance Status',
domain=[('node_type', '=', 'bl')])
# 增加提单状态操作时间
process_time = fields.Datetime(string='Process Time')
# 增加一个can_cancel的方法,用于检查提单当前是否可以取消,返回True表示可以取消, False表示不可以取消,同时返回取消的原因
def check_cancel(self):
if self.is_cancel:
......
......@@ -48,3 +48,8 @@ class CcNode(models.Model):
('checked_goods', 'Checked goods'),
('handover_completed', 'Handover Completed')
], default='', string='Corresponding to the status of the big package', index=True) # 对应大包状态 未理货/已理货/尾程交接
# 新增字段:对应小包状态。只有类型为提单上才可填写。可选已配置节点类型为小包的节点。单选;
package_state = fields.Many2one('cc.node', string='Corresponding to the status of the package',domain="[('node_type','=','package')]", index=True) # 对应小包状态
......@@ -50,8 +50,12 @@
<!-- # 为action_batch_input_ship_package_wizard添加一个按钮, 上下文中添加bl_id-->
<button name="%(action_batch_input_ship_package_wizard)d" type="action" class="oe_highlight"
string="Update Ship Package Status"
context="{'default_bl_id': active_id, 'active_id': id}"/>
context="{'default_bl_id': active_id, 'active_id': id,'default_action_type':'小包'}"/>
<button name="%(action_batch_input_ship_package_wizard)d" type="action" class="oe_highlight"
string="Update BL Status"
context="{'active_id': id,'default_action_type':'提单'}"/>
<field name="state" widget="statusbar" options="{'clickable': '1'}"/>
</header>
<sheet>
......
......@@ -82,55 +82,57 @@ class BatchInputShipPackageStatusWizard(models.TransientModel):
state_explain = fields.Text('State Explain', help='State Explain')
node_exception_reason_id = fields.Many2one('cc.node.exception.reason', 'Exception Reason',
domain="[('code_id', '=', update_status)]")
action_type = fields.Char(string='Action Type', default='小包')
# 批量更新小包状态
def submit(self):
# 确认数据
if not self.is_ok:
raise ValidationError('Please confirm that the above data is correct.') # 请确认以上数据正确
parcels = self.get_process_package()
if not parcels:
raise ValidationError(_('No package to update found.')) # 没有找到要更新的小包
# 1.若选择的更新节点为是当前节点【清关节点设置,是当前节点字段名称改为初始节点】,当更新节点为初始节点时,无需填写操作时间;
# if self.update_status and not self.update_status.is_default:
# 2.若选择的更新节点为“选择节点”的后续节点(根据节点设置排序),则按照操作时间不能大于当前时间,且不能早于最近的操作时间。
# 3.若选择的“更新节点”为“选择节点”的前序节点(根据节点设置排序),则查找“选择节点”是否已有同步日志,若有,则操作时间不允许早于前序节点同步日志里的操作时间,且不能大于当前时间。若有多条,以同步时间最晚的一条为准。
# 4.若选择的“更新节点”和“选择节点”一致时,需检查该节点的前序节点是否有同步日志,若有,则操作时间不允许早于前序节点同步日志里的操作时间,且不能大于当前时间。同一节点若有多条同步日志,以同步时间最晚的一条为准。
# 判断异常状态是否选择了异常原因
reason_obj = self.env['cc.node.exception.reason'].search([('code_id', '=', self.update_status.id)])
if reason_obj and not self.node_exception_reason_id:
raise ValidationError(_('Please select the reason for the exception!')) # 请选择异常原因
# 如果更新节点是 默认节点 同步的标志变为True
is_sync = False
if self.update_status.is_default:
is_sync = True
# 更新状态
parcels.write(
{'state': self.update_status.id, 'node_exception_reason_id': self.node_exception_reason_id.id,
'process_time': self.process_time, 'state_explain': self.state_explain, 'is_sync': is_sync})
# if parcels:
# where_sql = " where id={0}".format(parcels[0].id) if len(
# parcels) == 1 else " where id in {0}".format(tuple(parcels.ids))
# update_sql = """update cc_ship_package set node_exception_reason_id={0},process_time='{1}',state_explain='{2}',is_sync={3} {4}""".format(
# self.node_exception_reason_id.id if self.node_exception_reason_id else False,
# self.process_time, self.state_explain or '', is_sync,
# where_sql)
# update_sql = update_sql.replace("'False'", "null").replace("False", "null")
# self._cr.execute(update_sql)
# parcels.write({'state': self.update_status.id})
# for parcel in parcels:
# parcel.message_post(body='%s改为%s' % (self.current_status.name, self.update_status.name))
# 生成sns日志
# self.bl_id.message_post(body='%s更新为%s' % (self.current_status.name or '', self.update_status.name or ''))
# 跳转显示本次更新状态的小包 更新小包状态
return {
'name': _('Update the status of the small package'),
'type': 'ir.actions.act_window',
'res_model': 'cc.ship.package',
'view_mode': 'tree,form',
'domain': [('id', 'in', parcels.ids)],
}
if self.action_type == '小包':
parcels = self.get_process_package()
if not parcels:
raise ValidationError(_('No package to update found.')) # 没有找到要更新的小包
# 1.若选择的更新节点为是当前节点【清关节点设置,是当前节点字段名称改为初始节点】,当更新节点为初始节点时,无需填写操作时间;
# if self.update_status and not self.update_status.is_default:
# 2.若选择的更新节点为“选择节点”的后续节点(根据节点设置排序),则按照操作时间不能大于当前时间,且不能早于最近的操作时间。
# 3.若选择的“更新节点”为“选择节点”的前序节点(根据节点设置排序),则查找“选择节点”是否已有同步日志,若有,则操作时间不允许早于前序节点同步日志里的操作时间,且不能大于当前时间。若有多条,以同步时间最晚的一条为准。
# 4.若选择的“更新节点”和“选择节点”一致时,需检查该节点的前序节点是否有同步日志,若有,则操作时间不允许早于前序节点同步日志里的操作时间,且不能大于当前时间。同一节点若有多条同步日志,以同步时间最晚的一条为准。
# 判断异常状态是否选择了异常原因
reason_obj = self.env['cc.node.exception.reason'].search([('code_id', '=', self.update_status.id)])
if reason_obj and not self.node_exception_reason_id:
raise ValidationError(_('Please select the reason for the exception!')) # 请选择异常原因
# 如果更新节点是 默认节点 同步的标志变为True
is_sync = False
if self.update_status.is_default:
is_sync = True
# 更新状态
parcels.write(
{'state': self.update_status.id, 'node_exception_reason_id': self.node_exception_reason_id.id,
'process_time': self.process_time, 'state_explain': self.state_explain, 'is_sync': is_sync})
# if parcels:
# where_sql = " where id={0}".format(parcels[0].id) if len(
# parcels) == 1 else " where id in {0}".format(tuple(parcels.ids))
# update_sql = """update cc_ship_package set node_exception_reason_id={0},process_time='{1}',state_explain='{2}',is_sync={3} {4}""".format(
# self.node_exception_reason_id.id if self.node_exception_reason_id else False,
# self.process_time, self.state_explain or '', is_sync,
# where_sql)
# update_sql = update_sql.replace("'False'", "null").replace("False", "null")
# self._cr.execute(update_sql)
# parcels.write({'state': self.update_status.id})
# for parcel in parcels:
# parcel.message_post(body='%s改为%s' % (self.current_status.name, self.update_status.name))
# 生成sns日志
# self.bl_id.message_post(body='%s更新为%s' % (self.current_status.name or '', self.update_status.name or ''))
# 跳转显示本次更新状态的小包 更新小包状态
return {
'name': _('Update the status of the small package'),
'type': 'ir.actions.act_window',
'res_model': 'cc.ship.package',
'view_mode': 'tree,form',
'domain': [('id', 'in', parcels.ids)],
}
def get_process_package(self):
"""获取要更新的小包"""
......
......@@ -24,6 +24,7 @@
'views/config_settings_views.xml',
# 'views/flight_order_view.xml',
'views/cc_ship_package_sync_log_view.xml',
'views/cc_bl_sync_log_view.xml',
'views/ao_tt_api_log_view.xml',
'views/cc_node_view.xml',
'views/cc_ship_package_view.xml',
......
......@@ -44,8 +44,8 @@ class TT(models.Model):
def callback_track(self, push_data):
"""包裹轨迹回传"""
url = '/logistics/provider/cross_border/callback_track?country=GB'
"""包裹轨迹/提单状态回传"""
url = '/logistics/provider/cross_border/callback_track?country=GB'
# cb_excustoms_finished 出口清关完毕
# cb_transport_assigned 干线揽收
timestamp = int(time.time())
......@@ -66,7 +66,7 @@ class TT(models.Model):
def mwb_status_update(self, push_data):
"""清关提单状态回传"""
url = 'logistics/provider/customs/mwb_status_update'
url = 'logistics/provider/customs/mwb_status_update?country=GB'
timestamp = int(time.time())
sign = self.generate_sign(timestamp, push_data)
response = self.get_response(url, sign, timestamp, push_data)
......@@ -126,20 +126,20 @@ class TT(models.Model):
'app_key': app_key
}
request_url = tt_url + url
logging.info('request_url: %s' % request_url)
logging.info('request_data: %s' % parameter)
# logging.info('request_url: %s' % request_url)
# logging.info('request_data: %s' % parameter)
for i in range(3): # 尝试最多3次
try:
async with session.post(request_url, headers=headers, data=parameter) as response:
response_data = await response.json()
logging.info('response: %s', response_data)
# logging.info('response: %s', response_data)
# print(response.json())
return response_data
except Exception as e:
if i < 2: # 如果不是最后一次尝试,等待后重试
await asyncio.sleep(2 ** i) # 指数退避策略
else:
logging.warning('request error:%s' % str(e))
# logging.warning('request error:%s' % str(e))
return {'code': 500, 'requestID': 'request error timeout', 'msg': '超时,请重试'} # 如果重试次数用尽,抛出异常
async def async_callback_track_callback(self, session, push_data, package_id):
......@@ -157,3 +157,17 @@ class TT(models.Model):
"""异步调用推送接口"""
# async with semaphore:
return await self.async_callback_track_callback(session, data, package_id)
async def async_bl_callback_track_callback(self, session, push_data, package_id):
"""提单状态回传"""
url = '/logistics/provider/customs/mwb_status_update?country=GB'
timestamp = int(time.time())
sign = self.generate_sign(timestamp, push_data)
response = await self.async_get_response(session, url, sign, timestamp, push_data)
logging.info('bl_callback_track response:%s' % response)
return response, push_data, package_id
async def async_bl_callback_track(self, session, data, bl_id):
"""异步调用提单推送接口"""
# async with semaphore:
return await self.async_bl_callback_track_callback(session, data, bl_id)
......@@ -7,3 +7,10 @@ access_cc_ship_package_sync_log_base.group_erp_manager,cc_ship_package_sync_log
access_cc_ship_package_sync_log_ccs_base.group_clearance_of_customs_manager,cc_ship_package_sync_log ccs_base.group_clearance_of_customs_manager,ccs_connect_tiktok.model_cc_ship_package_sync_log,ccs_base.group_clearance_of_customs_manager,1,0,0,0
access_cc_ship_package_sync_log_ccs_base.group_clearance_of_customs_user,cc_ship_package_sync_log ccs_base.group_clearance_of_customs_user,ccs_connect_tiktok.model_cc_ship_package_sync_log,ccs_base.group_clearance_of_customs_user,1,0,0,0
access_cc_bl_sync_log_base.group_user,cc_bl_sync_log base.group_user,ccs_connect_tiktok.model_cc_bl_sync_log,base.group_user,1,0,0,0
access_cc_bl_sync_log_base.group_erp_manager,cc_bl_sync_log base.group_erp_manager,ccs_connect_tiktok.model_cc_bl_sync_log,base.group_erp_manager,1,1,1,1
access_cc_bl_sync_log_ccs_base.group_clearance_of_customs_manager,cc_bl_sync_log ccs_base.group_clearance_of_customs_manager,ccs_connect_tiktok.model_cc_bl_sync_log,ccs_base.group_clearance_of_customs_manager,1,0,0,0
access_cc_bl_sync_log_ccs_base.group_clearance_of_customs_user,cc_bl_sync_log ccs_base.group_clearance_of_customs_user,ccs_connect_tiktok.model_cc_bl_sync_log,ccs_base.group_clearance_of_customs_user,1,0,0,0
<?xml version="1.0" encoding="utf-8"?>
<odoo>
# ---------- CC Bl Sync Log ------------
<record model="ir.ui.view" id="tree_cc_bl_sync_log_view">
<field name="name">tree.cc.bl.sync.log</field>
<field name="model">cc.bl.sync.log</field>
<field name="arch" type="xml">
<tree string="CC Bl Sync Log">
<field optional="show" name="bl_id" string="Bill of Loading"/>
<field optional="show" name="api_customer" string="Api Customer"/>
<field optional="show" name="process_code" string="TK Process Code"/>
<field optional="show" name="progress_name" string="Progress Name"/>
<field optional="show" name="operate_time" string="Operate Time"/>
<field optional="show" name="operate_user" string="Operate User"/>
<field optional="show" name="sync_time" string="Sync Time"/>
</tree>
</field>
</record>
<record model="ir.ui.view" id="form_cc_bl_sync_log_view">
<field name="name">form.cc.bl.sync.log</field>
<field name="model">cc.bl.sync.log</field>
<field name="arch" type="xml">
<form string="CC Bl Sync Log">
<sheet>
<group>
<group>
<field name="bl_id" string="Bill of Loading"/>
<field name="api_customer" string="Api Customer"/>
<field name="process_code" string="TK Process Code"/>
<field name="progress_name" string="Progress Name"/>
<field name="operate_time" string="Operate Time"/>
<field name="operate_user" string="Operate User"/>
<field name="sync_time" string="Sync Time"/>
</group>
<group>
</group>
</group>
<notebook>
<page string="Operate Remark">
<field name="operate_remark" string="Operate Remark"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="search_cc_bl_sync_log_view">
<field name="name">search.cc.bl.sync.log</field>
<field name="model">cc.bl.sync.log</field>
<field name="arch" type="xml">
<search string="CC Bl Sync Log">
<field name="bl_id" string="Bill of Loading"/>
<field name="api_customer" string="Api Customer"/>
<field name="process_code" string="TK Process Code"/>
<field name="operate_time" string="Operate Time"/>
<field name="operate_user" string="Operate User"/>
<field name="sync_time" string="Sync Time"/>
<separator/>
<filter name="filter_operate_time" string="Operate Time" date="operate_time"/>
<filter name="filter_sync_time" string="Sync Time" date="sync_time"/>
<separator/>
<group expand="0" string="Group By">
<filter domain="[]" name="groupby_bl_id" string="Bill of Loading"
context="{'group_by': 'bl_id'}"/>
<filter domain="[]" name="groupby_operate_user" string="Operate User"
context="{'group_by': 'operate_user'}"/>
</group>
</search>
</field>
</record>
<record model="ir.actions.act_window" id="action_cc_bl_sync_log">
<field name="name">CC Bl Sync Log</field>
<field name="res_model">cc.bl.sync.log</field>
<field name="view_mode">tree</field>
<field name="domain">[]</field>
<field name="context">{}</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
[CC Bl Sync Log] Not yet! Click the Create button in the top left corner and the sofa is yours!
</p>
<p>
</p>
</field>
</record>
</odoo>
\ No newline at end of file
......@@ -24,6 +24,8 @@
<header position="inside">
<button name="callback_track" string="Sync Package Status" type="object"/>
<button name="batch_action_sync" string="Sync CC Attachment" type="object"/>
<!--增加同步提单状态的按钮-->
<button name="action_sync_bl_status" string="Sync Bl Status" type="object"/>
</header>
<button name="action_show_ship_package" position="replace">
......@@ -45,48 +47,9 @@
</div>
</button>
</button>
</field>
</record>
<!-- # 继承ccs_base模块的cc_ship_package_view.xml视图,增加is_sync字段在列表中-->
<record model="ir.ui.view" id="tree_cc_ship_package_view_inherit">
<field name="name">tree_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.tree_cc_ship_package_view"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="is_sync"/>
</field>
<tree position="attributes">
<attribute name="decoration-danger">is_sync == False</attribute>
</tree>
</field>
</record>
<!-- # 继承ccs_base模块的search_cc_ship_package_view视图,装置加未同步的筛选条件-->
<record model="ir.ui.view" id="search_cc_ship_package_view_inherit">
<field name="name">search_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.search_cc_ship_package_view"/>
<field name="arch" type="xml">
<search position="inside">
<filter string="Not Sync" name="filter_is_sync" domain="[('is_sync','=',False)]"/>
</search>
</field>
</record>
# 继承ccs_base模块的form_cc_ship_package_view视图,增加同步日志列表在notebook中
<record model="ir.ui.view" id="form_cc_ship_package_view_inherit">
<field name="name">form_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.form_cc_ship_package_view"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Sync Log">
<field name="sync_log_ids" widget="one2many_list"/>
<field name="bl_sync_log_ids" widget="one2many_list"/>
</page>
</notebook>
</field>
......@@ -100,7 +63,7 @@
<field name="state">code</field>
<field name="code">
if records:
records.callback_track()
records.callback_track()
</field>
</record>
......@@ -110,11 +73,11 @@
<field name="model_id" ref="model_cc_bl"/>
<field name="binding_model_id" ref="model_cc_bl"/>
<field name="binding_view_types">list</field>
<field name="groups_id" eval="[(4, ref('base.group_system'))]"/>
<field name="groups_id" eval="[(4, ref('base.group_system'))]"/>
<field name="state">code</field>
<field name="code">
if records:
records.deal_ship_package_state()
records.deal_ship_package_state()
</field>
</record>
</data>
......
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="tree_cc_ship_package_view">
<field name="name">tree.cc.ship.package</field>
<!-- # 继承ccs_base模块的cc_ship_package_view.xml视图,增加is_sync字段在列表中-->
<record model="ir.ui.view" id="tree_cc_ship_package_view_inherit">
<field name="name">tree_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.tree_cc_ship_package_view"/>
<field name="arch" type="xml">
<field name="state" position="after">
<field name="is_sync"/>
</field>
<field name="state" position="replace">
<field name="tk_code" invisible="1"/>
<field optional="show" name="state" string="Progress" widget="badge"
......@@ -13,7 +19,35 @@
decoration-warning="tk_code in ('cb_imcustoms_inspection','cb_imcustoms_exception')"
decoration-muted="tk_code=='cb_import_customs_failure'"/>
</field>
<tree position="attributes">
<attribute name="decoration-danger">is_sync == False</attribute>
</tree>
</field>
</record>
<!-- # 继承ccs_base模块的search_cc_ship_package_view视图,装置加未同步的筛选条件-->
<record model="ir.ui.view" id="search_cc_ship_package_view_inherit">
<field name="name">search_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.search_cc_ship_package_view"/>
<field name="arch" type="xml">
<search position="inside">
<filter string="Not Sync" name="filter_is_sync" domain="[('is_sync','=',False)]"/>
</search>
</field>
</record>
# 继承ccs_base模块的form_cc_ship_package_view视图,增加同步日志列表在notebook中
<record model="ir.ui.view" id="form_cc_ship_package_view_inherit">
<field name="name">form_cc_ship_package_view_inherit</field>
<field name="model">cc.ship.package</field>
<field name="inherit_id" ref="ccs_base.form_cc_ship_package_view"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Sync Log">
<field name="sync_log_ids" widget="one2many_list"/>
</page>
</notebook>
</field>
</record>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论