Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivoustarvikkeet
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Tutoriaalit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

_sql_constraints fail to be effective

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
constraintspsql
2 Vastaukset
6847 Näkymät
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
Hylkää
Avatar
Jagdish Panchal
Paras vastaus

Hello Albert

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

0
Avatar
Hylkää
Albert
Tekijä

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
Paras vastaus

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
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
It sounds to be a odoo bug in setting _sql_constraints
constraints psql
Avatar
0
elok. 21
3629
psql error
psql
Avatar
Avatar
Avatar
2
maalisk. 24
9871
psql command does not work
psql
Avatar
Avatar
1
helmik. 24
2527
@api.constrains Ratkaistu
constraints
Avatar
Avatar
2
jouluk. 23
4629
Constraints raising exception instead of showing normal warning
constraints
Avatar
0
kesäk. 21
3410
Yhteisö
  • Tutoriaalit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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