The write function is not updating while raising an error
@api.model
def create(self,vals):
record = self.search([('create_uid', '=', self.env.user.id), ('purchase_order_type', '=', 'po_type_local'), ('state', 'not in', ['sent', 'draft'])])
for rec in record:
d1 = datetime.strptime(rec.date_order, '%Y-%m-%d %H:%M:%S')
d2 = datetime.strptime(fields.Date.today(), '%Y-%m-%d')
d3 = fields.Date.today()
daysDiff = str((d2-d1).days+1)
if self.env.user.lpo_extend < d3:
if int(daysDiff) > 2:
if rec.invoice_count == 0:
self.env.user.write({'lpo_block': True})
raise UserError("You cannot create this order! Previous LPO is not processed yet!")
count = 0
if self.env.user.lpo_extend < d3:
for line in rec.invoice_ids:
if line.state != 'draft':
count += 1
if int(daysDiff) > 2:
if count == 0:
self.env.user.write({'lpo_block': True})
raise UserError("You cannot create this order! Previous LPO is not processed yet!")
return super(PurchaseOrder, self).create(vals)