Odoo Help

0

how to create field unique

By
oussama
on 10/23/14, 10:12 AM 1,283 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

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 - Technical Consultant, Sodexis Inc
on 10/24/14, 4:37 AM
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

oussama
on 10/24/14, 4:48 AM
0
laribi
On 10/23/14, 10:55 AM

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.

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

oussama
on 10/23/14, 1:09 PM
0
Odoo
On 10/23/14, 1:26 PM

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

Thanks for your response but it not working

oussama
on 10/24/14, 4:21 AM
0
Ben Bernard
On 10/23/14, 1:20 PM

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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 10/23/14, 10:12 AM
Seen: 1283 times
Last updated: 3/16/15, 8:10 AM