IMP benefit

This commit is contained in:
younes 2025-09-18 09:49:05 +01:00
parent 8f056adee7
commit 7c086eb5b2
2 changed files with 97 additions and 214 deletions

View File

@ -63,6 +63,8 @@ class GrantBenefitProfile(models.Model):
('benefit', 'Benefit'),
('non_benefit', 'Non Benefit'),
], string='Mother Status', compute="check_mother_status", store=True, default=False)
mother_salary_certificate = fields.Many2many('ir.attachment', 'mother_member_salary_cert_rel', 'mother_grant_benefit_id', 'attachment_id',
string="Salary Certificate")
phone2 = fields.Char(string="Phone2")
relative_phone = fields.Char(string="Relative Phone")
relative_relation = fields.Char(string="Relative Relation")
@ -541,6 +543,9 @@ class GrantBenefitProfile(models.Model):
('benefit', 'Benefit'),
('non_benefit', 'Non Benefit'),
], string='Replacement Mother Status', compute="check_replacement_mother_status", store=True, default=False)
replacement_mother_salary_certificate = fields.Many2many('ir.attachment', 'replacement_mother_member_salary_cert_rel',
'replacement_mother_grant_benefit_id', 'attachment_id',
string="Salary Certificate")
# Education_data for replacement mother
replacement_education_status_ids = fields.One2many('education.status', 'replacement_grant_benefit_id')
replacement_education_status = fields.Selection(
@ -1037,7 +1042,7 @@ class GrantBenefitProfile(models.Model):
# Check for uniqueness against `member_id_number` in child records and across database records
for member in self.member_ids:
if member.member_id_number and member.member_id_number in unique_ids:
if member.member_id_number and member.member_id_number in unique_ids and member.id not in [self.mother_family_member_id.id,self.replacement_mother_family_member_id.id]:
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:
@ -1063,7 +1068,7 @@ class GrantBenefitProfile(models.Model):
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)
duplicate_record_member = self.env['family.member'].search([('member_id_number', '=', id_number),('id', 'not in', [self.mother_family_member_id.id, self.replacement_mother_family_member_id.id])], limit=1)
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))
@ -1126,19 +1131,19 @@ class GrantBenefitProfile(models.Model):
rec.mother_status = False
if rec.mother_location_conf and rec.mother_marital_conf:
if not rec.mother_location_conf.is_benefit or not rec.mother_marital_conf.is_benefit or rec.state == 'suspended_second_approve':
rec.write({'mother_status':'non_benefit'})
rec.mother_status = 'non_benefit'
elif rec.mother_marital_conf.is_benefit :
if rec.is_mother_work and rec.mother_country_id.code == 'SA' or (
rec.mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'):
if mini_income_for_mother < rec.mother_income <= max_income_for_mother:
rec.write({'mother_status': 'non_benefit'})
rec.mother_status = 'non_benefit'
elif rec.mother_income <= mini_income_for_mother:
rec.write({'mother_status': 'benefit'})
rec.mother_status = 'benefit'
elif rec.mother_income > max_income_for_mother:
rec.write({'mother_status': 'benefit'})
rec.mother_status = 'benefit'
elif not rec.is_mother_work and rec.mother_country_id.code == 'SA' or (
rec.mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'):
rec.write({'mother_status': 'benefit'})
rec.mother_status = 'benefit'
@api.depends('replacement_mother_marital_conf', 'replacement_mother_income', 'replacement_mother_location_conf', 'replacement_mother_country_id', 'state')
@ -1147,7 +1152,9 @@ class GrantBenefitProfile(models.Model):
mini_income_for_mother = validation_setting.mini_income_for_mother
max_income_for_mother = validation_setting.max_income_for_mother
for rec in self:
rec.replacement_mother_status = False
rec.replacement_mother_status = 'non_benefit'
if not rec.add_replacement_mother:
continue
if not rec.replacement_mother_location_conf.is_benefit or not rec.replacement_mother_marital_conf.is_benefit or rec.state == 'suspended_second_approve':
rec.replacement_mother_status = 'non_benefit'
elif rec.replacement_mother_marital_conf.is_benefit:
@ -1200,22 +1207,11 @@ class GrantBenefitProfile(models.Model):
if 'salary_ids' in fields:
res['salary_ids'] = income_attachments_data
return res
def write(self, vals):
# mother_education_status = vals.get("education_status", False) or self.education_status
# if mother_education_status == "educated" and "mother_education_status_ids" not in vals and not len(self.mother_education_status_ids):
# raise ValidationError(
# _("You should at least insert one current/previous mother education status!")
# )
# replacement_education_status = vals.get("replacement_education_status", False) or self.replacement_education_status
# if replacement_education_status == "educated" and "replacement_education_status_ids" not in vals and not len(self.replacement_education_status_ids):
# raise ValidationError(
# _("You should at least insert one current/previous mother education status!")
# )
res = super(GrantBenefitProfile, self).write(vals)
if "name" in vals and self.user_id:
self.user_id.sudo().write({"name": vals.get("name")})
# res = super(GrantBenefitProfile, self).write(vals)
if any(field in vals for field in ["name", "first_name", "second_name", "middle_name", "family_name",
"father_name", "father_second_name", "father_third_name",
"father_family_name"]):
@ -1225,6 +1221,32 @@ class GrantBenefitProfile(models.Model):
record.sudo().user_id.write({"name": record.partner_id.name})
if not self.env.context.get('force_website', False) and not self.env.context.get('bypass_attachments_requirement', False):
self._validate_required_attachments()
# Handle mother update/create
mother_fields = [
'mother_name', 'mother_second_name', 'mother_third_name', 'mother_family_name', 'mother_id_number',
'mother_birth_date', 'mother_marital_conf', 'mother_location_conf', 'is_mother_work',
'mother_income', 'mother_age','education_status','mother_diseases_attachment_ids',
'mother_education_status_ids','mother_disabilities_attachment_ids'
]
if any(field in vals for field in mother_fields):
for rec in self:
rec.add_or_replace_mother_as_member()
# Handle replacement mother update/create
replacement_fields = [
'replacement_mother_name', 'replacement_mother_second_name', 'replacement_mother_third_name',
'replacement_mother_family_name','replacement_mother_id_number',
'replacement_mother_birth_date', 'replacement_mother_marital_conf',
'replacement_mother_location_conf','replacement_mother_relation',
'replacement_is_mother_work', 'replacement_mother_income', 'replacement_education_status',
'replacement_mother_age','replacement_mother_disabilities_attachment_ids',
'replacement_education_status_ids', 'replacement_mother_diseases_attachment_ids'
]
if any(field in vals for field in replacement_fields):
for rec in self:
if rec.add_replacement_mother:
rec.add_or_replace_replacement_mother_as_member()
return res
@api.model
@ -1242,9 +1264,10 @@ class GrantBenefitProfile(models.Model):
res.code = self.env['ir.sequence'].sudo().next_by_code('benefit.sequence') or _('New')
# Add mother
if res.mother_id_number:
res.add_mother_as_member()
res.add_or_replace_mother_as_member()
# Add replacement mother
if res.add_replacement_mother and res.replacement_mother_id_number:
res.add_replacement_mother_as_member()
res.add_or_replace_replacement_mother_as_member()
return res
def unlink(self):
@ -1309,20 +1332,7 @@ class GrantBenefitProfile(models.Model):
#
# if rec.member_income == 0.0:
# raise ValidationError(_("يرجى اكمال ادخال او الموافقة على القيم المرتبطة ببيانات الدخل والمرتب والالتزامات لتحديد فئة الاسرة بشكل صحيح"))
rec.validate_attachments()
mother_exist = self.env["family.member"].search([('member_id_number', '=', rec.mother_id_number),('relationn.relation_type','=','mother')], limit=1)
replacement_mother_exist = self.env["family.member"].search([('member_id_number', '=', rec.replacement_mother_id_number),('relationn.relation_type','=','replacement_mother')], limit=1)
if not mother_exist:
rec.add_mother_as_member()
if mother_exist:
rec.replace_mother_as_member(mother_exist.id)
if rec.add_replacement_mother:
if not replacement_mother_exist:
rec.add_replacement_mother_as_member()
if replacement_mother_exist:
rec.replace_replacement_mother_as_member(replacement_mother_exist.id)
self.state = 'waiting_approve'
def action_first_accepted(self):
@ -1852,111 +1862,11 @@ class GrantBenefitProfile(models.Model):
else:
name = name
return name
def add_mother_as_member(self):
for rec in self:
mother_name = rec.get_mother_name()
val = {
'name': mother_name,
'mother_first_name': rec.mother_name,
'mother_second_name': rec.mother_second_name,
'mother_third_name': rec.mother_third_name,
'mother_family_name': rec.mother_family_name,
'member_id_number': rec.mother_id_number,
'is_mother':True,
'birth_date': rec.mother_birth_date,
'gender': 'female',
'relationn': self.env['relation.settings'].search([('relation_type','=','mother')]).id,
'mother_marital_conf': rec.mother_marital_conf.id,
'mother_location_conf': rec.mother_location_conf.id,
'age': rec.mother_age,
'is_work': rec.is_mother_work,
'member_income': rec.mother_income,
'education_status': rec.education_status,
'member_education_status_ids': [(5, 0)] + [(4, mother_education_id.id) for mother_education_id in rec.mother_education_status_ids],
'case_study': rec.case_study,
'education_entity': rec.education_entity,
'last_education_entity': rec.last_education_entity,
'entities': rec.entities.id,
'last_entities': rec.last_entities.id,
'education_levels': rec.education_levels.id,
'last_education_levels': rec.last_education_levels.id,
'specialization_ids': rec.specialization_ids.id,
'last_specialization_ids': rec.last_specialization_ids.id,
'classroom': rec.classroom.id,
'last_classroom': rec.last_classroom.id,
'degree': rec.degree.id,
'last_degree': rec.last_degree.id,
'percentage': rec.percentage,
'last_percentage': rec.last_percentage,
'weak_study': rec.weak_study.ids,
'member_status': rec.mother_status,
'education_start_date':rec.education_start_date,
'education_end_date':rec.education_end_date,
'educational_certificate':rec.educational_certificate,
'last_education_start_date': rec.last_education_start_date,
'last_education_end_date': rec.last_education_end_date,
'last_educational_certificate': rec.last_educational_certificate,
'benefit_id': rec.id,
}
mother_family_member_id = self.env['family.member'].create(val)
rec.write({'mother_family_member_id': mother_family_member_id.id})
for r in rec.mother_diseases_attachment_ids:
r.write({'member_id': mother_family_member_id.id})
for r in rec.mother_disabilities_attachment_ids:
r.write({'member_id': mother_family_member_id.id})
def add_replacement_mother_as_member(self):
for rec in self:
mother_name = rec.get_replacement_mother_name()
val = {
'name': mother_name,
'mother_first_name': rec.replacement_mother_name,
'mother_second_name': rec.replacement_mother_second_name,
'mother_third_name': rec.replacement_mother_third_name,
'mother_family_name': rec.replacement_mother_family_name,
'member_id_number': rec.replacement_mother_id_number,
'is_mother':True,
'birth_date': rec.replacement_mother_birth_date,
'gender': 'female',
'relationn': rec.replacement_mother_relation.id,
'mother_marital_conf': rec.replacement_mother_marital_conf.id,
'mother_location_conf': rec.replacement_mother_location_conf.id,
'age': rec.replacement_mother_age,
'is_work': rec.replacement_is_mother_work,
'member_income': rec.replacement_mother_income,
'education_status': rec.replacement_education_status,
'case_study': rec.replacement_case_study,
'education_entity': rec.replacement_education_entity,
'member_education_status_ids': [(5, 0)] + [(4, replacement_education_id.id) for replacement_education_id in rec.replacement_education_status_ids],
'last_education_entity': rec.replacement_last_education_entity,
'entities': rec.replacement_entities.id,
'last_entities': rec.replacement_last_entities.id,
'education_levels': rec.replacement_education_levels.id,
'last_education_levels': rec.replacement_last_education_levels.id,
'specialization_ids': rec.replacement_specialization_ids.id,
'last_specialization_ids': rec.replacement_last_specialization_ids.id,
'classroom': rec.replacement_classroom.id,
'last_classroom': rec.replacement_last_classroom.id,
'degree': rec.replacement_degree.id,
'last_degree': rec.replacement_last_degree.id,
'percentage': rec.replacement_percentage,
'weak_study': rec.replacement_weak_study.ids,
'member_status': rec.replacement_mother_status,
'education_start_date': rec.replacement_education_start_date,
'education_end_date': rec.replacement_education_end_date,
'educational_certificate': rec.replacement_educational_certificate,
'last_education_start_date': rec.replacement_last_education_start_date,
'last_education_end_date': rec.replacement_last_education_end_date,
'last_educational_certificate': rec.replacement_last_educational_certificate,
}
replacement_mother_family_member_id = self.env['family.member'].create(val)
rec.write({'replacement_mother_family_member_id': replacement_mother_family_member_id.id})
for r in rec.replacement_mother_diseases_attachment_ids:
r.write({'member_id': replacement_mother_family_member_id.id})
for r in rec.replacement_mother_disabilities_attachment_ids:
r.write({'member_id': replacement_mother_family_member_id.id})
def add_or_replace_mother_as_member(self):
FamilyMember = self.env['family.member']
Relation = self.env['relation.settings'].search([('relation_type', '=', 'mother')], limit=1)
def replace_mother_as_member(self, id):
for rec in self:
mother_name = rec.get_mother_name()
val = {
@ -1969,47 +1879,31 @@ class GrantBenefitProfile(models.Model):
'is_mother': True,
'birth_date': rec.mother_birth_date,
'gender': 'female',
'relationn': self.env['relation.settings'].search([('relation_type','=','mother')]).id,
'relationn': Relation.id,
'mother_marital_conf': rec.mother_marital_conf.id,
'mother_location_conf': rec.mother_location_conf.id,
'age': rec.mother_age,
'is_work': rec.is_mother_work,
'member_income': rec.mother_income,
'education_status': rec.education_status,
'member_education_status_ids': [(5, 0)] + [(4, mother_education_id.id) for mother_education_id in rec.mother_education_status_ids],
'case_study': rec.case_study,
'education_entity': rec.education_entity,
'last_education_entity': rec.last_education_entity,
'entities': rec.entities.id,
'last_entities': rec.last_entities.id,
'education_levels': rec.education_levels.id,
'last_education_levels': rec.last_education_levels.id,
'specialization_ids': rec.specialization_ids.id,
'last_specialization_ids': rec.last_specialization_ids.id,
'classroom': rec.classroom.id,
'last_classroom': rec.last_classroom.id,
'degree': rec.degree.id,
'last_degree': rec.last_degree.id,
'percentage': rec.percentage,
'last_percentage': rec.last_percentage,
'weak_study': rec.weak_study.ids,
'member_status': rec.mother_status,
'education_start_date': rec.education_start_date,
'education_end_date': rec.education_end_date,
'educational_certificate': rec.educational_certificate,
'last_education_start_date': rec.last_education_start_date,
'last_education_end_date': rec.last_education_end_date,
'last_educational_certificate': rec.last_educational_certificate,
#'member_status': rec.mother_status,
'member_education_status_ids': [(5, 0)] + [(4, edu.id) for edu in rec.mother_education_status_ids],
'salary_certificate': [(6, 0, rec.mother_salary_certificate.ids)],
}
mother_family_member_id = rec.mother_family_member_id
if mother_family_member_id:
mother_family_member_id.write(val)
for r in rec.mother_diseases_attachment_ids:
r.write({'member_id': mother_family_member_id.id})
for r in rec.mother_disabilities_attachment_ids:
r.write({'member_id': mother_family_member_id.id})
def replace_replacement_mother_as_member(self, id):
mother_family_member = rec.mother_family_member_id
if mother_family_member:
mother_family_member.write(val)
else:
val['benefit_id'] = rec.id
mother_family_member = FamilyMember.create(val)
rec.write({'mother_family_member_id': mother_family_member.id})
rec.mother_diseases_attachment_ids.write({'member_id': mother_family_member.id})
rec.mother_disabilities_attachment_ids.write({'member_id': mother_family_member.id})
def add_or_replace_replacement_mother_as_member(self):
FamilyMember = self.env['family.member']
for rec in self:
mother_name = rec.get_replacement_mother_name()
val = {
@ -2019,7 +1913,7 @@ class GrantBenefitProfile(models.Model):
'mother_third_name': rec.replacement_mother_third_name,
'mother_family_name': rec.replacement_mother_family_name,
'member_id_number': rec.replacement_mother_id_number,
'is_mother': True,
'is_mother': False,
'birth_date': rec.replacement_mother_birth_date,
'gender': 'female',
'relationn': rec.replacement_mother_relation.id,
@ -2029,38 +1923,21 @@ class GrantBenefitProfile(models.Model):
'is_work': rec.replacement_is_mother_work,
'member_income': rec.replacement_mother_income,
'education_status': rec.replacement_education_status,
'member_education_status_ids': [(5, 0)] + [(4, replacement_education_id.id) for replacement_education_id in rec.replacement_education_status_ids],
'case_study': rec.replacement_case_study,
'education_entity': rec.replacement_education_entity,
'last_education_entity': rec.replacement_last_education_entity,
'entities': rec.replacement_entities.id,
'last_entities': rec.replacement_last_entities.id,
'education_levels': rec.replacement_education_levels.id,
'last_education_levels': rec.replacement_last_education_levels.id,
'specialization_ids': rec.replacement_specialization_ids.id,
'last_specialization_ids': rec.replacement_last_specialization_ids.id,
'classroom': rec.replacement_classroom.id,
'last_classroom': rec.replacement_last_classroom.id,
'degree': rec.replacement_degree.id,
'last_degree': rec.replacement_last_degree.id,
'percentage': rec.replacement_percentage,
'last_percentage': rec.replacement_last_percentage,
'weak_study': rec.replacement_weak_study.ids,
'member_status': rec.replacement_mother_status,
'education_start_date': rec.replacement_education_start_date,
'education_end_date': rec.replacement_education_end_date,
'educational_certificate': rec.replacement_educational_certificate,
'last_education_start_date': rec.replacement_last_education_start_date,
'last_education_end_date': rec.replacement_last_education_end_date,
'last_educational_certificate': rec.replacement_last_educational_certificate,
#'member_status': rec.replacement_mother_status,
'member_education_status_ids': [(5, 0)] + [(4, edu.id) for edu in rec.replacement_education_status_ids],
'salary_certificate': [(6, 0, rec.replacement_mother_salary_certificate.ids)],
}
replacement_mother_family_member_id = rec.replacement_mother_family_member_id
if replacement_mother_family_member_id:
replacement_mother_family_member_id.write(val)
for r in rec.replacement_mother_diseases_attachment_ids:
r.write({'member_id': replacement_mother_family_member_id.id})
for r in rec.replacement_mother_disabilities_attachment_ids:
r.write({'member_id': replacement_mother_family_member_id.id})
if rec.replacement_mother_family_member_id:
rec.replacement_mother_family_member_id.write(val)
replacement_member = rec.replacement_mother_family_member_id
else:
val['benefit_id'] = rec.id
replacement_member = FamilyMember.create(val)
rec.write({'replacement_mother_family_member_id': replacement_member.id})
rec.replacement_mother_diseases_attachment_ids.write({'member_id': replacement_member.id})
rec.replacement_mother_disabilities_attachment_ids.write({'member_id': replacement_member.id})
def get_members_count(self):
for ben in self:

View File

@ -112,7 +112,7 @@
<field name="name">grant.benefit.form</field>
<field name="model">grant.benefit</field>
<field name="arch" type="xml">
<form string="Benefit" create="0">
<form string="Benefit" create="1">
<header>
<button name="action_first_accepted" type="object"
string="First Accept" class="oe_highlight"
@ -428,14 +428,14 @@
<group>
<label for="mother_name" string="Mother Name"/>
<div class="o_row">
<field name="mother_name" nolabel="1" placeholder="First Name"
attrs="{'required':[('state','not in',['draft','new'])],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_second_name" nolabel="1" placeholder="Second Name"
attrs="{'required':[('state','not in',['draft','new'])],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_third_name" nolabel="1" placeholder="Third Name"
attrs="{'required':[('state','not in',['draft','new'])],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_family_name" nolabel="1" placeholder="Family Name"
attrs="{'required':[('state','not in',['draft','new'])],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_name" nolabel="1" placeholder="First Name" required="1"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_second_name" nolabel="1" placeholder="Second Name" required="1"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_third_name" nolabel="1" placeholder="Third Name" required="1"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_family_name" nolabel="1" placeholder="Family Name" required="1"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
</div>
</group>
<group/>
@ -511,11 +511,14 @@
readonly="1"/>
<field name="is_mother_work"
attrs="{'required':[('state','not in',['draft','new'])],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="mother_salary_certificate"
widget="many2many_attachment_preview"
attrs="{'invisible':[('is_mother_work','=',False)]}"/>
<field name="mother_has_disabilities" invisible="1"/>
<field name="mother_income" widget="monetary"
options="{'currency_field': 'currency_id', 'field_digits': False}"
digits="[16,0]"
attrs="{'required':[('is_mother_work','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
attrs="{'invisible':[('is_mother_work','=',False)],'required':[('is_mother_work','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="education_status"/>
<!-- <field name="is_mother_benefit"/>-->
</group>
@ -664,10 +667,13 @@
readonly="1"/>
<field name="replacement_is_mother_work"
attrs="{'required':[('state','not in',['draft','new']),('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="replacement_mother_salary_certificate"
widget="many2many_attachment_preview"
attrs="{'invisible':[('replacement_is_mother_work','=',False)]}"/>
<field name="replacement_mother_has_disabilities"
attrs="{'required':[('state','not in',['draft','new']),('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="replacement_mother_income"
attrs="{'required':[('replacement_is_mother_work','=',True),('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
attrs="{'invisible':[('replacement_is_mother_work','=',False)],'required':[('replacement_is_mother_work','=',True),('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/>
<field name="replacement_education_status"/>
<!-- <field name="is_mother_benefit"/>-->
</group>