Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to edit product field

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
modulereferenceodooV8
4 Replies
10135 Tampilan
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
Buang
Avatar
tudor
Penulis Jawaban Terbai

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
Buang
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
Jawaban Terbai

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
Buang
Avatar
Rihene
Jawaban Terbai

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
Buang
Avatar
Emipro Technologies Pvt. Ltd.
Jawaban Terbai

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
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Developing new modules, KeyError: 'stock.picking' return self.models[model_name] Diselesaikan
module update odooV8
Avatar
Avatar
1
Jan 25
24304
Error in Apps Server.
module apps odooV8
Avatar
Avatar
Avatar
4
Mar 16
5605
Developing new module, am I using API v7 in this block of code?
module api odooV8
Avatar
Avatar
2
Feb 16
4197
Is it possible to create columns dynamically?
module custom odooV8
Avatar
0
Mar 25
5209
How to relation 2 model
reference relation odooV8
Avatar
0
Des 15
3534
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik 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