Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • एस्टेट मैनेजमेंट
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • सीआरएम
  • e-Commerce
  • लेखांकन
  • इन्वेंटरी
  • PoS
  • प्रोजेक्ट
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

How to edit product field

Subscribe

Get notified when there's activity on this post

This question has been flagged
modulereferenceodooV8
4 Replies
10133 Views
Avatar
tudor

Hello,

I'm new to odoo and i'm trying to modify the 'add product' a little, more exactly the internal reference field. I would like to add a dynamic search to it, so that when i start to enter a reference, i get below a list of references that match what i have already entered. More exactly you can see this already implemented in Purchases - Requests for Quotation - Create - Add an item - product column.

I tried to start small and create a simple module to just have the internal reference unique. But i can't figure it out. I've read the few posts that mention this, but i couldn't make it work. My current code is:

class product_product(osv.osv):
    _name = "product.product"
_description = "Product"
_inherits = {'product.template': 'product_tmpl_id'}

_sql_constraints = [
('default_code', 'unique(default_code)', 'Product Reference must be unique!'),
]
product_product()

I also tried this module https://www.odoo.com/apps/modules/8.0/product_unique_default_code/ , but it doesn't work either.

If you have any idea please help. Also, i can't find any proper docs for odoo. Their website seems to only have bits and pieces. Do you know any better tutorials?

Thank you

0
Avatar
Discard
Avatar
tudor
Author Best Answer

Thank you for the answer. Yes, i have already tried like that, too, and it didn't work.

-----

Thank you for the answers. Sorry, apparently i can't comment or post again so the only way to answer seems to edit my only post. First of all sorry for the delay, only now i had the chance to test again.

@Teemur, @Drees Far: if i use only "_inherit = ['product.template']"  then i get an error when trying to install the module: KeyError: 'product_tmpl_id'

@Emipro Technologies Pvt. Ltd.: i have already tried this, but it doesn't do anything. The module installs ok, but then i can add products with the same default_code.

---------

I finally got it to work. It was a combination between all the answers. So, the py code is:

class product_product(osv.osv):
_name = "product.product"
_description = "Product"
_inherit = 'product.product'
_columns = {
'default_code' : fields.char('Internal Reference', select=True),
}
_sql_constraints = [
('default_code', 'unique(default_code)', 'Product Reference must be unique!'),
]

product_product()

and the xml code is

<openerp>
<data>
<record id="view_product_form_inherit" model="ir.ui.view">
<field name="name">product.product.form.inherit</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='default_code']" position="replace">
<field name="default_code"/>
</xpath>
</field>
</record>
</data>
</openerp>

Thank you for the help. Does anybody have any pointers about how to achieve the final goal: dynamic search, so that when i start to enter a reference, i get below a list of references that match what i have already entered. More exactly you can see this already implemented in Quotations - Create - Add an item - product column.

0
Avatar
Discard
Emipro Technologies Pvt. Ltd.

Please read answer carefully. Answer is also useful when you implement your code as you have written. My answer is for old data not for the code or module installation error. Even module is successfully installed then also you can enter duplicate default_code if unique constraint is not applied. And I have stated that in some of the case module is installed but constraint is not applied. I hope you will also care for the old data. thanks.

Avatar
Temur
Best Answer

are you sure you need to use inheritance by delegation as  _inherits = {'product.template': 'product_tmpl_id'}  ?

try with usual inheritance (a _inherit, NOT the _inherits):

_inherit = 'product.template'

refer to the documentation

1
Avatar
Discard
Avatar
Rihene
Best Answer

Try this friend:

class product_product(osv.osv):

_name = "product.product"

_description = "Product"

_inherit = ['product.template']

_sql_constraints = [

('default_code', 'unique(default_code)', 'Product Reference must be unique!'),

] 

If it doesnt work

try this:

class product_product(osv.osv):

_name = "product.product"

_description = "Product"

_inherit = ['product.template']

_columns = {

'default_code' : fields.char('Internal Reference', select=True),

_sql_constraints = [

('default_code', 'unique(default_code)', 'Product Reference must be unique!'),

]

}

And dont forget to add in your XML:


<record id="view_product_form_inherit" model="ir.ui.view">

<field name="name">product.product.form.inherit</field>

<field name="model">product.product</field>

<field name="inherit_id" ref="product.product_normal_form_view"/>

<xpath expr="//field[@name='default_code']" position="replace">

<field name="default_code"/>

</xpath>

</field>

</record>

</data>

</openerp>

PS : Pay attention to the model and name of view in your XML.

1
Avatar
Discard
Avatar
Emipro Technologies Pvt. Ltd.
Best Answer

Hello,

According to the below code Odoo will add one unique constraint inside postgresql database.

class product_product(osv.osv):
_name = "product.product"
_description = "Product"
_inherit = 'product.product'

_sql_constraints = [
('default_code', 'unique(default_code)', 'Product Reference must be unique!'),
]
product_product()

But according to the already available records there may be some situations like :

1) When all records have default_code is already unique : In this case when Odoo is going to add unique constraint on the field default_code at that time inside database one constraint is added for the field default_code inside product_product table, and it is added successfully. After that you can also see the effect of that constraint and you can not make any duplicate value inside default_code field.

2) When all records have default_code is not unique / Already there are some duplicate value is there : In this case when Odoo is going to add unique constraint on the field default_code at that time inside database it is not possible to apply unique constraint on already duplicated data. So, at that time constraint will not perfectly done at database side and Odoo also give us WARNING :

"""Table 'product_product': unable to add 'unique(default_code)' constraint ! If you want to have it, you should update the records and execute manually:  ALTER TABLE "product_product" ADD CONSTRAINT "product_product_default_code" unique(default_code)"""  

So, in this case if we want to apply this constraint first of all we have to make changes inside database to do so all default_code value is unique and then after just upgrade the module again, Odoo will add that constraint on that field or you can execute manual query as give inside warning.


In your code might be the issue of the data not of code. I hope it is helpful to you for understanding that how _sql_constraint is work in Odoo.

Thanks.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Developing new modules, KeyError: 'stock.picking' return self.models[model_name] Solved
module update odooV8
Avatar
Avatar
1
जन॰ 25
24301
Error in Apps Server.
module apps odooV8
Avatar
Avatar
Avatar
4
मार्च 16
5605
Developing new module, am I using API v7 in this block of code?
module api odooV8
Avatar
Avatar
2
फ़र॰ 16
4197
Is it possible to create columns dynamically?
module custom odooV8
Avatar
0
मार्च 25
5209
How to relation 2 model
reference relation odooV8
Avatar
0
दिस॰ 15
3522
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now