diff --git a/odex25_takaful/odex_takaful/__manifest__.py b/odex25_takaful/odex_takaful/__manifest__.py index 22e603889..281635cae 100644 --- a/odex25_takaful/odex_takaful/__manifest__.py +++ b/odex25_takaful/odex_takaful/__manifest__.py @@ -83,6 +83,7 @@ 'views/product_views.xml', 'views/payment_machine_views.xml', 'views/takaful_menus_actions.xml', + 'views/benefit_category_views.xml', 'data/message_template_data.xml', 'wizards/transfer_deduction_wizard_views.xml', diff --git a/odex25_takaful/odex_takaful/data/scheduled_actions.xml b/odex25_takaful/odex_takaful/data/scheduled_actions.xml index c5397eb9d..55b503f19 100644 --- a/odex25_takaful/odex_takaful/data/scheduled_actions.xml +++ b/odex25_takaful/odex_takaful/data/scheduled_actions.xml @@ -81,6 +81,22 @@ + + + Process Closing Active Sponsorships + + 1 + days + + -1 + + + code + model.cron_process_closing_ended_sponsorships() + + + + Family Member Restriction diff --git a/odex25_takaful/odex_takaful/models/__init__.py b/odex25_takaful/odex_takaful/models/__init__.py index 0efc0b126..b1d92c5ba 100644 --- a/odex25_takaful/odex_takaful/models/__init__.py +++ b/odex25_takaful/odex_takaful/models/__init__.py @@ -29,3 +29,5 @@ from . import family_member from . import sponsorship_scheduling_line from . import donation_replacement_log from . import payment_machine + +from . import benefit_category diff --git a/odex25_takaful/odex_takaful/models/benefit_category.py b/odex25_takaful/odex_takaful/models/benefit_category.py new file mode 100644 index 000000000..4a6683996 --- /dev/null +++ b/odex25_takaful/odex_takaful/models/benefit_category.py @@ -0,0 +1,7 @@ +from odoo import models, fields + + +class BenefitCategory(models.Model): + _inherit = 'benefit.category' + + allowed_sponsorship = fields.Boolean() \ No newline at end of file diff --git a/odex25_takaful/odex_takaful/models/donation_details_lines.py b/odex25_takaful/odex_takaful/models/donation_details_lines.py index 163a4849c..5470b60ca 100644 --- a/odex25_takaful/odex_takaful/models/donation_details_lines.py +++ b/odex25_takaful/odex_takaful/models/donation_details_lines.py @@ -352,11 +352,10 @@ class DonationsDetailsLines(models.Model): for rec in self: show_extend_button = ( rec.record_type == 'sponsorship' and - rec.sponsorship_duration != "permanent" and + rec.sponsorship_duration == 'temporary' and rec.end_date and rec.end_date >= today and - rec.state == 'active' - and rec.sponsorship_id.state not in ['canceled' , 'closed'] + rec.state in ['active', 'replace'] ) rec.show_extend_button = show_extend_button @@ -1250,6 +1249,21 @@ class DonationsDetailsLines(models.Model): self.product_template_id._quantity = 0 return super().unlink() + @api.model + def cron_process_closing_ended_sponsorships(self): + records = self.search([ + 'record_type', '=', 'sponsorship', + 'sponsorship_duration', '=', 'temporary', + 'state', 'in', ['active', 'replace'], + 'end_date', '<', fields.Date.today() + ]) + + for record in records: + record.state = 'closed' + for benefit_id in record.benefit_ids: + benefit_id.kafala_status = 'have_not_kafala' + benefit_id.sponsor_related_id = False + @api.model def cron_send_direct_debit_end_date_reminders(self): """ diff --git a/odex25_takaful/odex_takaful/models/family_member.py b/odex25_takaful/odex_takaful/models/family_member.py index 1e68a9141..46a74537d 100644 --- a/odex25_takaful/odex_takaful/models/family_member.py +++ b/odex25_takaful/odex_takaful/models/family_member.py @@ -56,6 +56,8 @@ class FamilyMember(models.Model): compute='_compute_benefit_group', store=True ) + allowed_sponsorship = fields.Boolean(related='benefit_id.benefit_category_id.allowed_sponsorship') + def name_get(self): result = [] diff --git a/odex25_takaful/odex_takaful/views/benefit_category_views.xml b/odex25_takaful/odex_takaful/views/benefit_category_views.xml new file mode 100644 index 000000000..875dfbe81 --- /dev/null +++ b/odex25_takaful/odex_takaful/views/benefit_category_views.xml @@ -0,0 +1,30 @@ + + + + + benefit.category.view.form.inherit + benefit.category + + + + + + + + + + + + benefit.category.view.tree.inherit + benefit.category + + + + + + + + + + + diff --git a/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml b/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml index c17afbd8c..2047b280f 100644 --- a/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_takaful/odex_takaful/views/takaful_sponorship_view.xml @@ -676,7 +676,7 @@ - + diff --git a/odex25_takaful/odex_takaful/wizards/add_benefit_wizard.xml b/odex25_takaful/odex_takaful/wizards/add_benefit_wizard.xml index 1f9e8166e..b3d34e358 100644 --- a/odex25_takaful/odex_takaful/wizards/add_benefit_wizard.xml +++ b/odex25_takaful/odex_takaful/wizards/add_benefit_wizard.xml @@ -11,7 +11,10 @@ - + diff --git a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py index 05a9c3cf6..562bc2997 100644 --- a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py +++ b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py @@ -69,13 +69,12 @@ class DonationExtensionWizard(models.TransientModel): extension_line_ids = [(5,)] donation_detail_ids = self.env['donations.details.lines'].browse(self.env.context.get('donation_detail_ids')) for line in donation_detail_ids: - line_ref = line.sequence_no or str(line.id) - if not (line.record_type == 'donation' and line.direct_debit) and line.record_type != 'sponsorship': - raise ValidationError(_("Only donation with direct debit or sponsorship can be extended. Line: {}").format(line_ref)) + if line.record_type == 'donation' or line.sponsorship_duration == 'permanent': + raise ValidationError(_("Only donation with direct debit or sponsorship can be extended. Line: %s") % line.name) if line.end_date and line.end_date < fields.Date.context_today(line): - raise ValidationError(_("Only active donations with end date in the future can be extended. Line: {}").format(line_ref)) - if line.state != 'active': - raise ValidationError(_("Only active donations can be extended. Line: {}").format(line_ref)) + raise ValidationError(_("Only active donations with end date in the future can be extended. Line: %s") % line.name) + if line.state not in ['active', 'replace']: + raise ValidationError(_("Only active donations can be extended. Line: %s") % line.name) extension_line_ids.append((0, 0, { 'donation_line_id': line.id, 'current_end_date': line.end_date, diff --git a/odex25_takaful/odex_takaful/wizards/replace_benefit_wizard.xml b/odex25_takaful/odex_takaful/wizards/replace_benefit_wizard.xml index 95a0c21c5..9aafe683e 100644 --- a/odex25_takaful/odex_takaful/wizards/replace_benefit_wizard.xml +++ b/odex25_takaful/odex_takaful/wizards/replace_benefit_wizard.xml @@ -12,7 +12,11 @@ - +