Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Unable to Enforce Unique Constraint on Passport Number in Custom Odoo Module

Odoberať

Get notified when there's activity on this post

This question has been flagged
constraintscustom_moduleodoo17odoo17CE
1 Odpoveď
1965 Zobrazenia
Avatar
imrantc
class PassportManagementModels(models.Model):
_name = 'om_hrm.passport'
_description = 'Passport Master'
_inherit = ['mail.thread']
_rec_name = "PassportNo"

PassportNo = fields.Char(string='Passport Number',size=16,required=True) PassportIssueDate = fields.Date(string='Passport Issue Date', required=True) PassportExpiryDate =fields.Date(string="Expiry Date",required=True) PassportNationality =fields.Char(string="Nationality",size=20,required=True) Passportdob = fields.Date(string="Date of Birth",required=True) Passportholdername = fields.Char(string="Holder Full Name",required=True) Passportpossesionwith = fields.Selection([("admin","Admin"),("staff","Staff"),("other","Other")],string="Possesion With!") passport_doc_ids = fields.Many2many('ir.attachment',string='Passport Documents',ondelete='cascade')

_sql_constraints = [('passport_unique','UNIQUE(PassportNo)','The Passport Number must be unique.')].

Hello Odoo Community,

I'm currently facing an issue with a custom module in Odoo where I am trying to enforce a unique constraint on the PassportNo field in my om_hrm.passport model. Despite my efforts, the constraint does not seem to be applied correctly, even when the table is empty.


I tried below but its not working .

  • Uninstalled custom module and reinstalled.
  • Created new Database and installed.
  • Passport table is empty and their is no data in it. 

i dont know why its not effecting i get below error in CLI.

2024-09-22 18:06:53,948 90489 WARNING odoodemo1 odoo.schema: Table 'om_hrm_passport': unable to add constraint 'om_hrm_passport_passport_unique' as UNIQUE(PassportNo)

2024-09-22 18:06:54,009 90489 ERROR odoodemo1 odoo.schema: Table 'om_hrm_passport': unable to add constraint 'om_hrm_passport_passport_unique' as UNIQUE(PassportNo)

I would appreciate any insights or suggestions on how to resolve this issue. Is there something I may have overlooked in the setup of my module? Any help would be greatly appreciated!


0
Avatar
Zrušiť
Avatar
imrantc
Autor Best Answer

i found the answer seems like odoo model fields should not be camel case or snakecase , 

passport_no = fields.Char(string='Passport Number',size=16,required=True)    PassportIssueDate = fields.Date(string='Passport Issue Date', required=True)    PassportExpiryDate =fields.Date(string="Expiry Date",required=True)    PassportNationality =fields.Char(string="Nationality",size=20,required=True)    Passportdob = fields.Date(string="Date of Birth",required=True)    Passportholdername = fields.Char(string="Holder Full Name",required=True)    Passportpossesionwith = fields.Selection([("admin","Admin"),("staff","Staff"),("other","Other")],string="Possesion With!")    passport_doc_ids = fields.Many2many('ir.attachment',string='Passport Documents',ondelete='cascade')
 _sql_constraints = [        ('key_uniq', 'unique (passport_no)', 'PassportNo must be unique.')    ]

i changed PassportNo to passport_no and it worked

0
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
How to use 'like' operator in XML Odoo17? Solved
odoo17 odoo17CE
Avatar
Avatar
1
nov 24
1848
How to connect QWeb with ViewXML (Odoo17)
odoo17 odoo17CE
Avatar
0
aug 24
1790
file on binary field is getting downloaded as zip on odoo17 community Solved
custom odoo17 Odoo17 odoo17CE
Avatar
Avatar
Avatar
2
júl 25
1694
Bulk SMS in Community Version
smsgateway SMS odoo17 odoo17CE
Avatar
1
apr 25
1524
Automatically save the parent item when creating a child Odoo 17
parent parent_ids odoo17 odoo17CE
Avatar
0
feb 25
1677
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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