Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Guest House
    • Distributeur de boissons
    • Hotel
    Real Estate
    • Real Estate Agency
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consulting
    • Accounting Firm
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Solar Energy Systems
    • Cordonnier
    • Services de nettoyage
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

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

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

_sql_constraints fail to be effective

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
constraintspsql
2 Réponses
6836 Vues
Avatar
Albert

When I am doing the exercise of Chap 11 of "Getting Started "  of "Tutorials" of "Developer" (https://www.odoo.com/documentation/14.0/developer/howtos/rdtraining/11_constraints.html). I find very puzzling phenomena. In my python program, I have the following codes:

class estate_estate(models.Model):
title = fields.Char('Title', required=True, translate=True)
selling_price = fields.Float('Selling Price', readonly=True, copy=False)
expected_price = fields.Float('Expected Price', copy=False)
_sql_constraints = [
('check_positive', 'CHECK(expected_price > 0 AND selling_price >0 )',
'The price shall be positive!')
]

_sql_constraints = [
('check_uniqueness', 'unique(title)', 'The property name shall be unique !')
]

At first, the uniqueness check work properly, but the check_positive works partially correct. So I modify the constraints to 

_sql_constraints = [
('check_positive', 'CHECK(expected_price > 0 )',
'The price shall be positive!')
]

But when I use psql to check constraints, I find that the constraint is still the original one, i.e. CHECK(expected_price > 0 AND selling_price >0. So I use the following to drop constraints

ALTER TABLE estate_estate
DROP CONSTRAINT check_positive;

I do find no more constrains on table, but when I use command to reactivate odoo./odoo/odoo-bin --addons-path=./custom,./odoo/odoo/addons -d rd-demo -u estate_estate --dev xml

I still did not see the check_positive constraint using psql, but check_uniqueness is still there:

Indexes:
  "estate_estate_check_uniqueness" UNIQUE CONSTRAINT, btree (title)

I do an experiment by removing check_uniqueness and restart odoo, then I add a duplicate property yyy to see if there is warning message, interestingly, I find that the user exception handling message 'The property name shall be unique !' did disappear, but in its stead is the system message:

Validation Error

×

duplicate key value violates unique constraint "estate_estate_check_uniqueness" DETAIL: Key (title)=(yyy) already exists.

I use psql commands to double check, see what I get?

"estate_estate_check_uniqueness" UNIQUE CONSTRAINT, btree (title)

The check_uniqueness is still there.

So, my conclusion seems to be:  when adding _sql_constraints for the first time, it works. But then you make some modification of the statement and restart odoo, those new settings seems to be no longer effective.

This is very baffling. Help is desperately needed.




0
Avatar
Ignorer
Avatar
Jagdish Panchal
Meilleure réponse

Hello Albert

In your database in duplicate value already exist, first remove duplicate data and then restart server it will work.

0
Avatar
Ignorer
Albert
Auteur

Thank you very much for answering my post. But you seem to misunderstand my problem. I did not meet duplicate data issue which will tell me “unable to add constraint xxx". My problem is that the constrain is stated, and system does not give me “unable to add constraint xxx" message, but when I set a negative value to a field for which a positive check wast set, but the server accept it. So I use psql to check the database, and find that the positive check is not set at all. However I do have the following in my python code:
_sql_constraints = [
('check_positive', 'CHECK(expected_price > 0 )',
'The price shall be positive!')
]
And it works the first it is set but with another condition. In short, I mean when I made a modification to positive check , my modification does not effect. If I drop constraint using psql, and restart the server, I even do not find positive check at all. So my conclusion is that when a check is modified odoo may not make the modification change to a proper psql command. I hope someone can correct me by doing the same experiment but result in a different result, so that I can know what is wrong with my experiment.

Avatar
Michael Angelo
Meilleure réponse

For anyone having this issue.

Check values that are already stored in DB. 
in my case i was setting a constraint to check if price was a positive number.

I used (price > 0)
My database had data where the price was 0 this caused the constraint to not be applied.
after removing that data and restarting the server, the constraint was set and everything worked properly.

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
It sounds to be a odoo bug in setting _sql_constraints
constraints psql
Avatar
0
août 21
3615
psql error
psql
Avatar
Avatar
Avatar
2
mars 24
9861
psql command does not work
psql
Avatar
Avatar
1
févr. 24
2520
@api.constrains Résolu
constraints
Avatar
Avatar
2
déc. 23
4617
Constraints raising exception instead of showing normal warning
constraints
Avatar
0
juin 21
3397
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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