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
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    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

Programatically test constraints validation

Abonare

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

Această întrebare a fost marcată
constraintsvalidationValidationError
1 Răspunde
5097 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Mukundayi Mpapa T.
Cel mai bun răspuns

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
Imagine profil
Abandonează
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!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Invoice validation error after using foss_round_off module for Multi Company
invoice validation ValidationError
Imagine profil
Imagine profil
1
mai 19
4392
Validation Error Rezolvat
ValidationError
Imagine profil
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
iul. 25
6590
perform Validation before Save on when value entered
validation
Imagine profil
1
feb. 24
27
@api.constrains Rezolvat
constraints
Imagine profil
Imagine profil
2
dec. 23
4679
Error Validation
ValidationError
Imagine profil
0
dec. 22
3010
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