Merge pull request #6115 from expsa/samir_aladawi_fix_group_takaful

[UPD] odex_takaful
This commit is contained in:
SamirLADOUI-sa 2026-01-11 10:36:15 +01:00 committed by GitHub
commit c45a55660f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 90 additions and 12 deletions

View File

@ -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',

View File

@ -81,6 +81,22 @@
<field name="active" eval="True"/>
</record>
<!-- Scheduler for Closing Active Sponsorships that have exceed the end date -->
<record id="scheduler_process_closing_sponsorship_action" forcecreate='True' model="ir.cron">
<field name="name">Process Closing Active Sponsorships</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 03:00:00')"/>
<field name="numbercall">-1</field>
<field name="doall" eval="False"/>
<field name="model_id" ref="model_donations_details_lines"/>
<field name="state">code</field>
<field name="code">model.cron_process_closing_ended_sponsorships()</field>
<field name="priority" eval="1"/>
<field name="active" eval="True"/>
</record>
<record id="ir_cron_family_member_restriction" model="ir.cron">
<field name="name">Family Member Restriction</field>
<field name="model_id" ref="odex_benefit.model_family_member"/>

View File

@ -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

View File

@ -0,0 +1,7 @@
from odoo import models, fields
class BenefitCategory(models.Model):
_inherit = 'benefit.category'
allowed_sponsorship = fields.Boolean()

View File

@ -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):
"""

View File

@ -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 = []

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_benefit_category_form_odex_benefit" model="ir.ui.view">
<field name="name">benefit.category.view.form.inherit</field>
<field name="model">benefit.category</field>
<field name="inherit_id" ref="odex_benefit.view_benefit_category_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_benefit']" position="after">
<field name="allowed_sponsorship" widget="boolean_toggle"/>
</xpath>
</field>
</record>
<record id="view_benefit_category_tree_odex_benefit" model="ir.ui.view">
<field name="name">benefit.category.view.tree.inherit</field>
<field name="model">benefit.category</field>
<field name="inherit_id" ref="odex_benefit.view_benefit_category_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_benefit']" position="after">
<field name="allowed_sponsorship" widget="boolean_toggle"/>
</xpath>
</field>
</record>
</odoo>

View File

@ -676,7 +676,7 @@
<page string="Orphans and Widows List"
attrs="{'invisible': ['|',('sponsorship_type', '!=', 'group'), ('hide_beneficiary_group', '=', True)]}">
<!-- attrs="{'invisible': ['|', '|', '|', ('hide_beneficiary_group','=', True), ('parent.record_type','!=','sponsorship'), ('sponsorship_type', '!=', 'group'), ('benefit_type', '!=', 'both')]}">-->
<field name="benefit_ids" nolabel="1" options="{'no_create': True}" context="{'group_by': 'benefit_group', 'members_domain_force_all': True}">
<field name="benefit_ids" nolabel="1" options="{'no_create': True}" domain="[('allowed_sponsorship', '=', True)]" context="{'group_by': 'benefit_group', 'members_domain_force_all': True}">
<tree editable="bottom">
<field name="benefit_group" invisible="1"/>
<field name="name"/>

View File

@ -11,7 +11,10 @@
<field name="members_domain_ids" invisible="1"/>
<group>
<group string="Benefit Information">
<field name="benefit_id" context="{'group_by': 'benefit_group', 'show_age_in_kafalat': True}" options="{'no_create': True, 'no_create_edit':True,'no_open': True}"/>
<field name="benefit_id"
context="{'group_by': 'benefit_group', 'show_age_in_kafalat': True}"
options="{'no_create': True, 'no_create_edit':True,'no_open': True}"
domain="[('allowed_sponsorship', '=', True)]"/>
</group>
</group>

View File

@ -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,

View File

@ -12,7 +12,11 @@
<group>
<group string="Replacement Information">
<field name="old_members_id" attrs="{'invisible': [('record_type', '=', 'donation')]}"/>
<field name="new_members_id" attrs="{'invisible': [('record_type', '=', 'donation')], 'required': [('record_type', '=', 'sponsorship')]}" options="{'no_create': True, 'no_create_edit':True,'no_open': True}" context="{'group_by': 'benefit_group', 'show_age_in_kafalat': True}"/>
<field name="new_members_id"
attrs="{'invisible': [('record_type', '=', 'donation')], 'required': [('record_type', '=', 'sponsorship')]}"
options="{'no_create': True, 'no_create_edit':True,'no_open': True}"
context="{'group_by': 'benefit_group', 'show_age_in_kafalat': True}"
domain="[('allowed_sponsorship', '=', True)]"/>
</group>
</group>
<group string="Replacement Reason">