From e038512488fb68ecf0b8e2c5b1e17b81222bc98f Mon Sep 17 00:00:00 2001 From: younes Date: Thu, 18 Dec 2025 13:28:32 +0100 Subject: [PATCH] [IMP] odex_benefit: IMP benefit --- odex25_benefit/odex_benefit/models/benefit.py | 36 ++++++--- .../odex_benefit/models/benefit_config.py | 1 + .../odex_benefit/models/family_debits.py | 1 + .../odex_benefit/views/benefit_view.xml | 73 +++++++++++++++++++ 4 files changed, 102 insertions(+), 9 deletions(-) diff --git a/odex25_benefit/odex_benefit/models/benefit.py b/odex25_benefit/odex_benefit/models/benefit.py index 18e581502..38e5a4dce 100644 --- a/odex25_benefit/odex_benefit/models/benefit.py +++ b/odex25_benefit/odex_benefit/models/benefit.py @@ -147,6 +147,7 @@ class GrantBenefitProfile(models.Model): cloth_ids = fields.One2many('benefit.cloth', 'benefit_id') expenses_request_ids = fields.One2many('benefit.expenses', 'benefit_id') expenses_ids = fields.One2many('expenses.line', 'benefit_id') + mother_expenses_ids = fields.One2many('expenses.line','mother_benefit_id',string="Mother Commitments / Expenses") # Father's case and his data # Birth Date # Address # dead data # Father's case and his data # family_name = fields.Char(string="Family Name", tracking=True) @@ -212,6 +213,8 @@ class GrantBenefitProfile(models.Model): is_mother_work = fields.Boolean('Is Mother Work?') mother_has_disabilities = fields.Boolean('Has Disabilities?') mother_income = fields.Float("Mother Income", digits=(16, 0)) + mother_net_income = fields.Float(string="Mother Net Income",compute='_compute_mother_net_income', + store=True,help="Mother gross income minus her deducted expenses and monthly debt installments") mother_birth_date = fields.Date(string="Birth Date") mother_age = fields.Integer(string="Age", compute='_compute_get_mother_age') mother_city_id = fields.Many2one('res.country.city', string='City') @@ -411,6 +414,7 @@ class GrantBenefitProfile(models.Model): meal_card = fields.Boolean(string="Meal Card",related="district_id.meal_card", store=True,related_sudo=True) attachment_ids = fields.One2many('ir.attachment', 'benefit_id') family_debits_ids = fields.One2many('family.debits', 'benefit_id') + mother_debits_ids = fields.One2many('family.debits','mother_benefit_id',string="Mother Debts") researcher_id = fields.Many2one("committees.line", string="Researcher",tracking=True) assigned_researcher_id = fields.Many2one('committees.line',string='Assigned Researcher',tracking=True) auto_accept_for_member = fields.Boolean(string="Auto Accept For members", default=True) @@ -627,6 +631,20 @@ class GrantBenefitProfile(models.Model): ('unique_code', "unique (code) WHERE state NOT IN ('draft', 'new')", 'This code already exists') ] + @api.depends('mother_income', 'is_mother_work','mother_expenses_ids','mother_debits_ids') + def _compute_mother_net_income(self): + for rec in self: + if not rec.is_mother_work: + rec.mother_net_income = 0.0 + continue + + deductions = ( + sum(rec.mother_expenses_ids.filtered('deduct_from_family_income').mapped('amount')) + + sum(rec.mother_debits_ids.filtered('deduct_from_family_income').mapped('monthly_installment')) + ) + + rec.mother_net_income = max(rec.mother_income - deductions, 0.0) + def _compute_total_families(self): for record in self: record.total_father_families = self.search_count([('father_id_number','=',record.father_id_number),('id','!=',record.id)]) @@ -857,7 +875,7 @@ class GrantBenefitProfile(models.Model): '&', ('res_model', '=', 'education.status'), ('res_id', 'in', self.mother_education_status_ids.ids), '&', ('res_model', '=', 'family.debits'), - ('res_id', 'in', self.family_debits_ids.ids), + ('res_id', 'in', (self.family_debits_ids + self.mother_debits_ids).ids), '&', ('res_model', '=', 'salary.line'), ('res_id', 'in', self.salary_ids.ids), '&', ('res_model', '=', 'family.member'), @@ -1260,12 +1278,12 @@ class GrantBenefitProfile(models.Model): 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: + if mini_income_for_mother < rec.mother_net_income <= max_income_for_mother: reasons.append(_("The mother's income is between minimum and maximum thresholds.")) status = 'non_benefit' - elif rec.mother_income <= mini_income_for_mother: + elif rec.mother_net_income <= mini_income_for_mother: status = 'benefit' - elif rec.mother_income > max_income_for_mother: + elif rec.mother_net_income > max_income_for_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'): @@ -1358,12 +1376,12 @@ class GrantBenefitProfile(models.Model): 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_net_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.calculate_income(rec.mother_income, rec.mother_status, rec.salary_ids) + rec.calculate_income(rec.mother_net_income, rec.mother_status, rec.salary_ids) rec.add_or_replace_mother_as_member() # Handle replacement mother update/create @@ -1398,7 +1416,7 @@ 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.calculate_income(res.mother_income, res.mother_status, res.salary_ids) + res.calculate_income(res.mother_net_income, res.mother_status, res.salary_ids) res.add_or_replace_mother_as_member() # Add replacement mother if res.add_replacement_mother and res.replacement_mother_id_number: @@ -2051,7 +2069,7 @@ class GrantBenefitProfile(models.Model): 'member_location_conf': rec.mother_location_conf.id, 'age': rec.mother_age, 'is_work': rec.is_mother_work, - 'member_income': rec.mother_income, + 'member_income': rec.mother_net_income, 'education_status': rec.education_status, #'member_status': rec.mother_status, 'member_education_status_ids': [(5, 0)] + [(4, edu.id) for edu in rec.mother_education_status_ids], @@ -2449,7 +2467,7 @@ class GrantBenefitProfile(models.Model): if partner_exist or benefit_exist: raise ValidationError(_("The account number already exists!")) - @api.onchange('mother_marital_conf', 'mother_location_conf', 'mother_income') + @api.onchange('mother_marital_conf', 'mother_location_conf', 'mother_net_income') def _onchange_mother_info(self): res = {} if self.mother_status == 'non_benefit': diff --git a/odex25_benefit/odex_benefit/models/benefit_config.py b/odex25_benefit/odex_benefit/models/benefit_config.py index 39c2e6d18..9f6b14790 100644 --- a/odex25_benefit/odex_benefit/models/benefit_config.py +++ b/odex25_benefit/odex_benefit/models/benefit_config.py @@ -474,6 +474,7 @@ class ExpensesLine(models.Model): category_id = fields.Many2one( 'benefit.category') benefit_id = fields.Many2one('grant.benefit') + mother_benefit_id = fields.Many2one('grant.benefit',string="Mother Benefit",ondelete='cascade') currency_id = fields.Many2one('res.currency', related='benefit_id.currency_id') expenses_type_custom = fields.Many2one('expenses.type') expenses_type = fields.Selection( diff --git a/odex25_benefit/odex_benefit/models/family_debits.py b/odex25_benefit/odex_benefit/models/family_debits.py index 7cdaaf0ea..304442dfe 100644 --- a/odex25_benefit/odex_benefit/models/family_debits.py +++ b/odex25_benefit/odex_benefit/models/family_debits.py @@ -19,6 +19,7 @@ class FamilyDebits(models.Model): loan_end_date = fields.Date(string='Loan End Date') loan_reason = fields.Many2one("loan.reason",string='Loan Reason') benefit_id = fields.Many2one("grant.benefit") + mother_benefit_id = fields.Many2one('grant.benefit',string="Mother Benefit",ondelete='cascade') currency_id = fields.Many2one('res.currency', related='benefit_id.currency_id') loan_attach = fields.Binary(attachment=True,string='Loan Attach') description = fields.Char(string='Description') diff --git a/odex25_benefit/odex_benefit/views/benefit_view.xml b/odex25_benefit/odex_benefit/views/benefit_view.xml index eb9281025..926d99b46 100644 --- a/odex25_benefit/odex_benefit/views/benefit_view.xml +++ b/odex25_benefit/odex_benefit/views/benefit_view.xml @@ -816,6 +816,10 @@ options="{'currency_field': 'currency_id', 'field_digits': False}" digits="[16,0]" attrs="{'invisible':[('is_mother_work','=',False)],'required':[('is_mother_work','=',True)],'readonly':[('state','not in',['draft','new','complete_info'])]}"/> + @@ -864,6 +868,75 @@ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+