IMP benefit

This commit is contained in:
younes 2025-09-08 11:14:54 +01:00
parent 3c30d4c4de
commit 79607a5bb5
5 changed files with 123 additions and 60 deletions

View File

@ -1705,6 +1705,7 @@ msgstr "نوع المرفق"
#. module: odex_benefit
#: model:ir.model,name:odex_benefit.model_ir_attachment
#: model:ir.model.fields,field_description:odex_benefit.field_expenses_line__expense_attachments
#: model:ir.model.fields,field_description:odex_benefit.field_family_member__attachment_ids
#: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__attachment_ids
#: model:ir.model.fields,field_description:odex_benefit.field_salary_line__salary_attach
@ -5012,6 +5013,7 @@ msgstr "نوع الاجراء"
#: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__expenses_ids
#: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__expenses_total
#: model_terms:ir.ui.view,arch_db:odex_benefit.expenses_line_form
#: model_terms:ir.ui.view,arch_db:odex_benefit.grant_benefit_form
msgid "Expenses"
msgstr "الالتزامات"
@ -11498,6 +11500,7 @@ msgstr "الاعدادات"
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_needs_payment_line__amount
#: model_terms:ir.ui.view,arch_db:odex_benefit.grant_benefit_form
msgid "Total"
msgstr "الإجمالي"
@ -15272,4 +15275,31 @@ msgstr "شهادة الزواج مطلوبة للفرد '%s' عند تحديده
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__family_edit
msgid "Family Edit"
msgstr "تعديل العائلة"
msgstr "تعديل العائلة"
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__family_return_reason
msgid "Family Return Reason"
msgstr "سبب ارجاع للاسرة"
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_attachments_settings__is_mother_salary
#: model:ir.model.fields,field_description:odex_benefit.field_salary_line__is_mother_salary
msgid "Is Mother Salary"
msgstr "هل هو راتب الأم"
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_salary_line__approved
msgid "Is Approved"
msgstr "تم اعتماده"
#. module: odex_benefit
#: model_terms:ir.ui.view,arch_db:odex_benefit.grant_benefit_form
msgid "Expenses & Family Loans"
msgstr "الديون والالتزامات"
#. module: odex_benefit
#: model:ir.model.fields,field_description:odex_benefit.field_expenses_line__deduct_from_family_income
#: model:ir.model.fields,field_description:odex_benefit.field_family_debits__deduct_from_family_income
msgid "Deduct from Family Income"
msgstr "يخصم من دخل الأسرة"

View File

@ -359,7 +359,7 @@ class GrantBenefitProfile(models.Model):
benefit_needs_percent = fields.Float()
followers_total = fields.Integer(string="followers Total")
followers_out_total = fields.Integer(string="followers Total", )
expenses_total = fields.Integer(string="Expenses", compute="get_total_expenses")
expenses_total = fields.Integer(string="Expenses", compute="get_total_expenses",store=True)
#################################################################
# Boolean Fields to use in filters#TODO
#################################################################
@ -387,7 +387,7 @@ class GrantBenefitProfile(models.Model):
is_sport = fields.Boolean()
support_separation = fields.Boolean(string="Support Separation", tracking=True)
is_life = fields.Boolean(string="Life", default=True)
total_expenses = fields.Float('Total Expenses', compute="get_total_expenses")
total_expenses = fields.Float('Total Expenses', compute="get_total_expenses",store=True)
total_income = fields.Float('Total Income', compute="get_total_income")
benefit_member_count = fields.Integer(string="Members count", compute="get_members_count")
non_member_count = fields.Integer(string="Non Benefit Members count", compute="get_non_members_count")
@ -1728,45 +1728,49 @@ class GrantBenefitProfile(models.Model):
height = (rec.height / 100)
rec.p_weight = (rec.weight / (height * height))
@api.depends(
'expenses_ids',
'expenses_ids.deduct_from_family_income',
'expenses_ids.amount',
'family_debits_ids',
'family_debits_ids.deduct_from_family_income',
'family_debits_ids.monthly_installment',
)
def get_total_expenses(self):
for ben in self:
if ben.id:
followers = ben.env['benefit.followers'].sudo().search([('benefit_id', '=', ben.id)])
expenses = ben.env['expenses.line'].sudo().search([('benefit_id', '=', ben.id)])
total_expenses = 0.0
if ben.expenses_ids and ben.family_debits_ids:
total_expenses = sum(ben.expenses_ids.filtered(lambda e: e.state == 'accepted').mapped('amount')) + sum(ben.family_debits_ids.filtered(lambda e: e.state == 'accepted').mapped('monthly_installment'))
elif ben.expenses_ids and not ben.family_debits_ids:
total_expenses = sum(ben.expenses_ids.filtered(lambda e: e.state == 'accepted').mapped('amount'))
elif ben.family_debits_ids and not ben.expenses_ids:
total_expenses = sum(ben.family_debits_ids.filtered(lambda e: e.state == 'accepted').mapped('monthly_installment'))
else:
total_expenses = 0.0
for rec in ben:
if followers:
rec.followers_total = len(followers)
if expenses:
rec.expenses_total = len(expenses)
rec.total_expenses = total_expenses
followers = ben.env['benefit.followers'].sudo().search([('benefit_id', '=', ben.id)])
expenses = ben.env['expenses.line'].sudo().search([('benefit_id', '=', ben.id)])
total_expenses = 0.0
if ben.expenses_ids and ben.family_debits_ids:
total_expenses = sum(ben.expenses_ids.filtered(lambda e: e.deduct_from_family_income).mapped('amount')) + sum(ben.family_debits_ids.filtered(lambda e: e.deduct_from_family_income).mapped('monthly_installment'))
elif ben.expenses_ids and not ben.family_debits_ids:
total_expenses = sum(ben.expenses_ids.filtered(lambda e: e.deduct_from_family_income).mapped('amount'))
elif ben.family_debits_ids and not ben.expenses_ids:
total_expenses = sum(ben.family_debits_ids.filtered(lambda e: e.deduct_from_family_income).mapped('monthly_installment'))
else:
self.total_expenses = 0.0
total_expenses = 0.0
if followers:
ben.followers_total = len(followers)
if expenses:
ben.expenses_total = len(expenses)
ben.total_expenses = total_expenses
def get_total_income(self):
validation_setting = self.env["family.validation.setting"].search([], limit=1)
max_income_for_mother = validation_setting.max_income_for_mother
for rec in self:
rec.total_income = 0.0
# Helper function to calculate income based on mother/replacement_mother status and salary_ids
def calculate_income(income, status, salary_ids):
total = 0.0
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)
income_type = self.env['attachments.settings'].search([('is_mother_salary','=',True)],limit=1)
income_type = self.env['attachments.settings'].search([('is_mother_salary', '=', True)], limit=1)
if should_have_salary_line:
if not existing_mother_salary:
salary_ids.create({
self.env['salary.line'].create({
'benefit_id': rec.id,
'is_mother_salary': True,
'salary_amount': income,
@ -1785,18 +1789,15 @@ class GrantBenefitProfile(models.Model):
total = sum(
salary_ids.filtered(lambda e: e.approved).mapped('salary_amount'))
return total
# Helper function to calculate income based on mother/replacement_mother status and salary_ids
if not rec.add_replacement_mother:
# Calculate total income for mother
rec.total_income = calculate_income(rec.mother_income, rec.mother_status, rec.salary_ids)
if rec.add_replacement_mother:
# Calculate total income for replacement mother if applicable
rec.total_income += calculate_income(rec.replacement_mother_income, rec.replacement_mother_status,
rec.salary_ids)
# total_income = mother_income + sum(approved salarys)
# approved_salarys = fillter
# mother_inocme = if replacement_mother : income else mother.income income > max
rec.salary_ids)
def get_mother_name(self):
for rec in self:
@ -1810,7 +1811,8 @@ class GrantBenefitProfile(models.Model):
def get_replacement_mother_name(self):
for rec in self:
name = ''
if all([rec.replacement_mother_name, rec.replacement_mother_second_name, rec.replacement_mother_third_name, rec.replacement_mother_family_name]):
if all([rec.replacement_mother_name, rec.replacement_mother_second_name, rec.replacement_mother_third_name,
rec.replacement_mother_family_name]):
name = rec.replacement_mother_name + " " + rec.replacement_mother_second_name + " " + rec.replacement_mother_third_name + " " + rec.replacement_mother_family_name
else:
name = name
@ -2039,11 +2041,11 @@ class GrantBenefitProfile(models.Model):
else:
ben.non_member_count = 0.0
@api.depends('salary_ids', 'expenses_ids', 'family_debits_ids.monthly_installment','mother_income','replacement_mother_income','member_ids','family_debits_ids.state','expenses_ids.state','salary_ids.approved')
@api.depends('salary_ids','mother_income','member_ids','salary_ids.approved')
def get_member_income(self):
for ben in self:
ben.get_total_income()
ben.get_total_expenses()
# ben.get_total_income()
# ben.get_total_expenses()
family_income = ben.total_income - ben.total_expenses
if ben.benefit_member_count:
if ben.benefit_member_count > 3:

View File

@ -304,7 +304,7 @@ class Salary(models.Model):
is_mother_salary = fields.Boolean(string="Is Mother Salary", default=False)
approved = fields.Boolean(string="Is Approved", default=False)
is_default = fields.Boolean(string='Is Default?')
state = fields.Selection(string='Status',selection=[('waiting', 'Waiting'),('accepted', 'Accepted'),('refused', 'Refused')],default="accepted")
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)
# @api.depends('salary_amount','state')
@ -472,6 +472,7 @@ class ExpensesLine(models.Model):
category_id = fields.Many2one(
'benefit.category')
benefit_id = fields.Many2one('grant.benefit')
currency_id = fields.Many2one('res.currency', related='benefit_id.currency_id')
expenses_type_custom = fields.Many2one('expenses.type')
expenses_type = fields.Selection(
string='',
@ -488,6 +489,8 @@ class ExpensesLine(models.Model):
amount = fields.Float()
note = fields.Char()
state = fields.Selection(string='Status', selection=[('waiting', 'Waiting'),('accepted', 'Accepted'), ('refused', 'Refused')],default="waiting")
expense_attachments = fields.Many2many('ir.attachment','expenses_line_attachment_rel','expense_line_id','attachment_id',string="Attachment")
deduct_from_family_income = fields.Boolean(string="Deduct from Family Income")
def action_accept(self):
# self.benefit_id.get_member_income()

View File

@ -19,9 +19,11 @@ 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")
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')
state = fields.Selection(string='Status', selection=[('accepted', 'Accepted'), ('refused', 'Refused')])
deduct_from_family_income = fields.Boolean(string="Deduct from Family Income")
def action_accept(self):
self.state = 'accepted'

View File

@ -314,8 +314,6 @@
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"/>
@ -1026,7 +1024,26 @@
</sheet>
</form>
</page>
<page string="Family Loans">
<page string="Expenses &amp; Family Loans">
<separator string="Expenses"/>
<field name="expenses_ids" context="{'default_state': 'accepted'}"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}">
<tree editable="top">
<field name="benefit_id" invisible="1"/>
<field name="expenses_type" invisible="1"/>
<field name="expenses_type_custom"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
<field name="expense_attachments" widget="many2many_attachment_preview"/>
<field name="note"/>
<field name="amount" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="amount"/>
<field name="currency_id" invisible="1"/>
<field name="state" invisible="1"/>
<field name="deduct_from_family_income" widget="boolean_toggle"/>
</tree>
</field>
<separator string="Family Loans"/>
<field name="family_debits_ids" context="{'default_state': 'accepted'}"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}">
<form string="Family Loans">
@ -1035,15 +1052,21 @@
<group>
<field name="loan_giver"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
<field name="loan_amount"/>
<field name="loan_amount" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="number_of_installments"/>
<field name="loan_total_paid"/>
<field name="loan_remaining"/>
<field name="monthly_installment"/>
<field name="loan_total_paid" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="loan_remaining" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="monthly_installment" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="loan_attach"/>
<field name="currency_id" invisible="1"/>
</group>
<group>
<field name="last_paid_amount"/>
<field name="last_paid_amount" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
<field name="last_paid_amount_date"/>
<field name="loan_reason"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
@ -1051,30 +1074,33 @@
<field name="benefit_id" invisible="1"/>
<field name="loan_start_date"/>
<field name="loan_end_date"/>
<field name="deduct_from_family_income" widget="boolean_toggle"/>
</group>
</group>
</sheet>
</form>
<tree>
<field name="loan_giver"/>
<field name="loan_amount"/>
<field name="state" invisible="1"/>
</tree>
</field>
</page>
<page string="expenses">
<field name="expenses_ids" context="{'default_state': 'accepted'}"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])]}">
<tree editable="top">
<field name="benefit_id" invisible="1"/>
<field name="expenses_type" invisible="1"/>
<field name="expenses_type_custom"
options="{'no_create': True, 'no_create_edit': True,'no_quick_create': True, 'no_open': True}"/>
<field name="note"/>
<field name="amount" sum="amount"/>
<field name="monthly_installment" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="loan_amount" widget="monetary"
options="{'currency_field': 'currency_id'}" sum="Total"/>
<field name="currency_id" invisible="1"/>
<field name="state" invisible="1"/>
<field name="deduct_from_family_income" widget="boolean_toggle"/>
</tree>
</field>
<group class="oe_subtotal_footer oe_right">
<label for="rent_amount"
attrs="{'invisible':[('property_type','!=','rent'),('property_type','!=','rent_shared')]}"/>
<field name="rent_amount" nolabel="1" widget="monetary"
options="{'currency_field': 'currency_id'}"
attrs="{'readonly':[('state','not in',['draft','new','complete_info'])],'invisible':[('property_type','!=','rent'),('property_type','!=','rent_shared')]}"/>
<label for="total_expenses"/>
<field name="total_expenses" nolabel="1" widget="monetary"
options="{'currency_field': 'currency_id'}"/>
</group>
</page>
<page string="Income and salary">
<field name="salary_ids" context="{'default_state': 'accepted'}" mode="tree"