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í
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • 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

Programatically test constraints validation

Odebírat

Get notified when there's activity on this post

This question has been flagged
constraintsvalidationValidationError
1 Odpovědět
5100 Zobrazení
Avatar
Eric Belrose

Greetins all,

We are searching for a way to test change on an object just for simulation purpose and not doing it really. For example, we have a stock.move and we want to know if, regarding some constraints on some models fields (stock.quant  for  example) , we would be able to save a certain modification/validate the  stock.move . 

The result should be wether or not the modification is possible. We don't want to really save the modification.

0
Avatar
Zrušit
Avatar
Mukundayi Mpapa T.
Nejlepší odpověď

you can use a computed field , let say a boolean that returns true if your validation is ok

Now in @api.depends()  decorator you put your object you want to test and in the compute method  you  put  your  logic.

Exemple:

is_ok=fields.Boolean(compute='test_quant')

@api.depends('stock.quant')

def test_quant(self):

    if \self.stock.quant==your_logic:

        self.is_ok=True

    else:

    self.is_ok=False


Don't put store=True in your compute fields. In this case your function will be called on the fly.

Hope it helps


0
Avatar
Zrušit
Eric Belrose
Autor

Hi thanks for your answer.
We have to use constraints validation mechanism with the @api.constrains annotation and validationerror exception here. That is already provided in a another module. That is what we want to "capture" and return true or false if there is exceptions or not. We can't just catch the exception while doing the modification as if there is no exception the modification will be save and we don't want that

Eric Belrose
Autor

We have this code from a community module :

class StockQuant(models.Model):
_inherit = "stock.quant"

@api.constrains("product_id", "quantity")
def check_negative_qty(self):
p = self.env["decimal.precision"].precision_get("Product Unit of Measure")
check_negative_qty = (
config["test_enable"] and self.env.context.get("test_stock_no_negative")
) or not config["test_enable"]
if not check_negative_qty:
return

for quant in self:
disallowed_by_product = (
not quant.product_id.allow_negative_stock
and not quant.product_id.categ_id.allow_negative_stock
)
disallowed_by_location = not quant.location_id.allow_negative_stock
if (
float_compare(quant.quantity, 0, precision_digits=p) == -1
and quant.product_id.type == "product"
and quant.location_id.usage in ["internal", "transit"]
and disallowed_by_product
and disallowed_by_location
):
msg_add = ""
if quant.lot_id:
msg_add = _(" lot '%s'") % quant.lot_id.name_get()[0][1]
raise ValidationError(
_(
"You cannot validate this stock operation because the "
"stock level of the product '%s'%s would become negative "
"(%s) on the stock location '%s' and negative stock is "
"not allowed for this product and/or location."
)
% (
quant.product_id.name,
msg_add,
quant.quantity,
quant.location_id.complete_name,
)
)
The code is called through constraints when new quant or quant modification is requested and raise ValidationError if there is no stock. Want we want to achieve is to be able to check this constraint with the exact same mechanism but we don't want the modification to be done at the end wether or not a ValidationError is raised. For example, we want to test a stock.move validation, it triggers quant creation/modification request, calls the constraints and at the end we need something to "rollback" the action in any case

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
Invoice validation error after using foss_round_off module for Multi Company
invoice validation ValidationError
Avatar
Avatar
1
kvě 19
4401
Validation Error Vyřešeno
ValidationError
Avatar
Avatar
Avatar
Avatar
Avatar
4
čvc 25
6596
perform Validation before Save on when value entered
validation
Avatar
1
úno 24
27
@api.constrains Vyřešeno
constraints
Avatar
Avatar
2
pro 23
4683
Error Validation
ValidationError
Avatar
0
pro 22
3011
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