class ApprovalFlow(models.Model): _name = 'approval.flow' _description = u'审批流程' approval_cannot_run_id = fields.Many2many('execute.function.not.list', 'function_not_rel', u'完成后不能执行操作', help=u'审批流程完成后不能能执行的操作,修改,删除') class Rokedispatchordermanagement(models.Model): _name = 'roke.dispatch.order.management' _inherit = ['mail.thread', 'mail.activity.mixin'] _description = "派船单" _rec_name = "code" client = fields.Many2one('roke.partner', string='客户', tracking=True, required=True, ) department_manager = fields.Many2one('res.users', string='创建人', tracking=True, default=lambda self: self.env.user.id) box_number = fields.Char(string='箱号') shipping_companies = fields.Char(string='船公司') field_station = fields.Char(string='场站') ship_name_voyage = fields.Char(string='船名航次') port_of_discharge = fields.Char(string='卸货港') box_type = fields.Many2one('roke.box.type', string='箱型') code = fields.Char(string='单据编号', track_visibility='onchange') def unlink(self): audit = self.env['approval.flow'] for record in audit: if record.approval_can_run_id == '删除': raise UserError("不能删除") return super(Rokedispatchordermanagement, self).unlink() approval.flow模型在另一个文件中在roke.dispatch.order.management重新删除方法不能删除approval_can_run_id值等于删除的
时间: 2024-02-03 11:02:50 浏览: 133
根据你的代码,我理解您想要在删除Rokedispatchordermanagement模型的记录之前,检查approval_can_run_id值是否等于“删除”,如果是,则不允许删除。但是,您的代码中有几个错误。
首先,您需要将“unlink”方法的重写代码放在“Rokedispatchordermanagement”模型中,而不是在“approval.flow”模型中。
其次,您应该在每个记录上检查approval_can_run_id的值,而不是在“approval.flow”模型上进行操作。您可以使用“self”关键字来引用当前记录。
最后,您需要使用“in”运算符来检查approval_can_run_id是否包含“删除”值,而不是使用“==”运算符来比较。
下面是更正后的代码:
```
class Rokedispatchordermanagement(models.Model):
_name = 'roke.dispatch.order.management'
_inherit = ['mail.thread', 'mail.activity.mixin']
_description = "派船单"
_rec_name = "code"
client = fields.Many2one('roke.partner', string='客户', tracking=True, required=True)
department_manager = fields.Many2one('res.users', string='创建人', tracking=True, default=lambda self: self.env.user.id)
box_number = fields.Char(string='箱号')
shipping_companies = fields.Char(string='船公司')
field_station = fields.Char(string='场站')
ship_name_voyage = fields.Char(string='船名航次')
port_of_discharge = fields.Char(string='卸货港')
box_type = fields.Many2one('roke.box.type', string='箱型')
code = fields.Char(string='单据编号', track_visibility='onchange')
def unlink(self):
for record in self:
if '删除' in record.approval_can_run_id.mapped('name'):
raise UserError("不能删除")
return super(Rokedispatchordermanagement, self).unlink()
```
这个更正后的代码应该可以达到您想要的效果。
阅读全文