diff --git a/odex25_ensan/odex_benefit/i18n/ar_001.po b/odex25_ensan/odex_benefit/i18n/ar_001.po index 71338a323..d5b3d80ed 100644 --- a/odex25_ensan/odex_benefit/i18n/ar_001.po +++ b/odex25_ensan/odex_benefit/i18n/ar_001.po @@ -2375,6 +2375,7 @@ msgstr "التدريب" #: model:ir.model.fields,field_description:odex_benefit.field_benefit_followers__follower_type #: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__benefit_type #: model:ir.model.fields,field_description:odex_benefit.field_service_request__benefit_type +#: model:ir.model.fields,field_description:odex_benefit.field_services_settings__benefit_type msgid "Benefit Type" msgstr "نوع المستفيدين" @@ -4905,6 +4906,7 @@ msgstr "استثنائية" #. module: odex_benefit #: model:ir.model.fields.selection,name:odex_benefit.selection__grant_benefit__action_type__exception #: model:ir.model.fields.selection,name:odex_benefit.selection__family_member__action_type__exception +#: model:ir.model.fields,field_description:odex_benefit.field_service_request__exception msgid "Exception" msgstr "استثناء" @@ -4912,6 +4914,7 @@ msgstr "استثناء" #: model:ir.model.fields,field_description:odex_benefit.field_exception_wizard__exception_attachment #: model:ir.model.fields,field_description:odex_benefit.field_family_member__exception_attachment #: model:ir.model.fields,field_description:odex_benefit.field_grant_benefit__exception_attachment +#: model:ir.model.fields,field_description:odex_benefit.field_service_request__exception_attach msgid "Exception Attachment" msgstr "مرفق الاستثناء" @@ -5137,6 +5140,7 @@ msgstr "الاسر المستفيدة" #: model:ir.model.fields,field_description:odex_benefit.field_service_request__family_id #: model:ir.model.fields,field_description:odex_benefit.field_visit_location__family_id #: model:ir.model.fields,field_description:odex_benefit.field_zkat_line__family_id +#: model:ir.model.fields.selection,name:odex_benefit.selection__services_settings__benefit_type__family #: model:ir.model.fields.selection,name:odex_benefit.selection__generate_reports__service_to__family #: model:ir.model.fields.selection,name:odex_benefit.selection__service_request__benefit_type__family #: model:ir.model.fields.selection,name:odex_benefit.selection__visit_location__benefit_type__family @@ -7951,6 +7955,7 @@ msgstr "الاجتماعات" #: model:ir.model.fields,field_description:odex_benefit.field_service_request__member_id #: model:ir.model.fields,field_description:odex_benefit.field_suspend_reason_wizard__member_id #: model:ir.model.fields.selection,name:odex_benefit.selection__service_request__benefit_type__member +#: model:ir.model.fields.selection,name:odex_benefit.selection__services_settings__benefit_type__member msgid "Member" msgstr "الفرد" @@ -15716,11 +15721,7 @@ msgid "Maximum Age" msgstr "الأقصى للعمر" #. module: odex_benefit -#: model:ir.model.fields,field_description:odex_benefit.field_services_settings__service_description -msgid "Service Description" -msgstr "وصف الخدمة" - -#. module: odex_benefit +#: model:ir.model.fields,field_description:odex_benefit.field_service_request__service_conditions #: model:ir.model.fields,field_description:odex_benefit.field_services_settings__service_conditions msgid "Service Conditions" msgstr "شروط الخدمة" @@ -15735,11 +15736,6 @@ msgstr "الإعدادات" msgid "Accounts" msgstr "الحسابات" -#. module: odex_benefit -#: model_terms:ir.ui.view,arch_db:odex_benefit.services_settings_form -msgid "Description and Details" -msgstr "الوصف والتفاصيل" - #. module: odex_benefit #: model:ir.model.fields,field_description:odex_benefit.field_services_settings__allowed_recurrence msgid "Allowed Recurrence" @@ -15893,6 +15889,7 @@ msgstr "متزوجة" #. module: odex_benefit #: code:addons/odex_benefit/models/family_members.py:0 +#: code:addons/odex_benefit/models/family_members.py:0 #, python-format msgid "She is employed and not enrolled in an educational institution." msgstr "تعمل وغير منتظمة بجهة تعلمية" @@ -15934,4 +15931,10 @@ msgstr "لاتقييم مع الاسرة" msgid "" "Application rejected due to missing documents, missing official proofs, or " "the family's ineligibility for the association's services." -msgstr "عدم استكمال المستندات المطاوبة او الاثباتات الرسمية او عدم استحقاق الاسرة لخدمات الجمعية وتم رفض الطلب" \ No newline at end of file +msgstr "عدم استكمال المستندات المطاوبة او الاثباتات الرسمية او عدم استحقاق الاسرة لخدمات الجمعية وتم رفض الطلب" + +#. module: odex_benefit +#: model_terms:ir.ui.view,arch_db:odex_benefit.service_request_form +#: model_terms:ir.ui.view,arch_db:odex_benefit.services_settings_form +msgid "Eligibility Criteria" +msgstr "شروط الاستحقاق" \ No newline at end of file diff --git a/odex25_ensan/odex_benefit/models/service_request.py b/odex25_ensan/odex_benefit/models/service_request.py index 1591c5dbc..8f6ea8b19 100644 --- a/odex25_ensan/odex_benefit/models/service_request.py +++ b/odex25_ensan/odex_benefit/models/service_request.py @@ -169,15 +169,22 @@ class ServiceRequest(models.Model): ('send_request_to_supplier', 'Send Request To Supplier'), ('family_received_device', 'Family Received Device'), ('refused', 'Refused') - ], string='state',default='draft', tracking=True) + ], string='state',default='draft', tracking=True, group_expand='_expand_states') state_a = fields.Selection(related='state', tracking=False) state_b = fields.Selection(related='state', tracking=False) refuse_reason_id = fields.Many2one('service.refuse.reason', string="Refuse Reason") return_reason = fields.Text(string="Reason for Returning the Request") specialist_note = fields.Text(string="Specialist's Note After Return") + exception = fields.Boolean(string='Exception',default=False) + exception_attach = fields.Many2many('ir.attachment', 'rel_exception_attachment_service_request', 'service_request_id', + 'attachment_id', string='Exception Attachment') + service_conditions = fields.Html(related='service_cat.service_conditions', string="Service Conditions") + def _expand_states(self, states, domain, order): + return [key for key, val in type(self).state.selection] + @api.depends('service_cat', 'service_reason_id') def _compute_account_id(self): for rec in self: @@ -576,342 +583,343 @@ class ServiceRequest(models.Model): date_before_ten_years = today - timedelta(days=3650) date_before_month = today - timedelta(days=30) for rec in self: - # Validation for 'member' benefit type - if rec.benefit_type == 'member' and rec.service_cat.service_type == 'rent': - max_requested_amount = rec.service_cat.max_amount_for_student - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _("You cannot request more than %s") % max_requested_amount} - return res + if not rec.exception and not rec.exception_attach: + # Validation for 'member' benefit type + if rec.benefit_type == 'member' and rec.service_cat.service_type == 'rent': + max_requested_amount = rec.service_cat.max_amount_for_student + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + 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(lambda r: r.benefit_category_id.id == rec.family_category.id \ - and r.benefit_count == rec.benefit_member_count - ) - max_requested_amount = rent_line_id.estimated_rent_branches if rec.branch_custom_id.branch_type == 'branches' else rent_line_id.estimated_rent_governorate - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - 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(lambda r: r.benefit_category_id.id == rec.family_category.id \ + and r.benefit_count == rec.benefit_member_count + ) + max_requested_amount = rent_line_id.estimated_rent_branches if rec.branch_custom_id.branch_type == 'branches' else rent_line_id.estimated_rent_governorate + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % max_requested_amount} + return res - # Validation for 'family and member' benefit type with 'home_maintenance' - if rec.service_cat.service_type == 'home_maintenance': - max_requested_amount = rec.service_cat.max_maintenance_amount - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _("You cannot request more than %s") % max_requested_amount} - return res + # Validation for 'family and member' benefit type with 'home_maintenance' + if rec.service_cat.service_type == 'home_maintenance': + max_requested_amount = rec.service_cat.max_maintenance_amount + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % max_requested_amount} + return res - # Prevent multiple 'home_maintenance' requests within the same year - existing_request_maintenance = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_maintenance: - raise UserError(_("You cannot request this service more than once a year.")) - existing_request_restoration = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_restoration: - raise UserError(_("You cannot request this service with restoration service in the same year.")) - # Validation for 'family' benefit type with 'home_restoration' - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration': - # Prevent multiple 'home_maintenance' requests within the same year - existing_request_restoration = self.search([ - ('date', '>', date_before_ten_years), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_restoration: - raise UserError(_("You cannot request this service more than once a ten years.")) - existing_request_maintenance = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_maintenance') - ], limit=1) - if existing_request_maintenance: - raise UserError( - _("You cannot request this service with maintenance service in the same year.")) - if rec.has_money_to_pay_first_payment == 'no': - home_restoration_line_id = rec.service_cat.home_restoration_lines.filtered(lambda r: r.benefit_category_id.id == rec.family_category.id) - if rec.requested_service_amount > home_restoration_line_id.max_amount: + # Prevent multiple 'home_maintenance' requests within the same year + existing_request_maintenance = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_maintenance: + raise UserError(_("You cannot request this service more than once a year.")) + existing_request_restoration = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_restoration: + raise UserError(_("You cannot request this service with restoration service in the same year.")) + # Validation for 'family' benefit type with 'home_restoration' + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration': + # Prevent multiple 'home_maintenance' requests within the same year + existing_request_restoration = self.search([ + ('date', '>', date_before_ten_years), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_restoration: + raise UserError(_("You cannot request this service more than once a ten years.")) + existing_request_maintenance = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_maintenance') + ], limit=1) + if existing_request_maintenance: raise UserError( - _("You cannot request more than %s") % home_restoration_line_id.max_amount - ) + _("You cannot request this service with maintenance service in the same year.")) + if rec.has_money_to_pay_first_payment == 'no': + home_restoration_line_id = rec.service_cat.home_restoration_lines.filtered(lambda r: r.benefit_category_id.id == rec.family_category.id) + if rec.requested_service_amount > home_restoration_line_id.max_amount: + raise UserError( + _("You cannot request more than %s") % home_restoration_line_id.max_amount + ) - # Validation for 'family' benefit type with 'complete_building_house' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house': - # Check for existing request of the same type - existing_request = self.search([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'complete_building_house'), - ], limit=1) - if existing_request: - raise UserError( - _("You Cannot request this service twice")) - existing_request_restoration = self.search([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), - ], limit=1) - if existing_request_restoration: - raise UserError( - _("You Cannot request this service and home restoration twice")) - # Validation for 'family' benefit type with 'electrical_devices' service type - 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([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'electrical_devices'), - ('date', '>', date_before_seven_years), - ('device_id', '=', rec.device_id.id) - ], limit=1) - if existing_request and not rec.exception_or_steal: - raise UserError( - _("You Cannot request this service twice in seven years")) - # Validation for 'family' benefit type with 'home_furnishing' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_furnishing': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'home_furnishing'), - ('date', '>', date_before_three_years), - ('id', '!=', self._origin.id), - ] - # if self.id: - # domain.append(('id', '!=', self.id)) # Exclude current record if already saved + # Validation for 'family' benefit type with 'complete_building_house' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house': + # Check for existing request of the same type + existing_request = self.search([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'complete_building_house'), + ], limit=1) + if existing_request: + raise UserError( + _("You Cannot request this service twice")) + existing_request_restoration = self.search([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), + ], limit=1) + if existing_request_restoration: + raise UserError( + _("You Cannot request this service and home restoration twice")) + # Validation for 'family' benefit type with 'electrical_devices' service type + 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([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'electrical_devices'), + ('date', '>', date_before_seven_years), + ('device_id', '=', rec.device_id.id) + ], limit=1) + if existing_request and not rec.exception_or_steal: + raise UserError( + _("You Cannot request this service twice in seven years")) + # Validation for 'family' benefit type with 'home_furnishing' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_furnishing': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'home_furnishing'), + ('date', '>', date_before_three_years), + ('id', '!=', self._origin.id), + ] + # if self.id: + # domain.append(('id', '!=', self.id)) # Exclude current record if already saved - # Search for existing requests - existing_requests_within_three_years = self.search(domain) + # Search for existing requests + existing_requests_within_three_years = self.search(domain) - # Include current record in the calculation - total_amount_in_three_years = sum( - existing_requests_within_three_years.mapped('requested_service_amount')) - total_amount_in_three_years += sum(self.furnishing_items_ids.mapped('furnishing_cost')) - if not rec.home_furnishing_exception: - if total_amount_in_three_years > rec.service_cat.max_furnishing_amount: + # Include current record in the calculation + total_amount_in_three_years = sum( + existing_requests_within_three_years.mapped('requested_service_amount')) + total_amount_in_three_years += sum(self.furnishing_items_ids.mapped('furnishing_cost')) + if not rec.home_furnishing_exception: + if total_amount_in_three_years > rec.service_cat.max_furnishing_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount} + return res + if rec.home_furnishing_exception: + if total_amount_in_three_years > rec.service_cat.max_furnishing_amount_if_exception: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount_if_exception} + return res + # Validation for 'family' benefit type with 'electricity_bill' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'electricity_bill': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'electricity_bill'), + ('date', '>', date_before_month) + ] + # Search for existing requests + existing_requests_within_month = self.search(domain) + if existing_requests_within_month: + raise UserError(_("You cannot request this service agin in this month")) + if rec.requested_service_amount > rec.max_electricity_bill_amount: self.benefit_type = False res['warning'] = {'title': _('ValidationError'), 'message': _( - "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount} + "You cannot request more than %s") % rec.max_electricity_bill_amount} return res - if rec.home_furnishing_exception: - if total_amount_in_three_years > rec.service_cat.max_furnishing_amount_if_exception: + # Validation for 'family' benefit type with 'water_bill' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'water_bill': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'water_bill'), + ('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 agin in this year")) + if rec.requested_service_amount > rec.max_water_bill_amount: self.benefit_type = False res['warning'] = {'title': _('ValidationError'), 'message': _( - "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount_if_exception} + "You cannot request more than %s") % rec.max_water_bill_amount} return res - # Validation for 'family' benefit type with 'electricity_bill' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'electricity_bill': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'electricity_bill'), - ('date', '>', date_before_month) - ] - # Search for existing requests - existing_requests_within_month = self.search(domain) - if existing_requests_within_month: - raise UserError(_("You cannot request this service agin in this month")) - if rec.requested_service_amount > rec.max_electricity_bill_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_electricity_bill_amount} - return res - # Validation for 'family' benefit type with 'water_bill' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'water_bill': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'water_bill'), - ('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 agin in this year")) - if rec.requested_service_amount > rec.max_water_bill_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_water_bill_amount} - return res - # Validation for 'family' benefit type with 'buy_car' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_car': - if rec.family_id.has_car: - raise UserError(_("You cannot request this service because you had a car")) - if rec.benefit_member_count < rec.service_cat.min_count_member: - raise UserError( - _("You cannot request this service because you are less than %s") % rec.service_cat.min_count_member) - if rec.requested_service_amount > rec.service_cat.max_buy_car_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_buy_car_amount} - return res - # Validation for 'family' benefit type with 'recruiting_driver' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'recruiting_driver': - recruiting_driver_existing_request = self.search([ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'recruiting_driver'), ('id', '!=', self._origin.id)], - limit=1) - son_members_above_age = rec.family_id.mapped('member_ids').filtered( - lambda x: x.relationn.relation_type == 'son' and x.age > 18) - daughter_members_above_age = rec.family_id.mapped('member_ids').filtered( - lambda x: x.relationn.relation_type == 'daughter' and x.age > 18) - disable_mother = rec.family_id.mapped('member_ids').filtered( - lambda x: x.relationn.relation_type == 'mother') - work_mother = rec.family_id.mapped('member_ids').filtered( - lambda x: x.relationn.relation_type == 'mother' and x.benefit.is_mother_work) - disable_replacement_mother = rec.family_id.mapped('member_ids').filtered( - lambda x: x.relationn.relation_type == 'replacement_mother') - work_replacement_mother = rec.family_id.mapped('member_ids').filtered(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")) - if son_members_above_age or daughter_members_above_age: - raise UserError( - _("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( - _("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( - _("You cannot request this service because mother should be worked or has disability")) - if recruiting_driver_existing_request: - raise UserError( - _("You cannot request this service Again")) - if rec.requested_service_amount > rec.service_cat.max_recruiting_driver_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_recruiting_driver_amount} - 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_id and rec.requested_service_amount > rec.max_amount: + # Validation for 'family' benefit type with 'buy_car' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_car': + if rec.family_id.has_car: + raise UserError(_("You cannot request this service because you had a car")) + if rec.benefit_member_count < rec.service_cat.min_count_member: + raise UserError( + _("You cannot request this service because you are less than %s") % rec.service_cat.min_count_member) + if rec.requested_service_amount > rec.service_cat.max_buy_car_amount: self.benefit_type = False - res['warning'] = { - 'title': _('ValidationError'), - 'message': _("You cannot request more than %s") % rec.max_amount - } + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_buy_car_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: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_debits_amount} - return res - # 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) + # Validation for 'family' benefit type with 'recruiting_driver' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'recruiting_driver': + recruiting_driver_existing_request = self.search([ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'recruiting_driver'), ('id', '!=', self._origin.id)], + limit=1) + son_members_above_age = rec.family_id.mapped('member_ids').filtered( + lambda x: x.relationn.relation_type == 'son' and x.age > 18) + daughter_members_above_age = rec.family_id.mapped('member_ids').filtered( + lambda x: x.relationn.relation_type == 'daughter' and x.age > 18) + disable_mother = rec.family_id.mapped('member_ids').filtered( + lambda x: x.relationn.relation_type == 'mother') + work_mother = rec.family_id.mapped('member_ids').filtered( + lambda x: x.relationn.relation_type == 'mother' and x.benefit.is_mother_work) + disable_replacement_mother = rec.family_id.mapped('member_ids').filtered( + lambda x: x.relationn.relation_type == 'replacement_mother') + work_replacement_mother = rec.family_id.mapped('member_ids').filtered(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")) + if son_members_above_age or daughter_members_above_age: + raise UserError( + _("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( + _("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( + _("You cannot request this service because mother should be worked or has disability")) + if recruiting_driver_existing_request: + raise UserError( + _("You cannot request this service Again")) + if rec.requested_service_amount > rec.service_cat.max_recruiting_driver_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_recruiting_driver_amount} + 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_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: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_debits_amount} + return res + # 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 - if rec.benefit_type == 'member' and rec.service_cat.service_type == 'marriage': - if rec.member_age > rec.service_cat.member_max_age: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "Member Age should be less than %s ") % rec.service_cat.member_max_age} - return res - if rec.member_payroll > rec.service_cat.member_max_payroll: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "Member Payroll should be less than %s ") % rec.service_cat.member_max_payroll} - return res - if rec.has_marriage_course == 'no': - raise UserError(_("You Should take a course")) - # Validation for 'family' benefit type with 'eid_gift' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'eid_gift': - if rec.eid_gift_benefit_count == 0: - raise UserError(_("You cannot request this service")) - # 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 - # Validation for 'family' benefit type with 'buy_home' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_home': - # Search for existing requests - existing_buy_home_requests = self.search([('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'buy_home'), - ('id', '!=', self._origin.id)]) - existing_home_restoration_requests = self.search([('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', - 'home_restoration'), - ('id', '!=', self._origin.id)]) - if rec.requested_service_amount > rec.service_cat.buy_home_max_total_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.buy_home_max_total_amount} - return res - if existing_buy_home_requests: - raise UserError(_("You cannot request this service Again")) - if existing_home_restoration_requests: - raise UserError( - _("You cannot request this service Again Because you request Home restoration service")) - if rec.home_age > rec.service_cat.home_age: - raise UserError( - _("You cannot request this service Again Because the home Age More than %s") % rec.service_cat.home_age) + # 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 + if rec.benefit_type == 'member' and rec.service_cat.service_type == 'marriage': + if rec.member_age > rec.service_cat.member_max_age: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "Member Age should be less than %s ") % rec.service_cat.member_max_age} + return res + if rec.member_payroll > rec.service_cat.member_max_payroll: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "Member Payroll should be less than %s ") % rec.service_cat.member_max_payroll} + return res + if rec.has_marriage_course == 'no': + raise UserError(_("You Should take a course")) + # Validation for 'family' benefit type with 'eid_gift' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'eid_gift': + if rec.eid_gift_benefit_count == 0: + raise UserError(_("You cannot request this service")) + # 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 + # Validation for 'family' benefit type with 'buy_home' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_home': + # Search for existing requests + existing_buy_home_requests = self.search([('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'buy_home'), + ('id', '!=', self._origin.id)]) + existing_home_restoration_requests = self.search([('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', + 'home_restoration'), + ('id', '!=', self._origin.id)]) + if rec.requested_service_amount > rec.service_cat.buy_home_max_total_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.buy_home_max_total_amount} + return res + if existing_buy_home_requests: + raise UserError(_("You cannot request this service Again")) + if existing_home_restoration_requests: + raise UserError( + _("You cannot request this service Again Because you request Home restoration service")) + if rec.home_age > rec.service_cat.home_age: + raise UserError( + _("You cannot request this service Again Because the home Age More than %s") % rec.service_cat.home_age) @api.onchange('requested_quantity','benefit_type') @@ -952,16 +960,12 @@ class ServiceRequest(models.Model): # if self.service_cat: # self.service_cat = False - @api.depends('family_category', 'sub_service_category') + @api.depends('family_category') def _compute_available_service_cats(self): for rec in self: if rec.benefit_type: if rec.benefit_type == 'family': - domain = [ - ('is_main_service', '=', False), - ('service_type', '!=', False), - ('parent_service', '=', rec.sub_service_category.id) - ] + domain = [('service_type', '!=', 'main_service')] rec.available_service_cats = rec.available_service_cats.sudo().search(domain).filtered( lambda r: rec.family_category.id in r.benefit_category_ids.ids or\ (rec.family_category.id, rec.benefit_member_count) in r.rent_lines.mapped(lambda r: (r.benefit_category_id.id, r.benefit_count)) or\ @@ -971,9 +975,7 @@ class ServiceRequest(models.Model): ) elif rec.benefit_type == 'member': domain = [ - ('is_main_service', '=', False), - ('service_type', '!=', False), - ('parent_service', '=', rec.sub_service_category.id), + ('service_type', '!=', 'main_service'), ('is_this_service_for_student','=',True) ] rec.available_service_cats = rec.available_service_cats.sudo().search(domain).filtered( diff --git a/odex25_ensan/odex_benefit/models/services_settings.py b/odex25_ensan/odex_benefit/models/services_settings.py index d9bf995d3..b9ccfaed3 100644 --- a/odex25_ensan/odex_benefit/models/services_settings.py +++ b/odex25_ensan/odex_benefit/models/services_settings.py @@ -4,8 +4,10 @@ from odoo import fields, models, api, _ class ServicesSettings(models.Model): _name = 'services.settings' _rec_name = 'service_name' + _order = 'service_number' service_name = fields.Char(string='Service Name') + benefit_type = fields.Selection(string='Benefit Type', selection=[('family', 'Family'), ('member', 'Member')]) parent_service = fields.Many2one('services.settings',string='Parent Service') is_main_service = fields.Boolean(string='Is Main Service?') is_service_producer = fields.Boolean(string='Is Service Producer?') @@ -18,7 +20,7 @@ class ServicesSettings(models.Model): ('providing_medicines_medical_devices_and_needs_the_disabled','Providing Medicines Medical Devices And Needs The Disabled'), ('recruiting_domestic_worker_or_nurse','Recruiting a domestic worker or nurse') ,('marriage','Marriage'),('eid_gift','Eid gift'), ('winter_clothing','Winter clothing'),('ramadan_basket','Ramadan basket'),('natural_disasters','Natural disasters'), - ('legal_arguments','Legal arguments'),('buy_home','Buy Home')] + ('legal_arguments','Legal arguments'),('buy_home','Buy Home'),('main_service','Main Service')] ,string='Service Type') max_amount_for_student = fields.Float(string='Max Amount for Student') raise_amount_for_orphan = fields.Float(string='Raise Amount For Orphan') @@ -94,7 +96,7 @@ class ServicesSettings(models.Model): max_amount = fields.Monetary(string="Maximum Amount", currency_field='currency_id',copy=False) max_age = fields.Integer(string="Maximum Age",copy=False) service_description = fields.Text(string="Service Description") - service_conditions = fields.Text(string="Service Conditions") + service_conditions = fields.Html(string="Service Conditions") allowed_recurrence = fields.Selection([ ('once', 'Once'), ('periodic', 'Every Period'), diff --git a/odex25_ensan/odex_benefit/views/service_request.xml b/odex25_ensan/odex_benefit/views/service_request.xml index ef3423607..6bc868693 100644 --- a/odex25_ensan/odex_benefit/views/service_request.xml +++ b/odex25_ensan/odex_benefit/views/service_request.xml @@ -64,20 +64,20 @@ - - + + - + + + - - - - + + + + - + - - + + @@ -177,34 +179,34 @@ - + - + - + - + - + @@ -212,7 +214,7 @@ - + @@ -228,19 +230,24 @@ - + - + + + + + +
@@ -262,11 +269,12 @@ - - + + - - + + + @@ -320,7 +328,8 @@ - + + diff --git a/odex25_ensan/odex_benefit/views/services_settings.xml b/odex25_ensan/odex_benefit/views/services_settings.xml index 16cc83328..7fad0abcf 100644 --- a/odex25_ensan/odex_benefit/views/services_settings.xml +++ b/odex25_ensan/odex_benefit/views/services_settings.xml @@ -14,7 +14,8 @@ - + + @@ -76,10 +77,7 @@ - - - - + @@ -322,12 +320,11 @@ services.settings + + - - - - + diff --git a/odex25_ensan/odex_benefit_project/models/service_request.py b/odex25_ensan/odex_benefit_project/models/service_request.py index 753dd86c5..dcd382c5d 100644 --- a/odex25_ensan/odex_benefit_project/models/service_request.py +++ b/odex25_ensan/odex_benefit_project/models/service_request.py @@ -54,354 +54,355 @@ class ServiceRequestInherit(models.Model): date_before_ten_years = today - timedelta(days=3650) date_before_month = today - timedelta(days=30) for rec in self: - # Validation for 'member' benefit type - if rec.benefit_type == 'member' and rec.service_cat.service_type == 'rent': - max_requested_amount = rec.service_cat.max_amount_for_student - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - 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(lambda r: r.benefit_category_id.id == rec.family_category.id \ - and r.benefit_count == rec.benefit_member_count - ) - max_requested_amount = rent_line_id.estimated_rent_branches if rec.branch_custom_id.branch_type == 'branches' else rent_line_id.estimated_rent_governorate - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _("You cannot request more than %s") % max_requested_amount} - return res + if not rec.exception and not rec.exception_attach: + # Validation for 'member' benefit type + if rec.benefit_type == 'member' and rec.service_cat.service_type == 'rent': + max_requested_amount = rec.service_cat.max_amount_for_student + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % max_requested_amount} + return res - # Validation for 'family and member' benefit type with 'home_maintenance' - if rec.service_cat.service_type == 'home_maintenance': - max_requested_amount = rec.service_cat.max_maintenance_amount - if rec.requested_service_amount > max_requested_amount: - self.benefit_type = False - 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(lambda r: r.benefit_category_id.id == rec.family_category.id \ + and r.benefit_count == rec.benefit_member_count + ) + max_requested_amount = rent_line_id.estimated_rent_branches if rec.branch_custom_id.branch_type == 'branches' else rent_line_id.estimated_rent_governorate + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % max_requested_amount} + return res - # Prevent multiple 'home_maintenance' requests within the same year - existing_request_maintenance = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_maintenance: - raise UserError(_("You cannot request this service more than once a year.")) - existing_request_restoration = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_restoration: - raise UserError( - _("You cannot request this service with restoration service in the same year.")) - # Validation for 'family' benefit type with 'home_restoration' - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration': - # Prevent multiple 'home_maintenance' requests within the same year - existing_request_restoration = self.search([ - ('date', '>', date_before_ten_years), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) - ], limit=1) - if existing_request_restoration: - raise UserError(_("You cannot request this service more than once a ten years.")) - existing_request_maintenance = self.search([ - ('date', '>', date_before_year), - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_maintenance') - ], limit=1) - if existing_request_maintenance: - raise UserError( - _("You cannot request this service with maintenance service in the same year.")) - if rec.has_money_to_pay_first_payment == 'no': - home_restoration_line_id = rec.service_cat.home_restoration_lines.filtered(lambda r: r.benefit_category_id.id == rec.family_category.id) - if rec.requested_service_amount > home_restoration_line_id.max_amount: + # Validation for 'family and member' benefit type with 'home_maintenance' + if rec.service_cat.service_type == 'home_maintenance': + max_requested_amount = rec.service_cat.max_maintenance_amount + if rec.requested_service_amount > max_requested_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _("You cannot request more than %s") % max_requested_amount} + return res + + # Prevent multiple 'home_maintenance' requests within the same year + existing_request_maintenance = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_maintenance'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_maintenance: + raise UserError(_("You cannot request this service more than once a year.")) + existing_request_restoration = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_restoration: raise UserError( - _("You cannot request more than %s") % home_restoration_line_id.max_amount - ) + _("You cannot request this service with restoration service in the same year.")) + # Validation for 'family' benefit type with 'home_restoration' + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_restoration': + # Prevent multiple 'home_maintenance' requests within the same year + existing_request_restoration = self.search([ + ('date', '>', date_before_ten_years), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), ('id', '!=', self._origin.id) + ], limit=1) + if existing_request_restoration: + raise UserError(_("You cannot request this service more than once a ten years.")) + existing_request_maintenance = self.search([ + ('date', '>', date_before_year), + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_maintenance') + ], limit=1) + if existing_request_maintenance: + raise UserError( + _("You cannot request this service with maintenance service in the same year.")) + if rec.has_money_to_pay_first_payment == 'no': + home_restoration_line_id = rec.service_cat.home_restoration_lines.filtered(lambda r: r.benefit_category_id.id == rec.family_category.id) + if rec.requested_service_amount > home_restoration_line_id.max_amount: + raise UserError( + _("You cannot request more than %s") % home_restoration_line_id.max_amount + ) - # Validation for 'family' benefit type with 'complete_building_house' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house': - # Check for existing request of the same type - existing_request = self.search([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'complete_building_house'), - ], limit=1) - if existing_request: - raise UserError( - _("You Cannot request this service twice")) - existing_request_restoration = self.search([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), - ], limit=1) - if existing_request_restoration: - raise UserError( - _("You Cannot request this service and home restoration twice")) - # Validation for 'family' benefit type with 'electrical_devices' service type - 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([ - ('family_id', '=', rec.family_id.id), - ('service_cat.service_type', '=', 'electrical_devices'), - ('date', '>', date_before_seven_years),('device_id','=',rec.device_id.id) - ], limit=1) - if existing_request and not rec.exception_or_steal: - raise UserError( - _("You Cannot request this service twice in seven years")) - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'alternative_housing' and not rec.providing_alternative_housing_based_rent: - if rec.requested_service_amount > rec.service_cat.rent_amount_for_alternative_housing: - raise UserError( - _("You Cannot request amount more than %s") % rec.service_cat.rent_amount_for_alternative_housing) - 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' benefit type with 'complete_building_house' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'complete_building_house': + # Check for existing request of the same type + existing_request = self.search([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'complete_building_house'), + ], limit=1) + if existing_request: + raise UserError( + _("You Cannot request this service twice")) + existing_request_restoration = self.search([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), + ], limit=1) + if existing_request_restoration: + raise UserError( + _("You Cannot request this service and home restoration twice")) + # Validation for 'family' benefit type with 'electrical_devices' service type + 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([ + ('family_id', '=', rec.family_id.id), + ('service_cat.service_type', '=', 'electrical_devices'), + ('date', '>', date_before_seven_years),('device_id','=',rec.device_id.id) + ], limit=1) + if existing_request and not rec.exception_or_steal: + raise UserError( + _("You Cannot request this service twice in seven years")) + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'alternative_housing' and not rec.providing_alternative_housing_based_rent: + if rec.requested_service_amount > rec.service_cat.rent_amount_for_alternative_housing: + raise UserError( + _("You Cannot request amount more than %s") % rec.service_cat.rent_amount_for_alternative_housing) + 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' benefit type with 'home_furnishing' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_furnishing': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'home_furnishing'), - ('date', '>', date_before_three_years), - ('id', '!=', self._origin.id), - ] - # if self.id: - # domain.append(('id', '!=', self.id)) # Exclude current record if already saved + # Validation for 'family' benefit type with 'home_furnishing' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'home_furnishing': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'home_furnishing'), + ('date', '>', date_before_three_years), + ('id', '!=', self._origin.id), + ] + # if self.id: + # domain.append(('id', '!=', self.id)) # Exclude current record if already saved - # Search for existing requests - existing_requests_within_three_years = self.search(domain) + # Search for existing requests + existing_requests_within_three_years = self.search(domain) - # Include current record in the calculation - total_amount_in_three_years = sum(existing_requests_within_three_years.mapped('requested_service_amount')) - total_amount_in_three_years += sum(self.furnishing_items_ids.mapped('furnishing_cost')) - if not rec.home_furnishing_exception: - if total_amount_in_three_years > rec.service_cat.max_furnishing_amount: + # Include current record in the calculation + total_amount_in_three_years = sum(existing_requests_within_three_years.mapped('requested_service_amount')) + total_amount_in_three_years += sum(self.furnishing_items_ids.mapped('furnishing_cost')) + if not rec.home_furnishing_exception: + if total_amount_in_three_years > rec.service_cat.max_furnishing_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount} + return res + if rec.home_furnishing_exception: + if total_amount_in_three_years > rec.service_cat.max_furnishing_amount_if_exception: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount_if_exception} + return res + # Validation for 'family' benefit type with 'electricity_bill' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'electricity_bill': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'electricity_bill'), + ('date', '>', date_before_month),('id', '!=', self._origin.id) + ] + # Search for existing requests + existing_requests_within_month = self.search(domain) + if existing_requests_within_month: + raise UserError(_("You cannot request this service agin in this month")) + if rec.requested_service_amount > rec.max_electricity_bill_amount: self.benefit_type = False res['warning'] = {'title': _('ValidationError'), 'message': _( - "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount} + "You cannot request more than %s") % rec.max_electricity_bill_amount} return res - if rec.home_furnishing_exception: - if total_amount_in_three_years > rec.service_cat.max_furnishing_amount_if_exception: + # Validation for 'family' benefit type with 'water_bill' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'water_bill': + # Add current record conditionally + domain = [ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'water_bill'), + ('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 agin in this year")) + if rec.requested_service_amount > rec.max_water_bill_amount: self.benefit_type = False res['warning'] = {'title': _('ValidationError'), 'message': _( - "You cannot request more than %s within 3 years") % rec.service_cat.max_furnishing_amount_if_exception} + "You cannot request more than %s") % rec.max_water_bill_amount} return res - # Validation for 'family' benefit type with 'electricity_bill' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'electricity_bill': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'electricity_bill'), - ('date', '>', date_before_month),('id', '!=', self._origin.id) - ] - # Search for existing requests - existing_requests_within_month = self.search(domain) - if existing_requests_within_month: - raise UserError(_("You cannot request this service agin in this month")) - if rec.requested_service_amount > rec.max_electricity_bill_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_electricity_bill_amount} - return res - # Validation for 'family' benefit type with 'water_bill' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'water_bill': - # Add current record conditionally - domain = [ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'water_bill'), - ('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 agin in this year")) - if rec.requested_service_amount > rec.max_water_bill_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.max_water_bill_amount} - return res - # Validation for 'family' benefit type with 'buy_car' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_car': - if rec.family_id.has_car: - raise UserError(_("You cannot request this service because you had a car")) - if rec.benefit_member_count < rec.service_cat.min_count_member: - raise UserError(_("You cannot request this service because you are less than %s")%rec.service_cat.min_count_member) - if rec.requested_service_amount > rec.service_cat.max_buy_car_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_buy_car_amount} - return res - # Validation for 'family' benefit type with 'recruiting_driver' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'recruiting_driver': - recruiting_driver_existing_request = self.search([ - ('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'recruiting_driver'), ('id', '!=', self._origin.id)], limit=1) - son_members_above_age = rec.family_id.mapped('member_ids').filtered(lambda x:x.relationn.relation_type == 'son' and x.age > 18) - daughter_members_above_age = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'daughter' and x.age > 18) - disable_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'mother') - work_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'mother' and x.benefit_id.is_mother_work) - disable_replacement_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'replacement_mother') - work_replacement_mother = rec.family_id.mapped('member_ids').filtered(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")) - if son_members_above_age or daughter_members_above_age: - raise UserError( - _("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( - _("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( - _("You cannot request this service because mother should be worked or has disability")) - if recruiting_driver_existing_request: - raise UserError( - _("You cannot request this service Again")) - if rec.requested_service_amount > rec.service_cat.max_recruiting_driver_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_recruiting_driver_amount} - 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_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: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.max_debits_amount} - return res - # 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) + # Validation for 'family' benefit type with 'buy_car' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_car': + if rec.family_id.has_car: + raise UserError(_("You cannot request this service because you had a car")) + if rec.benefit_member_count < rec.service_cat.min_count_member: + raise UserError(_("You cannot request this service because you are less than %s")%rec.service_cat.min_count_member) + if rec.requested_service_amount > rec.service_cat.max_buy_car_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_buy_car_amount} + return res + # Validation for 'family' benefit type with 'recruiting_driver' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'recruiting_driver': + recruiting_driver_existing_request = self.search([ + ('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'recruiting_driver'), ('id', '!=', self._origin.id)], limit=1) + son_members_above_age = rec.family_id.mapped('member_ids').filtered(lambda x:x.relationn.relation_type == 'son' and x.age > 18) + daughter_members_above_age = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'daughter' and x.age > 18) + disable_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'mother') + work_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'mother' and x.benefit_id.is_mother_work) + disable_replacement_mother = rec.family_id.mapped('member_ids').filtered(lambda x: x.relationn.relation_type == 'replacement_mother') + work_replacement_mother = rec.family_id.mapped('member_ids').filtered(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")) + if son_members_above_age or daughter_members_above_age: + raise UserError( + _("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( + _("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( + _("You cannot request this service because mother should be worked or has disability")) + if recruiting_driver_existing_request: + raise UserError( + _("You cannot request this service Again")) + if rec.requested_service_amount > rec.service_cat.max_recruiting_driver_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_recruiting_driver_amount} + 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_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: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.max_debits_amount} + return res + # 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: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "Member Age should be less than %s ") % rec.service_cat.member_max_age} - return res - if rec.member_payroll > rec.service_cat.member_max_payroll: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "Member Payroll should be less than %s ") % rec.service_cat.member_max_payroll} - return res - if not rec.family_id.mother_marital_conf.is_dead and rec.requested_service_amount > rec.service_cat.fatherless_member_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s ") % rec.service_cat.fatherless_member_amount} - return res - if rec.family_id.mother_marital_conf.is_dead and rec.requested_service_amount > rec.service_cat.orphan_member_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s ") % rec.service_cat.orphan_member_amount} - return res - if rec.has_marriage_course == 'no': - raise UserError(_("You Should take a course")) - # Validation for 'family' benefit type with 'eid_gift' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'eid_gift': - if rec.eid_gift_benefit_count == 0: - raise UserError(_("You cannot request this service because family should have members his age less than %s")%rec.service_cat.eid_gift_max_age) - # Validation for 'member' benefit type with 'eid_gift' service type - if rec.benefit_type == 'member' and rec.service_cat.service_type == 'eid_gift': - 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 - # Validation for 'family' benefit type with 'buy_home' service type - if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_home': - # Search for existing requests - existing_buy_home_requests = self.search([('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=','buy_home'), - ('id', '!=', self._origin.id)]) - existing_home_restoration_requests = self.search([('family_id', '=', self.family_id.id), - ('service_cat.service_type', '=', 'home_restoration'), - ('id', '!=', self._origin.id)]) - if rec.requested_service_amount > rec.service_cat.buy_home_max_total_amount: - self.benefit_type = False - res['warning'] = {'title': _('ValidationError'), - 'message': _( - "You cannot request more than %s") % rec.service_cat.buy_home_max_total_amount} - return res - if existing_buy_home_requests: - raise UserError(_("You cannot request this service Again")) - if existing_home_restoration_requests: - raise UserError(_("You cannot request this service Again Because you request Home restoration service")) - if rec.home_age > rec.service_cat.home_age: - raise UserError( - _("You cannot request this service Again Because the home Age More than %s") % rec.service_cat.home_age) + # 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: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "Member Age should be less than %s ") % rec.service_cat.member_max_age} + return res + if rec.member_payroll > rec.service_cat.member_max_payroll: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "Member Payroll should be less than %s ") % rec.service_cat.member_max_payroll} + return res + if not rec.family_id.mother_marital_conf.is_dead and rec.requested_service_amount > rec.service_cat.fatherless_member_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s ") % rec.service_cat.fatherless_member_amount} + return res + if rec.family_id.mother_marital_conf.is_dead and rec.requested_service_amount > rec.service_cat.orphan_member_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s ") % rec.service_cat.orphan_member_amount} + return res + if rec.has_marriage_course == 'no': + raise UserError(_("You Should take a course")) + # Validation for 'family' benefit type with 'eid_gift' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'eid_gift': + if rec.eid_gift_benefit_count == 0: + raise UserError(_("You cannot request this service because family should have members his age less than %s")%rec.service_cat.eid_gift_max_age) + # Validation for 'member' benefit type with 'eid_gift' service type + if rec.benefit_type == 'member' and rec.service_cat.service_type == 'eid_gift': + 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 + # Validation for 'family' benefit type with 'buy_home' service type + if rec.benefit_type == 'family' and rec.service_cat.service_type == 'buy_home': + # Search for existing requests + existing_buy_home_requests = self.search([('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=','buy_home'), + ('id', '!=', self._origin.id)]) + existing_home_restoration_requests = self.search([('family_id', '=', self.family_id.id), + ('service_cat.service_type', '=', 'home_restoration'), + ('id', '!=', self._origin.id)]) + if rec.requested_service_amount > rec.service_cat.buy_home_max_total_amount: + self.benefit_type = False + res['warning'] = {'title': _('ValidationError'), + 'message': _( + "You cannot request more than %s") % rec.service_cat.buy_home_max_total_amount} + return res + if existing_buy_home_requests: + raise UserError(_("You cannot request this service Again")) + if existing_home_restoration_requests: + raise UserError(_("You cannot request this service Again Because you request Home restoration service")) + if rec.home_age > rec.service_cat.home_age: + raise UserError( + _("You cannot request this service Again Because the home Age More than %s") % rec.service_cat.home_age) diff --git a/odex25_ensan/odex_benefit_project/views/services_settings_inherit.xml b/odex25_ensan/odex_benefit_project/views/services_settings_inherit.xml index d1f7f728a..eebfbf435 100644 --- a/odex25_ensan/odex_benefit_project/views/services_settings_inherit.xml +++ b/odex25_ensan/odex_benefit_project/views/services_settings_inherit.xml @@ -6,11 +6,9 @@ services.settings - - - - + +