diff --git a/odex25_ensan/odex_benefit/i18n/ar_001.po b/odex25_ensan/odex_benefit/i18n/ar_001.po
index dae6d36e5..72c31c4e4 100644
--- a/odex25_ensan/odex_benefit/i18n/ar_001.po
+++ b/odex25_ensan/odex_benefit/i18n/ar_001.po
@@ -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 "تعديل العائلة"
\ No newline at end of file
+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 "يخصم من دخل الأسرة"
\ No newline at end of file
diff --git a/odex25_ensan/odex_benefit/models/benefit.py b/odex25_ensan/odex_benefit/models/benefit.py
index a6ada1cbf..582af25ad 100644
--- a/odex25_ensan/odex_benefit/models/benefit.py
+++ b/odex25_ensan/odex_benefit/models/benefit.py
@@ -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:
diff --git a/odex25_ensan/odex_benefit/models/benefit_config.py b/odex25_ensan/odex_benefit/models/benefit_config.py
index dc775ba08..daefcd8d5 100644
--- a/odex25_ensan/odex_benefit/models/benefit_config.py
+++ b/odex25_ensan/odex_benefit/models/benefit_config.py
@@ -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()
diff --git a/odex25_ensan/odex_benefit/models/family_debits.py b/odex25_ensan/odex_benefit/models/family_debits.py
index fc413c6b6..fa6d4686a 100644
--- a/odex25_ensan/odex_benefit/models/family_debits.py
+++ b/odex25_ensan/odex_benefit/models/family_debits.py
@@ -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'
diff --git a/odex25_ensan/odex_benefit/views/benefit_view.xml b/odex25_ensan/odex_benefit/views/benefit_view.xml
index 12a57d450..ad5c80f0b 100644
--- a/odex25_ensan/odex_benefit/views/benefit_view.xml
+++ b/odex25_ensan/odex_benefit/views/benefit_view.xml
@@ -314,8 +314,6 @@
options="{'currency_field': 'currency_id'}" readonly="1" force_save="1"/>
-
@@ -1026,7 +1024,26 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+