From 1863890a508437687e7df724cb67152fa123d302 Mon Sep 17 00:00:00 2001 From: younes Date: Tue, 11 Nov 2025 19:24:48 +0100 Subject: [PATCH] [IMP] odex_benefit: IMP benefit --- .../odex_benefit/models/family_expense.py | 50 +------------------ 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/odex25_ensan/odex_benefit/models/family_expense.py b/odex25_ensan/odex_benefit/models/family_expense.py index bb1c57440..49b0b1370 100644 --- a/odex25_ensan/odex_benefit/models/family_expense.py +++ b/odex25_ensan/odex_benefit/models/family_expense.py @@ -208,8 +208,8 @@ class ConfirmBenefitExpense(models.Model): # Search for conflicting records of the same expense type within the past month conflicting_records = self.search([ - ('date', '>=', rec.start_date), - ('date', '<=', rec.end_date), + ('start_date', '<=', rec.end_date), + ('end_date', '>=', rec.start_date), ('expense_type', '=', rec.expense_type), ]) @@ -338,52 +338,6 @@ class ConfirmBenefitExpense(models.Model): # else: # pay.payment_method_id = False - @api.onchange('expense_type', 'date', 'branch_custom_id', 'start_date', 'end_date') - def _onchange_expense_type(self): - # Define base domain for family selection - validation_setting = self.env["family.validation.setting"].search([], limit=1) - - base_domain = ['|', ('state', '=', 'second_approve'), '&', - ('state', 'in', ('waiting_approve', 'first_approve')), ('action_type', '=', 'suspended')] - if self.branch_custom_id: - base_domain.append(('branch_custom_id', '=', self.branch_custom_id.id)) - min_income = validation_setting.benefit_category_ids.mapped('mini_income_amount') - max_income = validation_setting.benefit_category_ids.mapped('max_income_amount') - base_domain.extend([('member_income', '>=', min(min_income)), ('member_income', '<=', max(max_income))]) - base_domain.extend([('benefit_category_id', '!=', False)]) - if self.expense_type == 'family_invoice': - base_domain.append(('meal_card', '=', True)) - - # if self.date: - if self.start_date and self.end_date: - # Calculate the start date for the past month range - month_ago = self.date - relativedelta(months=1) - - # Search for conflicting records of the same expense type within the past month - conflicting_records = self.search([ - ('date', '>=', self.start_date), - ('date', '<=', self.end_date), - ('expense_type', '=', self.expense_type), - ]) - - if conflicting_records: - # Gather the family IDs that are already associated with the same expense type - conflicting_family_ids = conflicting_records.mapped('family_ids').ids - base_domain.append(('id', 'not in', conflicting_family_ids)) - related_records = self.family_ids = self.env['grant.benefit'].search(base_domain) - if related_records and self.branch_custom_id: - self.family_ids = [(6, 0, related_records.ids)] # 6 means 'set' in Many2many - else: - self.family_ids = [(5,)] # Clear the records if source_field is empty - # self.family_ids = self.env['grant.benefit'].search(base_domain).ids - - # Return domain restrictions - return { - 'domain': { - 'family_ids': base_domain, - } - } - def action_accounting_transfer(self): for rec in self: validation_setting = self.env["family.validation.setting"].search([], limit=1)