[IMP] IMP benefit services

This commit is contained in:
younes 2025-10-11 13:55:27 +01:00
parent fa2754648a
commit b5c8ce6023
3 changed files with 18 additions and 52 deletions

View File

@ -537,9 +537,9 @@ class ServiceRequest(models.Model):
special_services = ['home_furnishing', 'electrical_devices']
if rec.service_cat.service_type == 'buy_car':
if rec.family_id.has_car:
raise UserError(_("You cannot request this service because you have a car."))
raise ValidationError(_("You cannot request this service because you have a car."))
if rec.benefit_member_count < rec.service_cat.min_count_member:
raise UserError(
raise ValidationError(
_("You cannot request this service because you are less than %s") % rec.service_cat.min_count_member)
if rec.service_cat.service_type == 'recruiting_driver':
son_members_above_age = rec.family_id.mapped('member_ids').filtered(
@ -556,15 +556,15 @@ class ServiceRequest(models.Model):
lambda
x: x.relationn.relation_type == 'replacement_mother' and x.replacement_is_mother_work)
if not rec.family_id.has_car:
raise UserError(_("You cannot request this service because you do not have a car"))
raise ValidationError(_("You cannot request this service because you do not have a car"))
if son_members_above_age or daughter_members_above_age:
raise UserError(
raise ValidationError(
_("You cannot request this service because children above 18 years"))
if rec.family_id.add_replacement_mother and not disable_replacement_mother and not work_replacement_mother:
raise UserError(
raise ValidationError(
_("You cannot request this service because mother should be worked or has disability"))
if not rec.family_id.add_replacement_mother and not disable_mother and not work_mother:
raise UserError(
raise ValidationError(
_("You cannot request this service because mother should be worked or has disability"))
# check if 'home_restoration' service
if service_type in ['home_maintenance','complete_building_house','buy_home']:
@ -577,7 +577,7 @@ class ServiceRequest(models.Model):
if existing_request_restoration and existing_request_restoration.date:
if service_type == 'buy_home':
raise UserError(_(
raise ValidationError(_(
"You cannot request this service together with 'home_restoration' within the same recurrence period."
))
else:
@ -589,20 +589,20 @@ class ServiceRequest(models.Model):
)
if today < next_allowed_restoration_date:
raise UserError(_(
raise ValidationError(_(
"You cannot request this service together with 'home_restoration' within the same recurrence period."
))
if service_type == 'transportation_insurance':
if rec.family_id.has_car:
raise UserError(_("You cannot request this service because you have a car."))
raise ValidationError(_("You cannot request this service because you have a car."))
if service_type == 'buy_home':
if rec.service_cat.buy_home_max_total_amount < rec.amount_for_buy_home_for_member_count:
raise UserError(_(
raise ValidationError(_(
"You can request this service because the total housing amount (%.2f) "
"is still under the maximum limit of %.2f."
) % (rec.amount_for_buy_home_for_member_count, rec.service_cat.buy_home_max_total_amount))
if rec.home_age > rec.service_cat.home_age:
raise UserError(
raise ValidationError(
_("You cannot request this service Again Because the home Age More than %s") % rec.service_cat.home_age)
if allowed:
@ -616,7 +616,7 @@ class ServiceRequest(models.Model):
pass
elif allowed == 'once':
if Service.search_count(base_domain):
raise UserError(_("You cannot request this service more than once."))
raise ValidationError(_("You cannot request this service more than once."))
else:
if service_type in special_services:
if service_type == 'home_furnishing':
@ -629,11 +629,11 @@ class ServiceRequest(models.Model):
if not rec.home_furnishing_exception:
rec.service_max_amount = rec.service_cat.max_amount
if total_amount > rec.service_cat.max_amount:
raise UserError(_("You cannot request more than %s") % rec.service_max_amount)
raise ValidationError(_("You cannot request more than %s") % rec.service_max_amount)
if rec.home_furnishing_exception:
rec.service_max_amount = rec.service_cat.max_furnishing_amount_if_exception
if total_amount > rec.service_cat.max_furnishing_amount_if_exception:
raise UserError(_("You cannot request more than %s") % rec.service_max_amount)
raise ValidationError(_("You cannot request more than %s") % rec.service_max_amount)
if service_type == 'electrical_devices':
rec.service_max_amount = rec.device_id.price_unit if rec.device_id else 0.0
if rec.device_id:
@ -651,7 +651,7 @@ class ServiceRequest(models.Model):
)
allowed_qty = allowed_line.allowed_quantity if allowed_line else 0
if total_qty > allowed_qty:
raise UserError(_(
raise ValidationError(_(
"You cannot request this device more than %s times within %s %s."
) % (allowed_qty, interval, period))
@ -672,7 +672,7 @@ class ServiceRequest(models.Model):
next_allowed_date = next_allowed_date.date()
if today < next_allowed_date:
raise UserError(_(
raise ValidationError(_(
"You can only request this service again after %s."
) % next_allowed_date.strftime('%Y-%m-%d'))
@ -696,14 +696,13 @@ class ServiceRequest(models.Model):
if service_type == 'transportation_insurance':
if rec.service_reason_id and rec.requested_service_amount > rec.max_amount:
raise UserError(_("You cannot request more than %s"))
raise ValidationError(_("You cannot request more than %s"))
continue
if rec.requested_service_amount > rec.service_max_amount and service_type not in special_services:
raise UserError(
raise ValidationError(
_("You cannot request more than %s") % rec.service_max_amount
)
# if rec.benefit_type == 'family' and rec.service_cat.service_type == 'electrical_devices':
# Check for existing request of the same type in seven years and not exception or steal
# existing_request = self.search([
@ -723,7 +722,6 @@ class ServiceRequest(models.Model):
res['warning'] = {'title': _('ValidationError'),
'message': _("You cannot request more than %s") % max_requested_amount}
return res
# Validation for 'family' benefit type
if rec.benefit_type == 'family' and rec.service_cat.service_type == 'rent':
rent_line_id = rec.service_cat.rent_lines.filtered(
@ -822,22 +820,6 @@ class ServiceRequest(models.Model):
if rec.member_id.age > rec.service_cat.eid_gift_max_age:
raise UserError(
_("You cannot request this service because your age should be less than %s") % rec.service_cat.eid_gift_max_age)
# Validation for 'family and member' benefit type with 'natural_disasters' service type
if rec.service_cat.service_type == 'natural_disasters':
if rec.requested_service_amount > rec.service_cat.natural_disasters_max_amount:
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _(
"You cannot request more than %s") % rec.service_cat.natural_disasters_max_amount}
return res
# Validation for 'family and member' benefit type with 'legal_arguments' service type
if rec.service_cat.service_type == 'legal_arguments':
if rec.requested_service_amount > rec.service_cat.legal_arguments_max_amount:
self.benefit_type = False
res['warning'] = {'title': _('ValidationError'),
'message': _(
"You cannot request more than %s") % rec.service_cat.legal_arguments_max_amount}
return res
@api.onchange('member_id')
def onchange_member_id(self):

View File

@ -59,10 +59,6 @@ class ServicesSettings(models.Model):
winter_clothing_member_amount = fields.Float(string="Winter clothing Member Amount")
#Ramadan Basket
ramadan_basket_member_amount = fields.Float(string='Ramadan Basket Member Amount')
#Natural disasters
natural_disasters_max_amount = fields.Float(string='Natural disasters Max Amount')
# Legal Arguments
legal_arguments_max_amount = fields.Float(string='Legal Arguments Max Amount')
#Buy Home
limit_person_line_ids = fields.One2many('service.limit.person.line', 'services_settings_id')
buy_home_max_total_amount = fields.Float(string='Buy Home Max Total Amount')

View File

@ -234,18 +234,6 @@
<field name="ramadan_basket_member_amount"/>
</group>
</page>
<page string="Natural disasters Settings"
attrs="{'invisible':[('service_type','!=','natural_disasters')]}">
<group>
<field name="natural_disasters_max_amount"/>
</group>
</page>
<page string="Legal arguments Settings"
attrs="{'invisible':[('service_type','!=','legal_arguments')]}">
<group>
<field name="legal_arguments_max_amount"/>
</group>
</page>
<page string="Amounts by Number of Persons"
attrs="{'invisible':['|',('service_type','!=','buy_home'),('max_limit_type', '!=', 'amount_person')]}">
<field name="limit_person_line_ids" widget="one2many_list">