Hi All,
I am trying to auto-generate the "Default Code" or "Internal Reference" by using logic as below. What I am experiencing that when multiple users try to create product records, my code generates duplicate codes. Probably, an issue with record locking when creating a code using custom code.
Can someone help ...
My code as below -
@api.model
def get_facode(self):
last_facode_rec = self.env['product.product'].search([('default_code', 'like', 'FA')], order='default_code DESC', limit=1)
if not last_facode_rec and len(last_facode_rec) == 0:
return 'FA000001'
last_facode = last_facode_rec[0].default_code
if last_facode and last_facode != '':
new_facode = last_facode[:2] + ("000000" + str(int(last_facode[2:])+1))[-6:]
else:
new_facode = 'FA000001'
return new_facode