Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Rollback ORM transaction on parent model constraint

Odebírat

Get notified when there's activity on this post

This question has been flagged
developmentapi.dependsapi.model
2012 Zobrazení
Avatar
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
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
MrpBom _skip_bom_line skips line of product that has two multi-choice attribute values when both are selected in Apply to variant
development
Avatar
Avatar
1
lis 25
155
How to make all branches for user active automatically after login his account?
development
Avatar
0
lis 25
151
How to create a new field have 2 related field by developer mode
development
Avatar
Avatar
2
říj 25
502
i face one error while edit my website
development
Avatar
0
říj 25
617
How to add market price of the product to the Odoo 18 Community POS receipt?
development
Avatar
0
říj 25
551
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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