Merge pull request #5353 from expsa/ktty_dev_odex25_ensan

[IMP] odex_benefit: IMP benefit
This commit is contained in:
kchyounes19 2025-11-11 19:32:46 +01:00 committed by GitHub
commit da679e48da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 48 deletions

View File

@ -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)