diff --git a/odex25_ensan/odex_benefit/models/benefit.py b/odex25_ensan/odex_benefit/models/benefit.py index 61d2f8404..08610c282 100644 --- a/odex25_ensan/odex_benefit/models/benefit.py +++ b/odex25_ensan/odex_benefit/models/benefit.py @@ -59,10 +59,7 @@ class GrantBenefitProfile(models.Model): code = fields.Char(string="Code", copy=False, readonly=True, default=lambda x: _('New')) benefit_type = fields.Selection([('benefit', 'benefit'), ('orphan', 'orphan'), ('widow', 'widow') ], string='Benefit Type', tracking=True) - mother_status = fields.Selection(selection=[ - ('benefit', 'Benefit'), - ('non_benefit', 'Non Benefit'), - ], string='Mother Status', compute="check_mother_status", store=True, default=False) + mother_status = fields.Selection(string='Mother Status', related="mother_family_member_id.member_status") 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") @@ -540,10 +537,7 @@ class GrantBenefitProfile(models.Model): replacement_mother_dead_reason = fields.Char(string='Dead Reason', required=False) replacement_mother_dead_date = fields.Date(string="Replacement Mother Dead Date") replacement_mother_dead_certificate = fields.Many2many('ir.attachment', 'rel_replacement_mother_dead_attachment', 'benefit_id', 'attachment_id', string='Replacement Mother Dead Certificate') - replacement_mother_status = fields.Selection(selection=[ - ('benefit', 'Benefit'), - ('non_benefit', 'Non Benefit'), - ], string='Replacement Mother Status', compute="check_replacement_mother_status", store=True, default=False) + replacement_mother_status = fields.Selection(string='Replacement Mother Status', related="replacement_mother_family_member_id.member_status") replacement_mother_salary_certificate = fields.Many2many('ir.attachment', 'replacement_mother_member_salary_cert_rel', 'replacement_mother_grant_benefit_id', 'attachment_id', string="Salary Certificate") @@ -1123,53 +1117,49 @@ class GrantBenefitProfile(models.Model): 'url': url } - @api.depends('mother_marital_conf', 'mother_income', 'mother_location_conf', 'mother_country_id', 'state') def check_mother_status(self): validation_setting = self.env["family.validation.setting"].search([], limit=1) 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.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.mother_status = 'non_benefit' + return '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.mother_status = 'non_benefit' + return 'non_benefit' elif rec.mother_income <= mini_income_for_mother: - rec.mother_status = 'benefit' + return 'benefit' elif rec.mother_income > max_income_for_mother: - rec.mother_status = 'benefit' + return '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.mother_status = 'benefit' + return 'benefit' - - @api.depends('replacement_mother_marital_conf', 'replacement_mother_income', 'replacement_mother_location_conf', 'replacement_mother_country_id', 'state') def check_replacement_mother_status(self): validation_setting = self.env["family.validation.setting"].search([], limit=1) 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 = 'non_benefit' + rec.replacement_mother_status = False 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' + return 'non_benefit' elif rec.replacement_mother_marital_conf.is_benefit: if rec.replacement_is_mother_work and rec.replacement_mother_country_id.code == 'SA' or ( rec.replacement_mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'): if mini_income_for_mother < rec.replacement_mother_income <= max_income_for_mother: - rec.replacement_mother_status = 'non_benefit' + return 'non_benefit' elif rec.replacement_mother_income <= mini_income_for_mother: - rec.replacement_mother_status = 'benefit' + return 'benefit' elif rec.replacement_mother_income > max_income_for_mother: - rec.replacement_mother_status = 'benefit' + return 'benefit' elif not rec.replacement_is_mother_work and rec.replacement_mother_country_id.code == 'SA' or ( rec.replacement_mother_country_id.code != 'SA' and rec.father_country_id.code == 'SA'): - rec.replacement_mother_status = 'benefit' + return 'benefit' def delete_from_db(self): find_id = self.env['benefit.housing'].search([]) @@ -1651,7 +1641,7 @@ class GrantBenefitProfile(models.Model): rec.is_diseases = 'sick' if rec.is_diseases else 'healthy' def _onchange_is_has_needs(self): - for rec in self: + for rec in self: benefits_needs = rec.env['benefits.needs'].sudo().search(['|', ('benefit_id', '=', rec.id), ('benefit_ids', 'in', rec.id)]) diff --git a/odex25_ensan/odex_benefit/models/family_members.py b/odex25_ensan/odex_benefit/models/family_members.py index dc81804ad..a131e4744 100644 --- a/odex25_ensan/odex_benefit/models/family_members.py +++ b/odex25_ensan/odex_benefit/models/family_members.py @@ -454,13 +454,14 @@ class FamilyMemberProfile(models.Model): 'is_married', 'member_location_conf', 'state', - 'is_dead' + 'is_dead', + 'benefit_id.member_ids.member_status', ) def check_member_status(self): for rec in self: current_education_status_id = rec.member_education_status_ids.filtered(lambda r: r.education_status_type == 'current') if rec.state == 'second_approve' and rec.is_excluded_suspension: - rec.member_status = 'benefit' + rec.write({'member_status': 'benefit'}) continue if rec.birth_date: validation_setting = self.env["family.validation.setting"].search([], limit=1) @@ -471,15 +472,21 @@ class FamilyMemberProfile(models.Model): minor_siblings_age = validation_setting.minor_siblings_age max_income_for_benefit = validation_setting.max_income_for_benefit rec.member_status = 'benefit' # Default to benefit + benefiting_children = rec.benefit_id.member_ids.filtered( + lambda m: m.relationn.relation_type in ['son', 'daughter'] and m.member_status == 'benefit' + ) if rec.relationn.relation_type == 'mother': - rec.member_status = rec.benefit_id.mother_status - if rec.relationn.relation_type == 'replacement_mother': - rec.member_status = rec.benefit_id.replacement_mother_status - if rec.state == 'suspended_second_approve': + if not benefiting_children: + rec.write({'member_status': 'non_benefit'}) + else: + rec.member_status = rec.benefit_id.check_mother_status() + elif rec.relationn.relation_type == 'replacement_mother': + rec.member_status = rec.benefit_id.check_replacement_mother_status() + if rec.state == 'suspended_second_approve' or not benefiting_children: rec.member_status = 'non_benefit' # continue # Skip further checks for mothers # Gender-specific checks - if rec.relationn.relation_type == 'son': + elif rec.relationn.relation_type == 'son': if rec.age > male_benefit_age: if current_education_status_id.specialization_ids.is_scientific_specialty and rec.age > exceptional_age_scientific_specialty and not rec.minor_siblings : rec.member_status = 'non_benefit' @@ -501,7 +508,6 @@ class FamilyMemberProfile(models.Model): rec.member_status = 'non_benefit' if rec.state == 'suspended_second_approve' or rec.is_dead == True: rec.member_status = 'non_benefit' - elif rec.relationn.relation_type == 'daughter': if rec.age < female_benefit_age and rec.is_married: rec.member_status = 'non_benefit' @@ -685,15 +691,15 @@ class FamilyMemberProfile(models.Model): # raise ValidationError( # _('The ID Number Already Exist!')) - @api.onchange('relationn','member_status','gender','birth_date', 'is_scientific_specialty', 'is_medical_specialty', 'is_married', - 'minor_siblings','member_income','is_married','member_location_conf','education_status','case_study') - def onchange_member_status(self): - res ={} - for rec in self: - if rec.member_status == 'non_benefit': - res['warning'] = {'title': _('ValidationError'), - 'message': _('Not Benefit')} - return res + #@api.onchange('relationn','member_status','gender','birth_date', 'is_scientific_specialty', 'is_medical_specialty', 'is_married', + # 'minor_siblings','member_income','is_married','member_location_conf','education_status','case_study') + #def onchange_member_status(self): + # res ={} + # for rec in self: + # if rec.member_status == 'non_benefit': + # res['warning'] = {'title': _('ValidationError'), + # 'message': _('Not Benefit')} + # return res #Member Suspend Manual def action_suspend(self): diff --git a/odex25_ensan/odex_benefit/views/benefit_view.xml b/odex25_ensan/odex_benefit/views/benefit_view.xml index a146de264..fc7633584 100644 --- a/odex25_ensan/odex_benefit/views/benefit_view.xml +++ b/odex25_ensan/odex_benefit/views/benefit_view.xml @@ -420,9 +420,9 @@ - - @@ -453,8 +453,8 @@ - + - - @@ -596,13 +596,13 @@ + attrs="{('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/> + attrs="{'required':[('add_replacement_mother','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/> - - - - - - - + +