Update models.py

This commit is contained in:
zainab2097 2024-08-13 15:05:46 +03:00 committed by GitHub
parent 6ac9edad33
commit da10b3cae7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 18 deletions

View File

@ -19,29 +19,29 @@ class ResPartner(models.Model):
issuer = fields.Char(string='Issuer')
copy_no = fields.Integer(string='Copy No')
@api.constrains('identification_expiry_date','identification_type','identification_number', 'identification_issue_date')
@api.constrains('identification_expiry_date', 'identification_type', 'identification_number', 'identification_issue_date')
def check_expr_date(self):
for each in self:
if self.identification_expiry_date:
if each.identification_expiry_date:
exp_date = fields.Date.from_string(each.identification_expiry_date)
if exp_date < date.today():
raise Warning('Your Document Is Expired.')
if self.identification_type=='id':
if len(self.identification_number) != 10:
raise Warning(_('Saudi ID must be 10 digits'))
if self.identification_number[0] != '1':
raise Warning(_('The Saudi ID number should begin with 1'))
raise Warning(_('Your Document Is Expired.'))
if self.identification_type=='iqama':
if len(self.identification_number) != 10:
raise Warning(_('Identity must be 10 digits'))
if self.identification_number[0] != '2' and self.identification_number[0] != '4' and self.identification_number[0] != '3':
raise Warning(_('Identity must begin with 2 or 3 or 4'))
if each.identification_type == 'id':
if each.identification_number and len(each.identification_number) != 10:
raise Warning(_('Saudi ID must be 10 digits'))
if each.identification_number and each.identification_number[0] != '1':
raise Warning(_('The Saudi ID number should begin with 1'))
if self.identification_expiry_date and self.identification_issue_date:
if each.identification_type == 'iqama':
if each.identification_number and len(each.identification_number) != 10:
raise Warning(_('Identity must be 10 digits'))
if each.identification_number and each.identification_number[0] not in ['2', '3', '4']:
raise Warning(_('Identity must begin with 2 or 3 or 4'))
if self.identification_expiry_date <= self.identification_issue_date:
raise Warning(_('Error, date of issue must be less than expiry date'))
if each.identification_expiry_date and each.identification_issue_date:
if each.identification_expiry_date <= each.identification_issue_date:
raise Warning(_('Error, date of issue must be less than expiry date'))
if date.today() >= self.identification_expiry_date:
raise Warning(_("Error,the expiry date must be greater than the date of the day"))
if date.today() >= each.identification_expiry_date:
raise Warning(_("Error, the expiry date must be greater than the date of the day"))