def write(self, vals): audit = self.env['approval.flow'].search([('approval_cannot_run_id', '=', '修改')]) value_list = list(vals.keys()) receive_list = [] value_list_not_in_receive_list = [i for i in value_list if i not in receive_list] value_list = value_list_not_in_receive_list # 应付 dispatch_number = 0 dispatch_id = self.env['roke.dispatch.order.management.price.approve'].search([('order_id.id', '=', self.id)]) dispatch_list = ['value03', 'value04', 'value05', 'value06', 'value07', 'value08'] if dispatch_id: for rec in value_list: for dispatch_list_id in dispatch_list: if rec == dispatch_list_id: if dispatch_id.approval_status != '未提' and dispatch_id.approval_status != '驳回': raise UserError("应付费用已开始审核不允许修改") value_list_not_in_dispatch_list = [i for i in value_list if i not in dispatch_list] value_list = value_list_not_in_dispatch_list dispatch_number = 1 break if dispatch_number: break # 基础 base_number = 0 base_list = ['client', 'department_manager', 'box_number', 'shipping_companies', 'field_station', 'ship_name_voyage', 'port_of_discharge', 'box_type', 'code', 'bill__of_lading_number', 'departure_date', 'lead_sealing', 'booking_time', 'date_of_pick_up', 'encore_date', 'set_port_date', 'estimated_range', 'destination_port_arrival_time'] if value_list: for rec in value_list: for base_list_id in base_list: if rec == base_list_id: if dispatch_id: if dispatch_id.approval_status != '未提' and dispatch_id.approval_status != '驳回': raise UserError("应付费用已开始审核不允许修改") base_number = 1 break if base_number: break return super(Rokedispatchordermanagement, self).write(vals) audit审核完成如果是修改不能修改如果不是可以修改怎么写可以实现
时间: 2024-02-14 16:17:58 浏览: 210
在给定的代码中,如果修改的字段包含“应付费用”字段,则需要检查“roke.dispatch.order.management.price.approve”模型中的“approval_status”字段,如果不是“未提”或“驳回”,则不能进行修改,否则可以进行修改。如果修改的字段不包含“应付费用”字段,则需要检查是否存在“roke.dispatch.order.management.price.approve”模型,如果存在,则需要检查“approval_status”字段是否为“未提”或“驳回”,如果不是,则不能进行修改,否则可以进行修改。如果不存在“roke.dispatch.order.management.price.approve”模型,则可以直接进行修改。因此,可以在代码中加入以下内容来实现这个逻辑:
```
# 判断是否需要进行审核
if '应付费用' in vals:
dispatch_id = self.env['roke.dispatch.order.management.price.approve'].search([('order_id.id', '=', self.id)])
if dispatch_id and (dispatch_id.approval_status != '未提' and dispatch_id.approval_status != '驳回'):
raise UserError("应付费用已开始审核不允许修改")
else:
dispatch_id = self.env['roke.dispatch.order.management.price.approve'].search([('order_id.id', '=', self.id)])
if dispatch_id and (dispatch_id.approval_status != '未提' and dispatch_id.approval_status != '驳回'):
raise UserError("应付费用已开始审核不允许修改")
elif not dispatch_id:
# 可以直接进行修改
return super(Rokedispatchordermanagement, self).write(vals)
```
以上代码可以放在`write`方法中的`value_list = value_list_not_in_dispatch_list`和`return`之间,以实现对修改的限制。
阅读全文