Skip to Content
Menu
This question has been flagged
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!


Avatar
Discard
Author 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

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
647
0
Aug 24
606
1
Apr 25
129
0
Feb 25
382
0
Aug 24
672