跳至內容
選單
此問題已被標幟
1 回覆
620 瀏覽次數

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

作者 最佳答案

thanks for your reply

I have no problem with the generation auto sequence code, the problem is with every click on the test button while importing a record the sequence code also increases, if the user clicks 5 times and the next by code is 6 the generation code after successful import record is 11 and this makes a problem.

頭像
捨棄