Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Problem with computed field

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
constraintcomputed-fieldsodoo16features
1 Răspunde
4602 Vizualizări
Imagine profil
Masood Zarei

Hi,

My requirement as brief:

  • Root contact is a contact whose parent_id is None
  • I don't want to have *root contacts* with the same email/country
  • I need to use sql_constraints to fix this issue
  • I need to define a new field named root_contact for all contacts and set it to 0 or 1 for all contacts

So,

I've defined root_contact as:

root_contact = fields.Integer(
​string="Root Contact",
​compute="_compute_root_contact",
​copy=False,
​store=True
)
And the function is:
def_compute_root_contact(self):
​if(self.parent_id):
​ ​self.root_contact = 0
​else:
​ ​self.root_contact = 1

As there are many previous contacts in the contact list, how can I set this field for all contacts?

Later, I want to set sql_constraints as below:

_sql_constraints = [        
​('email_country_parent_uniq', 'UNIQUE(root_contact,email,country_id)',
​ ​'A root contact with the same info is presented before. \
​ Please edit that contact or define a new one with different info.')
]

Problems:

  1. If I use store=True the compute function doesn't call at all, and in this case, based on the Odoo document, I need to set @api.onchange to be able to call this method (and this is not the thing I want).
  2. If I don't use store=True so the field doesn't store in the database and so, I could not use the field in sql_constraints

From Postgres 15, a new feature is added named 'NULLS NOT DISTINCT' that can be used with the combination of UNIQUE in sql_constraints and this is the best-fit choice for my requirement but I'm using Postgres 14.

0
Imagine profil
Abandonează
Imagine profil
Cybrosys Techno Solutions Pvt.Ltd
Cel mai bun răspuns

Hi,

Try use @api.depends with a computed field to store in the db and recompute when the value of the field changes.

Please refer this tutorial:

https://www.cybrosys.com/odoo-development-tutorial/v14/computed-fields-api-depends/

Regards

1
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
What is the use of precompute attribute on computed fields? Rezolvat
computed-fields odoo16features
Imagine profil
Imagine profil
1
sept. 23
10107
compute field not working...
method computed-fields odoo16features
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
apr. 24
3370
how i can get value of json type data
computed-fields odoo16features v17
Imagine profil
0
ian. 24
2386
Compute Fields Based on Another Model - Dependencies ?
studio computed-fields odoo16features
Imagine profil
Imagine profil
2
iun. 23
5882
Check uniqueness of a field value with onchange event in edit(or draft) mode
constraint constraints UniqueConstraint odoo16features
Imagine profil
Imagine profil
Imagine profil
2
iul. 25
4968
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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