Hi every one
HAPPY NEW YEAR
I use this code to generate 2 sequence codes & validate for prebent duplication while importing from a CSV file, but the sequence code increases when clicking on the "TEST" button, if the user click 5 times on the test button to check for any error the sequence code increases 5 times,
any one can help me to solve this issue?
@api.model
def create(self, vals):
# Check for duplicates during record creation
if 'indent_no' in vals:
existing_record = self.search([('indent_no', '=', vals['indent_no'])])
if existing_record:
raise ValidationError("The Indent Number Already Exists!")
# Generate sequence for 'name' field
vals['name'] = self.env['ir.sequence'].next_by_code('vessel.indent')
vals['unique_code'] = self.env['ir.sequence'].next_by_code('vessel.indent.un.code')
return super(VesselIndent, self).create(vals)
Check record is created when you click on the Test button,
https://www.cybrosys.com/blog/how-to-create-sequence-number-in-odoo-15