Merge pull request #4338 from expsa/kch_dev_odex25_ensan

IMP benefit
This commit is contained in:
kchyounes19 2025-08-26 15:31:54 +01:00 committed by GitHub
commit 17253025fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 7 deletions

View File

@ -591,7 +591,7 @@ class GrantBenefitProfile(models.Model):
]
def _expand_states(self, states, domain, order):
return [key for key, val in type(self).state.selection]
return [key for key, val in type(self).state.selection if key != 'draft']
@api.constrains('father_name', 'father_second_name', 'father_third_name', 'father_family_name',
'mother_name', 'mother_second_name', 'mother_third_name', 'mother_family_name',
@ -996,13 +996,29 @@ class GrantBenefitProfile(models.Model):
raise ValidationError(_("The ID number %s in the Family Members list must be unique across the record.")%member.member_id_number)
# Check for duplicate IDs across records in the database
for id_number in unique_ids:
duplicate_record_family = self.env['grant.benefit'].search([
'|','|', ('father_id_number', '=', id_number), ('mother_id_number', '=', id_number),
('replacement_mother_id_number', '=', id_number),('id','!=',self._origin.id)
], limit=1)
if id_number == self.father_id_number:
conflict = self.env['grant.benefit'].search([
('id', '!=', self._origin.id),
'|', '|',
('mother_id_number', '=', id_number),
('replacement_mother_id_number', '=', id_number),
], limit=1)
if conflict:
raise ValidationError(
_("Father ID %s is already used in another family (as non-father) with code %s.") %
(id_number, conflict.code))
else:
conflict = self.env['grant.benefit'].search([
('id', '!=', self._origin.id),
'|', '|', '|',
('father_id_number', '=', id_number),
('mother_id_number', '=', id_number),
('replacement_mother_id_number', '=', id_number),
], limit=1)
if conflict:
raise ValidationError(_("The ID number %s already exists in family with code %s.") %
(id_number, conflict.code))
duplicate_record_member = self.env['family.member'].search([('member_id_number', '=', id_number)], limit=1)
if duplicate_record_family :
raise ValidationError(_("The ID number {} already exists in family with code {}. Please enter a unique ID number.").format(id_number, duplicate_record_family.code))
if duplicate_record_member :
raise ValidationError(_("The ID number {} already exists in family with code {}. Please enter a unique ID number.").format(id_number, duplicate_record_member.code))