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

Rollback ORM transaction on parent model constraint

Abonare

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

Această întrebare a fost marcată
developmentapi.dependsapi.model
2015 Vizualizări
Imagine profil
Lalala

Hello guys. I am struggling with odoo tutorial because it does not cover one serious issue with the model.

Let's look at these two models from odoo tutorial:


EstateProperty

​offer_ids = fields.One2many("estate.property.offer")

​state(New, Offer Received, Offer Accepted, Sold, Cancelled)


EstatePropertyOffer

​estate_property_id = fields.Many2one("estate.property", "offer_ids")

​status(None, Accepted, Denied)


What I want:

1) On any change of EstatePropertyOffer (create, unlink, change), there should be called constraint check and some logic for EstateProperty model. And if that constraint/logic fails - EstatePropertyOffer's transaction should rollback (offer changes ignored).

2) All logic should be inside EstateProperty model, not inside EstatePropertyOffer.

​In the context of tutorial: state of EstateProperty depends on gazillion of checks:

​a) if no offers, or all offers are Denied, set state=New

​b) if offer accepted, state = Offer Accepted, set accepted price and buyer

​c) if offers with status!=Accepted/Denied exist, set state=Offers Received

​d) if state = Sold, deny any changes

​....


What I tried:

1) Added dummy field to EstateProperty with (compute="_update_state"), added it to form (without adding it to form, _compute does not trigger), and added:

@api.depends("offer_ids")

def update_state()

​logic here, change some EstateProperty's fields, depending on new EstatePropertyOffer records, ​throw on constraint check


​But this fails, because this method is called after EstatePropertyOffer settled into database.

By the way, what is the correct way to create such constraint without creating dummy field?


2) Call EstateProperty.update_state() from EstatePropertyOffer on any change of the EstatePropertyOffer model. This is ugly, but acceptable:

@api.model

def create(self):

res = super.create()

EstateProperty._update_state()

​return res

Same for unlink.​​ But this also fails, because leads to errors on unlink (EstateProperty barks on unlink that record exists but already deleted ....).

How to 'catch' all changes to the EstatePropertyOffer model to make this:

@api.catch_all_changes_to_this_model_before_commit

def all_changes():

​#here all changes to the model have been done, but transaction not finished

​self.estate_property_id.update_state()


And more generally, how to inject logic from EstateProperty into EstatePropertyOffer's transaction ?














0
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
How to make all branches for user active automatically after login his account?
development
Imagine profil
Imagine profil
1
nov. 25
175
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
Imagine profil
Imagine profil
1
nov. 25
169
How to create a new field have 2 related field by developer mode
development
Imagine profil
Imagine profil
2
oct. 25
504
i face one error while edit my website
development
Imagine profil
0
oct. 25
625
How to add market price of the product to the Odoo 18 Community POS receipt?
development
Imagine profil
0
oct. 25
552
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