I have made a customization that when confirming a sale order, an rfq or more to be created automatically, and when SO is cancelled, the RFQs to be deleted
but I don't want to skip the sequence, for example, if the deleted RFQs have P0004_P0005_P0006
I want the next number to be P0004, not P0007
so i tried to update the sequence next_number but didn't work
here is my code and i would appreciate help
def_action_cancel(self):
res = super(SaleOrder, self)._action_cancel()
purchase_orders = self.env['purchase.order'].search([('source_sale_id', '=', self.id)])
sequence_code = 'purchase.order'# Update with the correct sequence code
for po in purchase_orders:
for order in po:
for inv in order.invoice_ids:
ifinvandinv.state notin ('cancel', 'draft'):
raise UserError(_("Unable to cancel this sale order. You must first cancel the ""vendor bills related to the RFQs."))
po_name = po.name
po.write({'state': 'cancel', 'mail_reminder_confirmed': False})
po.unlink()
sequence = self.env['ir.sequence'].search([ ('code', '=', sequence_code), ('company_id', '=', self.env.company.id) ], limit=1)
if sequence:
sequence_number = int(po_name.split('/')[-1])
next_sequence_number = sequence_number - 1
sequence.sudo().write({'number_next':
next_sequence_number})sequence.sudo().write({'number_next_actual': next_sequence_number})
return res
Why do you have such a requirement? Why not only cancel the RFQ's and not delete? keep the sequence without any gaps.
Btw. If you set up the MTO process for this, I think the RFQ's will be cancelled automatic, if you cancel the sales order.