chaami hulangamuwa
chaami hulangamuwa

Reputation: 1

How to add unique Item Code every product in open erp

I'm adding a new product to the open erp. However, I'm unable to add a unique number to each product. But there should be a unique product number for every product.

Upvotes: 0

Views: 96

Answers (2)

Kenly
Kenly

Reputation: 26748

You can use @api.constrains decorator.

@api.one
@api.constrains('code')
def _unique_code(self):
    if len(self.search([('code', '=', self.code)])) > 1:
        raise ValidationError("Product code must be unique!")

Upvotes: 1

Nikesh Chaudhary
Nikesh Chaudhary

Reputation: 69

Id is the always unique for all model in openerp.

And another way,

you can also add your custome field for unique number usind "_sql_constraints"

eg: _sql_constraints = [
    ('seq_uniq', 'unique (item_code)', _("The Item Code must be \
        unique per Stage!"))]

Upvotes: 0

Related Questions