[IMP] IMP benefit services

This commit is contained in:
younes 2025-10-11 15:04:35 +01:00
parent b5c8ce6023
commit 36b8eb29cb
3 changed files with 15 additions and 56 deletions

View File

@ -192,6 +192,8 @@ class ServiceRequest(models.Model):
commands.append((0, 0, {
'service_id': False,
'service_request_id': rec.id,
'name': attachment_line.name,
'notes':attachment_line.notes,
'previous_service_attachment_settings_id': attachment_line.id,
}))
@ -523,7 +525,6 @@ class ServiceRequest(models.Model):
res = {}
Service = self.env['service.request']
today = fields.Date.today()
# to delete
date_before_year = today - timedelta(days=365)
for rec in self:
@ -699,6 +700,17 @@ class ServiceRequest(models.Model):
raise ValidationError(_("You cannot request more than %s"))
continue
if rec.service_cat.service_type == 'health_care':
domain = [
('family_id', '=', self.family_id.id),
('service_cat.service_type', '=', 'health_care'),
('date', '>', date_before_year),
('id', '!=', self._origin.id),
('state', '!=', 'refused')
]
existing_requests_within_year = self.search(domain)
rec.service_max_amount = rec.service_cat.max_health_care_amount - sum(existing_requests_within_year.mapped('requested_service_amount'))
if rec.requested_service_amount > rec.service_max_amount and service_type not in special_services:
raise ValidationError(
_("You cannot request more than %s") % rec.service_max_amount
@ -741,47 +753,6 @@ class ServiceRequest(models.Model):
elif rec.rent_period > rec.service_cat.rent_period:
raise UserError(
_("You Cannot request this service for period more than %s") % rec.service_cat.rent_period)
# Validation for 'family and member' benefit type with 'health_care' service type
if rec.service_cat.service_type == 'health_care':
# Add current record conditionally
domain = [
('family_id', '=', self.family_id.id),
('service_cat.service_type', '=', 'health_care'),
('date', '>', date_before_year),
('id', '!=', self._origin.id),
]
# Search for existing requests
existing_requests_within_year = self.search(domain)
# Include current record in the calculation
total_amount_in_year = sum(existing_requests_within_year.mapped('requested_service_amount'))
total_amount_in_year += rec.requested_service_amount
if total_amount_in_year > rec.service_cat.max_health_care_amount:
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _(
"You cannot request more than %s within year") % rec.service_cat.max_health_care_amount}
return res
# Validation for 'family and member' benefit type with 'health_care' service type
if rec.service_cat.service_type == 'recruiting_domestic_worker_or_nurse':
# Add current record conditionally
domain = [
('family_id', '=', self.family_id.id),
('service_cat.service_type', '=', 'recruiting_domestic_worker_or_nurse'),
('date', '>', date_before_year),
('id', '!=', self._origin.id),
]
# Search for existing requests
existing_requests_within_year = self.search(domain)
if existing_requests_within_year:
raise UserError(_("You cannot request this service more than once Within year."))
# Include current record in the calculation
if rec.requested_service_amount > rec.service_cat.max_recruiting_domestic_worker_or_nurse_amount:
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _(
"You cannot request more than %s within year") % rec.service_cat.max_recruiting_domestic_worker_or_nurse_amount}
return res
# Validation for 'member' benefit type with 'marriage' service type
if rec.benefit_type == 'member' and rec.service_cat.service_type == 'marriage':
if rec.member_age > rec.service_cat.member_max_age:

View File

@ -45,8 +45,6 @@ class ServicesSettings(models.Model):
transportation_insurance_ids = fields.One2many('transportation.insurance', 'services_settings_id')
#Health_care
max_health_care_amount = fields.Float(string='Max Health Care Amount In Year')
#recruiting_domestic_worker_or_nurse
max_recruiting_domestic_worker_or_nurse_amount = fields.Float(string='Max Recruiting Domestic Worker Or Nurse Care Amount')
# Marriage
member_max_age = fields.Integer(string='Member Max Age')
member_max_payroll = fields.Float(string='Member Max Payroll')

View File

@ -35,6 +35,8 @@
<field name="max_limit_type"/>
<field name="max_amount"
attrs="{'invisible': [('max_limit_type', '!=', 'fixed')]}"/>
<field name="max_health_care_amount"
attrs="{'invisible': ['|',('service_type','!=','health_care'),('max_limit_type', '!=', 'service')]}"/>
<field name="min_count_member"
attrs="{'invisible':[('service_type','!=','buy_car')]}"/>
<field name="buy_home_max_total_amount" attrs="{'invisible':['|',('service_type','!=','buy_home'),('max_limit_type', '!=', 'amount_person')]}"/>
@ -196,18 +198,6 @@
</field>
</group>
</page>
<page string="Health Care Settings"
attrs="{'invisible':[('service_type','!=','health_care')]}">
<group>
<field name="max_health_care_amount"/>
</group>
</page>
<page string="Recruiting Domestic Worker Or Nurse Settings"
attrs="{'invisible':[('service_type','!=','recruiting_domestic_worker_or_nurse')]}">
<group>
<field name="max_recruiting_domestic_worker_or_nurse_amount"/>
</group>
</page>
<page string="Marriage Settings" attrs="{'invisible':[('service_type','!=','marriage')]}">
<group>
<field name="member_max_age"/>