hi all
this is my code to create custom code for every new variant but return same "cust_product_code" for all template variants "product.product"
any idea ?
class InheritProductProduct(models.Model):
_inherit = 'product.product'
cust_product_code = fields.Char("Product Code")
category_code = fields.Integer(related='categ_id.category_code', readonly=True, store=True)
template_code = fields.Integer(related='product_tmpl_id.template_code', readonly=True, store=True)
@api.model
def create(self, vals):
res = super(InheritProductProduct, self).create(vals)
for rec in res:
prod = self.search([('categ_id', '=', rec.categ_id.id), ('product_tmpl_id', '=', rec.product_tmpl_id.id)],
limit=1, order='cust_product_code desc')
if prod:
seq = int(prod.cust_product_code[6:12]) + 1
rec.cust_product_code = str(rec.category_code) + str(rec.template_code) + str(seq).zfill(7)
else:
seq = "0000001"
rec.cust_product_code = str(rec.category_code) + str(rec.template_code) + seq
return res
class InheritProductProduct(models.Model):
_inherit = 'product.product'
cust_product_code = fields.Char("Product Code")
category_code = fields.Integer(related='categ_id.category_code', readonly=True, store=True)
template_code = fields.Integer(related='product_tmpl_id.template_code', readonly=True, store=True)
@api.model
def create(self, vals):
res = super(InheritProductProduct, self).create(vals)
for rec in res:
prod = self.search([('categ_id', '=', rec.categ_id.id), ('product_tmpl_id', '=', rec.product_tmpl_id.id)],
limit=1, order='cust_product_code desc')
if prod:
seq = int(prod.cust_product_code[6:12]) + 1
rec.cust_product_code = str(rec.category_code) + str(rec.template_code) + str(seq).zfill(7)
else:
seq = "0000001"
rec.cust_product_code = str(rec.category_code) + str(rec.template_code) + seq
return res