This question has been flagged
8 Replies
8587 Views

Hi

how to change field default_code in product.product to unique

my code

from __future__ import division
from openerp.osv import fields, osv

class product_product(osv.osv):
    
    _inherit = 'product.product'
     


    _columns = {

        'default_code' : fields.char('Internal Reference', size=64, select=True),
        }
 
    _sql_constraints = [('ref_unique','unique(default_code)', 'reference must be unique!')]     

product_product()    

 

 

 

thanks

Avatar
Discard

is it working fine for you? or check this link: https://github.com/OCA/product-attribute/blob/7.0/product_sequence/product_product.py

Thanks a lot 

2014-10-24 9:37 GMT+01:00 atchuthan <atchuthantu@mail.odoo.com>:

is it working fine for you? or check this link: https://github.com/OCA/product-attribute/blob/7.0/product_sequence/product_product.py

--
atchuthan

Best Answer
Like laribi said, you need to check if in the database exist some field duplicated. In this case, won't work the 

_sql_constraints because don't add the constraints to the table, until there no exist duplicate fields inside the table.

Avatar
Discard
Best Answer

Hi ,

Your code is correct. You must only verify if there is already records with the same default code before restarting server and edit them because the constraint can not be applied in that case.

Avatar
Discard
Author

Hi laribi I delete all products and i created other but it not working. Thanks

Best Answer

Hi,

change your code like below I mentioed might be work

   _sql_constraints=[('unique_dept_id','unique(name)','Error! Enter unique dept id')]   ,Please mark if it is resloved

Avatar
Discard
Author

Thanks for your response but it not working

Best Answer

'unique(reference)' -> 'unique(default_code)'

Avatar
Discard