Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
constraintscustom_moduleodoo17odoo17CE
1 Respondre
1929 Vistes
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
Descartar
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
Descartar
Enjoying the discussion? Don't just read, join in!

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

Registrar-se
Related Posts Respostes Vistes Activitat
How to use 'like' operator in XML Odoo17? Solved
odoo17 odoo17CE
Avatar
Avatar
1
de nov. 24
1819
How to connect QWeb with ViewXML (Odoo17)
odoo17 odoo17CE
Avatar
0
d’ag. 24
1763
file on binary field is getting downloaded as zip on odoo17 community Solved
custom odoo17 Odoo17 odoo17CE
Avatar
Avatar
Avatar
2
de jul. 25
1655
Bulk SMS in Community Version
smsgateway SMS odoo17 odoo17CE
Avatar
1
d’abr. 25
1512
Automatically save the parent item when creating a child Odoo 17
parent parent_ids odoo17 odoo17CE
Avatar
0
de febr. 25
1645
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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