Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Programatically test constraints validation

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
constraintsvalidationValidationError
1 Svar
5108 Visninger
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
Kassér
Avatar
Mukundayi Mpapa T.
Bedste svar

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
Kassér
Eric Belrose
Forfatter

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
Forfatter

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!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Invoice validation error after using foss_round_off module for Multi Company
invoice validation ValidationError
Avatar
Avatar
1
maj 19
4407
Validation Error Løst
ValidationError
Avatar
Avatar
Avatar
Avatar
Avatar
4
jul. 25
6598
perform Validation before Save on when value entered
validation
Avatar
1
feb. 24
27
@api.constrains Løst
constraints
Avatar
Avatar
2
dec. 23
4688
Error Validation
ValidationError
Avatar
0
dec. 22
3011
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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