Odoo Help

Welcome!

This community 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.

0

how to create field unique

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

--Odoo --
1328
| 5 2 5
kerala, India
--Odoo --

Working as a Odoo Functional and Technical Expert

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

--Ben Bernard--
1083
| 4 3 6
Jakarta, Indonesia
--Ben Bernard--
Ben Bernard
On 10/23/14, 1:20 PM

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

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