'Override create method to Restrict user from creating a new record based on condition Odoo13
I want to restrict the user from creating a new record on a model based on a specific condition. for instance, I have two fields in the model both of them is Integer (move_item_count,item_number ) and they are computed field I compute their values. If their move_item_count != item_number I should prevent the user from creating the record and raise an error message. here is my code it gives me this error 'NoneType' object has no attribute 'id'.
here is my code :
# Overriding the Create Method in Odoo
@api.model
def create(self, vals):
# overriding the create method to add the sequence and prevent the user from
# creating a new record if a condition didn't fulfilled
for rec in self:
if rec.move_item_count != rec.item_number:
raise UserError(_("Some Item Are Missing."))
if vals.get('name', _('New')) == _('New'):
vals['name'] = self.env['ir.sequence'].next_by_code('move.sequence') or _('New')
result = super(LogisticMove, self).create(vals)
return result
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
