IMP benefit

This commit is contained in:
younes 2025-09-07 13:00:07 +01:00
parent 09ef499ad1
commit 57d14b3f8d
3 changed files with 47 additions and 21 deletions

View File

@ -604,6 +604,7 @@ class GrantBenefitProfile(models.Model):
string="Company Currency",
related='company_id.currency_id')
family_edit = fields.Boolean(string='Family Edit', default=False)
family_return_reason = fields.Text(string="Family Return Reason")
_sql_constraints = [
('unique_code', "unique (code) WHERE state NOT IN ('draft', 'new')", 'This code already exists')
@ -1753,6 +1754,7 @@ class GrantBenefitProfile(models.Model):
def get_total_income(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.total_income = 0.0
@ -1760,15 +1762,27 @@ class GrantBenefitProfile(models.Model):
# Helper function to calculate income based on mother/replacement_mother status and salary_ids
def calculate_income(income, status, salary_ids):
total = 0.0
accepted_salaries = sum(salary_ids.filtered(lambda e: e.state == 'accepted').mapped('salary_amount'))
existing_mother_salary = salary_ids.filtered(lambda x: x.is_mother_salary == True)
should_have_salary_line = (status == 'benefit' and income > max_income_for_mother)
if should_have_salary_line:
if not existing_mother_salary:
salary_ids.create({
'benefit_id': rec.id,
'is_mother_salary': True,
'salary_amount': income,
'state': 'accepted',
})
elif existing_mother_salary:
existing_mother_salary.write({'salary_amount': income})
else:
if existing_mother_salary:
existing_mother_salary.unlink()
if status == 'non_benefit':
total = accepted_salaries
total = sum(salary_ids.filtered(lambda e: e.state == 'accepted' and not e.is_mother_salary).mapped(
'salary_amount'))
elif status == 'benefit':
if not salary_ids:
total = income if income > mini_income_for_mother else 0.0
else:
total = accepted_salaries + (income if income > mini_income_for_mother else 0.0)
total = sum(
salary_ids.filtered(lambda e: e.state == 'accepted').mapped('salary_amount'))
return total
if not rec.add_replacement_mother:
# Calculate total income for mother
@ -2019,17 +2033,20 @@ class GrantBenefitProfile(models.Model):
@api.depends('salary_ids', 'expenses_ids', 'family_debits_ids.monthly_installment','mother_income','member_ids','family_debits_ids.state','expenses_ids.state','salary_ids.state')
def get_member_income(self):
validation_setting = self.env["family.validation.setting"].search([], limit=1)
max_income_for_mother = validation_setting.max_income_for_mother
total = 0
# max_income_for_mother = validation_setting.max_income_for_mother
# total = 0
for ben in self:
if ben.mother_income >= max_income_for_mother and ben.family_debits_ids:
family_income = ben.total_income - ben.total_expenses
elif ben.mother_income >= max_income_for_mother:
family_income = ben.total_income - ben.total_expenses
elif ben.family_debits_ids:
family_income = ben.total_income - ben.total_expenses
else:
family_income = ben.total_income - ben.total_expenses
ben.get_total_income()
ben.get_total_expenses()
# if ben.mother_income >= max_income_for_mother and ben.family_debits_ids:
# family_income = ben.total_income - ben.total_expenses
# elif ben.mother_income >= max_income_for_mother:
# family_income = ben.total_income - ben.total_expenses
# elif ben.family_debits_ids:
# family_income = ben.total_income - ben.total_expenses
# else:
# family_income = ben.total_income - ben.total_expenses
family_income = ben.total_income - ben.total_expenses
if ben.benefit_member_count:
if ben.benefit_member_count > 3:
ben.member_income = family_income / ben.benefit_member_count
@ -2041,10 +2058,10 @@ class GrantBenefitProfile(models.Model):
@api.depends("member_income")
def get_benefit_category(self):
for rec in self:
if rec.member_income:
result = self.env['benefit.category'].sudo().search(
[('mini_income_amount', '<=', rec.member_income),
('max_income_amount', '>=', rec.member_income)])
result = self.env['benefit.category'].sudo().search(
[('mini_income_amount', '<=', rec.member_income),
('max_income_amount', '>=', rec.member_income)])
if result:
rec.benefit_category_id = result.id
else:
rec.benefit_category_id = None

View File

@ -300,6 +300,7 @@ class Salary(models.Model):
attach_start_date = fields.Date(string='Attach Start Date')
attach_end_date = fields.Date(string='Attach End Date')
is_required = fields.Boolean(string='Is Required?')
is_mother_salary = fields.Boolean(string="Is Mother Salary", default=False)
is_default = fields.Boolean(string='Is Default?')
state = fields.Selection(string='Status',selection=[('waiting', 'Waiting'),('accepted', 'Accepted'),('refused', 'Refused')],default="waiting")
# total_salary = fields.Float(string="Total Salary", compute='_compute_total_salary',store=True)

View File

@ -311,6 +311,10 @@
<field name="currency_id" groups="base.group_multi_currency"/>
<field name="member_income" widget="monetary"
options="{'currency_field': 'currency_id'}" readonly="1" force_save="1"/>
<field name="total_income" widget="monetary"
options="{'currency_field': 'currency_id'}" invisible="1"/>
<field name="total_expenses" widget="monetary"
options="{'currency_field': 'currency_id'}" invisible="1"/>
<field name="benefit_category_id" readonly="1" force_save="1"/>
<field name="mother_family_member_id" invisible="1" readonly="1"/>
<field name="replacement_mother_family_member_id" invisible="1" readonly="1"/>
@ -1079,6 +1083,7 @@
<field name="benefit_id" invisible="1"/>
<field name="income_type"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
<field name="is_mother_salary" readonly="1" force_save="1"/>
<field name="salary_amount"/>
<field name="salary_attach" widget="many2many_attachment_preview"/>
<field name="attach_start_date"/>
@ -1363,6 +1368,9 @@
<field name="has_needs" invisible="1"/>
<!-- <field name="required_attach" attrs="{'required':[('state','not in',['draft'])]}"/>-->
</group>
<group>
<field name="family_return_reason"/>
</group>
</page>
</notebook>