From f2298b864b14d9a827f813b1c16885925401708d Mon Sep 17 00:00:00 2001 From: Samir Ladoui Date: Thu, 2 Jan 2025 09:19:22 +0100 Subject: [PATCH] [UPD] odex_benefit_project: change fields with the new logic --- .../models/service_request.py | 48 ++++++++----------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/odex25_ensan/odex_benefit_project/models/service_request.py b/odex25_ensan/odex_benefit_project/models/service_request.py index ef80d3f37..2e45ec916 100644 --- a/odex25_ensan/odex_benefit_project/models/service_request.py +++ b/odex25_ensan/odex_benefit_project/models/service_request.py @@ -33,7 +33,18 @@ class ServiceRequestInherit(models.Model): ) rec.project_id = project - @api.onchange('requested_service_amount', 'benefit_type', 'date', 'service_cat','family_id','device_id','exception_or_steal','home_furnishing_exception','rent_period','has_marriage_course','member_id','home_age') + @api.onchange( + 'requested_service_amount', + 'benefit_type', + 'date', + 'service_cat', + 'family_id', + 'exception_or_steal', + 'home_furnishing_exception', + 'has_marriage_course', + 'home_age', + 'service_reason_id' + ) def onchange_requested_service_amount(self): res = {} today = fields.Date.today() @@ -245,34 +256,13 @@ class ServiceRequestInherit(models.Model): return res # Validation for 'family' benefit type with 'transportation_insurance' service type if rec.benefit_type == 'family' and rec.service_cat.service_type == 'transportation_insurance': - if rec.service_reason == 'government_transportation': - if rec.requested_service_amount > rec.max_government_transportation_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_government_transportation_amount} - return res - if rec.service_reason == 'universities_training_institutes_transportation': - if rec.requested_service_amount > rec.max_universities_training_institutes_transportation_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_universities_training_institutes_transportation_amount} - return res - if rec.service_reason == 'hospitals_transportation': - if rec.requested_service_amount > rec.max_hospitals_transportation_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_hospitals_transportation_amount} - return res - if rec.service_reason == 'programs_transportation': - if rec.requested_service_amount > rec.max_programs_transportation_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_hospitals_transportation_amount} - return res + if rec.service_reason_id and rec.requested_service_amount > rec.max_amount: + self.benefit_type = False + res['warning'] = { + 'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % rec.max_amount + } + return res # Validation for 'family' benefit type with 'recruiting_driver' service type if rec.benefit_type == 'family' and rec.service_cat.service_type == 'debits': if rec.requested_service_amount > rec.service_cat.max_debits_amount: