From cf082e3988a2184c1bed0f25f4345df385240657 Mon Sep 17 00:00:00 2001 From: Abdurrahman Saber Date: Mon, 3 Nov 2025 17:18:20 +0200 Subject: [PATCH 01/16] [IMP] odex_takaful: reset to draft, multiple line extension --- .../odex_takaful/data/server_actions.xml | 8 + .../odex_takaful/models/account_move.py | 13 +- .../models/donation_details_lines.py | 5 +- .../odex_takaful/models/res_partner.py | 15 +- .../models/takaful_sponorship_model.py | 94 +------- .../odex_takaful/security/ir.model.access.csv | 1 + .../views/takaful_sponorship_view.xml | 5 +- .../wizards/account_payment_register.py | 5 +- .../wizards/donation_extension_wizard.py | 227 +++++++++++------- .../wizards/donation_extension_wizard.xml | 34 ++- 10 files changed, 213 insertions(+), 194 deletions(-) diff --git a/odex25_ensan/odex_takaful/data/server_actions.xml b/odex25_ensan/odex_takaful/data/server_actions.xml index c4bdf4c4c..ee01e5634 100644 --- a/odex25_ensan/odex_takaful/data/server_actions.xml +++ b/odex25_ensan/odex_takaful/data/server_actions.xml @@ -10,5 +10,13 @@ action = records.action_unlink_sponsor_and_related() + + + Extend Donation + + + code + action = records.action_extend_sponsorship() + \ No newline at end of file diff --git a/odex25_ensan/odex_takaful/models/account_move.py b/odex25_ensan/odex_takaful/models/account_move.py index b67c5434f..eaaebd7ec 100644 --- a/odex25_ensan/odex_takaful/models/account_move.py +++ b/odex25_ensan/odex_takaful/models/account_move.py @@ -7,13 +7,22 @@ from collections import defaultdict class AccountMove(models.Model): _inherit = 'account.move' - takaful_sponsorship_id = fields.Many2one('takaful.sponsorship') + takaful_sponsorship_id = fields.Many2one('takaful.sponsorship', compute='_compute_takaful_sponsorship_id', store=True) is_refund_sponsorship = fields.Boolean(string='Is Refund Sponsorship', default=False) sponsorship_scheduling_line = fields.Many2one('sponsorship.scheduling.line') payment_details_line = fields.Many2one('payment.details.lines') sponsorship_id = fields.Many2one('takaful.sponsorship', string='Sponsorship', readonly=True, ) payment_id = fields.Many2one('account.payment', string='Payment', copy=False) + @api.depends('state') + def _compute_takaful_sponsorship_id(self): + for move in self: + if not move.takaful_sponsorship_id: + partials = move.line_ids.matched_debit_ids | move.line_ids.matched_credit_ids + takaful_sponsorship_ids = (partials.debit_move_id.move_id.takaful_sponsorship_id | partials.credit_move_id.move_id.takaful_sponsorship_id) + move.takaful_sponsorship_id = takaful_sponsorship_ids[-1] if takaful_sponsorship_ids else False + else: + move.takaful_sponsorship_id = move.takaful_sponsorship_id def action_move_line_create(self): ''' Confirm the vouchers given in ids and create the journal entries for each of them @@ -239,5 +248,5 @@ class AccountMove(models.Model): class AccountMoveLines(models.Model): _inherit = 'account.move.line' - takaful_sponsorship_id = fields.Many2one('takaful.sponsorship') + takaful_sponsorship_id = fields.Many2one('takaful.sponsorship', related='move_id.takaful_sponsorship_id', store=True) diff --git a/odex25_ensan/odex_takaful/models/donation_details_lines.py b/odex25_ensan/odex_takaful/models/donation_details_lines.py index a44af72f0..b6145bfe9 100644 --- a/odex25_ensan/odex_takaful/models/donation_details_lines.py +++ b/odex25_ensan/odex_takaful/models/donation_details_lines.py @@ -934,7 +934,6 @@ class DonationsDetailsLines(models.Model): """ Open wizard to extend donation detail line """ - self.ensure_one() return { 'type': 'ir.actions.act_window', @@ -943,9 +942,7 @@ class DonationsDetailsLines(models.Model): 'view_mode': 'form', 'target': 'new', 'context': { - 'default_donation_detail_id': self.id, - 'default_current_end_date': self.end_date, - 'default_amount': self.product_template_id.list_price, + 'donation_detail_ids': self.ids, }, } diff --git a/odex25_ensan/odex_takaful/models/res_partner.py b/odex25_ensan/odex_takaful/models/res_partner.py index 4390bf9cd..8c54daa2e 100644 --- a/odex25_ensan/odex_takaful/models/res_partner.py +++ b/odex25_ensan/odex_takaful/models/res_partner.py @@ -5,8 +5,7 @@ from odoo.exceptions import UserError, ValidationError, Warning from dateutil.parser import parse import re from odoo.osv import expression -SAUDI_MOBILE_PATTERN = r"^(05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$" - +SAUDI_MOBILE_PATTERN = r"^(\+?966)?0?5[013456789][0-9]{7}$" class IrActionsServer(models.Model): _inherit = 'ir.actions.server' @@ -407,3 +406,15 @@ class ResPartner(models.Model): else: rec.name = " " +class ResPartnerBank(models.Model): + _inherit = 'res.partner.bank' + + def name_get(self): + result = [] + for bank in self: + if bank.bank_id: + name = f"{bank.acc_number} - {bank.bank_id.name}" + else: + name = f"{bank.acc_number}" + result.append((bank.id, name)) + return result \ No newline at end of file diff --git a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py index 63336a5a3..6b0724671 100644 --- a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py +++ b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py @@ -15,7 +15,7 @@ import requests from odoo.osv import expression import logging -SAUDI_MOBILE_PATTERN = r"^(05|5)(5|0|3|6|4|9|1|8|7)([0-9]{7})$" +SAUDI_MOBILE_PATTERN = r"^(\+?966)?0?5[013456789][0-9]{7}$" def trunc_datetime(someDate): @@ -755,6 +755,7 @@ class TakafulSponsorship(models.Model): taxes = line.move_id.fiscal_position_id.map_tax(taxes, partner=line.partner_id) line.tax_ids = taxes line.product_uom_id = line._get_computed_uom() + bill_id.action_post() else: sponsorship.state = sponsorship.state @@ -1068,90 +1069,11 @@ class TakafulSponsorship(models.Model): rec.expected_cancel_date = None rec.due_days = 0 - # On Change - # @api.onchange('sponsorship_class', 'sponsorship_type', 'benefit_id', 'benefit_ids') - # def sponsorship_fully_value(self): - # if self.sponsorship_class == 'fully' and self.benefit_ids and self.sponsorship_type == 'group': - # self.update({'contribution_value': sum( - # self.benefit_ids.mapped('benefit_needs_value'))}) - # elif self.sponsorship_class == 'fully' and self.benefit_id and self.sponsorship_type == 'person': - # self.update( - # {'contribution_value': self.benefit_id.benefit_needs_value}) - # else: - # self.update({'contribution_value': 0}) - - # @api.constrains('contribution_value') - # def check_contribution_value(self): - # if not self.sponsor_id: - # raise ValidationError( - # _(u'Please Select The Sponsor')) - - # if not self.sponsorship_type: - # raise ValidationError( - # _(u'Please Select Sponsorship Type')) - # - # if not self.benefit_type: - # raise ValidationError( - # _(u'Please Select Sponsorship Beneficiary Type')) - # - # if not self.sponsorship_class: - # raise ValidationError( - # _(u'Please Select Sponsorship Class')) - # - # if not self.sponsorship_duration: - # raise ValidationError( - # _(u'Please Select Sponsorship Duration')) - # - # if not self.benefit_id and self.sponsorship_type == 'person': - # raise ValidationError( - # _(u'Please Select a Beneficiary For Sponsorship Person')) - # - # if len(self.benefit_ids) < 2 and self.sponsorship_type == 'group': - # raise ValidationError( - # _(u'Please Select At least Two Beneficiaries For Sponsorship Group')) - # - # if self.sponsorship_class == 'partial': - # default_sponsorship = int( - # self.env['ir.config_parameter'].sudo().get_param('odex_takaful_base.min_kafala', 0)) - # - # if self.benefit_ids and self.sponsorship_type == 'group': - # benefit_count = len(self.benefit_ids) - # else: - # benefit_count = 1 - # - # if default_sponsorship <= 0: - # raise ValidationError( - # _(u'Min kafala value should be defined by administration')) - # - # total_sponsorship = default_sponsorship * benefit_count - # if self.contribution_value < total_sponsorship: - # raise ValidationError( - # _(u'Kafala value should be equal or greater than') + ' ' + str(total_sponsorship)) - - # Model Operations @api.model def create(self, vals): if vals.get('code', 'New') == 'New': vals['code'] = self.env['ir.sequence'].sudo().next_by_code('sponsorship.sequence') - # if vals.get('benefit_type') == 'orphan': - # main_code = self.env['ir.sequence'].sudo( - # ).next_by_code('sponsorship.sequence') - # sub_code = self.env['ir.sequence'].sudo().next_by_code( - # 'sponsorship.orphan.sequence') - # if main_code and sub_code: - # defualt_code = 'OR/' + str(main_code) + '/' + sub_code - # vals.update({"code": defualt_code}) - - # elif vals.get('benefit_type') == 'widow': - # main_code = self.env['ir.sequence'].sudo( - # ).next_by_code('sponsorship.sequence') - # sub_code = self.env['ir.sequence'].sudo().next_by_code( - # 'sponsorship.widow.sequence') - # if main_code and sub_code: - # defualt_code = 'WI/' + str(main_code) + '/' + sub_code - # vals.update({"code": defualt_code}) - - # Valid Sponsor Mobile + sponsor_phone = vals.get('sponsor_phone', False) if sponsor_phone: self._check_phone_numbers(sponsor_phone) @@ -1730,6 +1652,7 @@ class TakafulSponsorship(models.Model): 'dont_redirect_to_payments': True, 'sponsorship_line_ids': sponsorship_line_ids.ids, 'sponsorship_payment': True, + 'sponsorship_payment_skip_compute_amount': True, 'default_sponsorship_payment': True, 'force_sponsorship_line_partner_id': self.sponsor_id.id, }, @@ -1743,6 +1666,15 @@ class TakafulSponsorship(models.Model): sponsorship_line_ids = (rec.donations_details_lines | rec.donations_details_lines_mechanism_ids).filtered(lambda l: not l.direct_debit) rec.show_register_payment = rec.with_context(exclude_direct_debit=True).amount_paid < sum(sponsorship_line_ids.mapped('total_donation_amount')) + def action_reset_to_draft(self): + for rec in self: + if rec.state != 'confirmed': + raise ValidationError(_("You can only reset to draft a confirmed sponsorship.")) + move_ids = rec.journal_entry_ids.filtered(lambda l: l.move_type == 'out_invoice') + move_ids.button_draft() + move_ids.button_cancel() + self.write({'state': 'draft'}) + class AnotherSponsors(models.Model): _name = "donate.for.another.person" diff --git a/odex25_ensan/odex_takaful/security/ir.model.access.csv b/odex25_ensan/odex_takaful/security/ir.model.access.csv index 25899b728..7c34b0b99 100644 --- a/odex25_ensan/odex_takaful/security/ir.model.access.csv +++ b/odex25_ensan/odex_takaful/security/ir.model.access.csv @@ -45,6 +45,7 @@ access_group_kufula_user_account_partial_reconcile,access_group_kufula_user_acco access_group_kufula_user_account_full_reconcile,access_group_kufula_user_account_full_reconcile,account.model_account_full_reconcile,odex_takaful.group_kufula_user,1,1,1,0 access_donation_extension_wizard,donation.extension.wizard.access,model_donation_extension_wizard,base.group_user,1,1,1,1 access_donation_extension_history,donation.extension.history.access,model_donation_extension_history,odex_takaful.group_kufula_user,1,1,1,0 +access_donation_extension_wizard_line,donation.extension.wizard.line.access,model_donation_extension_wizard_line,odex_takaful.group_kufula_user,1,1,1,0 access_replace_sponsor_wizard,replace.sponsor.wizard.access,model_replace_sponsor_wizard,odex_takaful.group_replace_sponsor,1,1,1,1 diff --git a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml index b5ddf7845..d13a75436 100644 --- a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml @@ -39,6 +39,9 @@ - - - - - + + + + + + + + + + + + + + From 54a8dd6f2a5a2e746551242f8df4e6076dbfb523 Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Tue, 4 Nov 2025 15:09:36 +0300 Subject: [PATCH 10/16] =?UTF-8?q?FIX=20customer=20notes=20and=20kafala=20i?= =?UTF-8?q?nfo=20=D9=81tran?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- odex25_ensan/odex_takaful/i18n/ar_001.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odex25_ensan/odex_takaful/i18n/ar_001.po b/odex25_ensan/odex_takaful/i18n/ar_001.po index 145f1de36..c9dcefb5d 100644 --- a/odex25_ensan/odex_takaful/i18n/ar_001.po +++ b/odex25_ensan/odex_takaful/i18n/ar_001.po @@ -7289,7 +7289,7 @@ msgstr "مبلغ التبرع صفر الرجاء ادخال قيمة لمبلغ #. module: odex_takaful #: model_terms:ir.ui.view,arch_db:odex_takaful.family_member_form_inherit_donation_button msgid "Kafala Information" -msgstr "" +msgstr "بيانات الكفالة" From 5e880f435650499bb37b3f514a67fc5bb2629a3e Mon Sep 17 00:00:00 2001 From: Altahir Hassan Date: Tue, 4 Nov 2025 16:55:16 +0400 Subject: [PATCH 11/16] REMOVE unnecessary class from tree view in sponsorship form --- odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml index b625f19a7..5d18333d2 100644 --- a/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml +++ b/odex25_ensan/odex_takaful/views/takaful_sponorship_view.xml @@ -187,7 +187,7 @@ context="{'default_active_id': active_id,'default_donation_mechanism': 'without_conditions','default_start_date': sponsorship_creation_date}" widget="section_and_note_one2many" attrs="{'invisible': ['|',('donation_mechanism', '=', 'with_conditions'),('record_type', '!=', 'donation')], 'readonly': [('state','!=','draft')]}"> - + Date: Tue, 4 Nov 2025 16:38:16 +0300 Subject: [PATCH 12/16] FIX inhert from account move --- odex25_ensan/odex_takaful/views/acount_move.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 odex25_ensan/odex_takaful/views/acount_move.xml diff --git a/odex25_ensan/odex_takaful/views/acount_move.xml b/odex25_ensan/odex_takaful/views/acount_move.xml new file mode 100644 index 000000000..e69de29bb From 11b7b8839539b56f740ab087a8c35c4763db26de Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Tue, 4 Nov 2025 16:39:06 +0300 Subject: [PATCH 13/16] FIX inhert from account move --- odex25_ensan/odex_takaful/views/acount_move.xml | 15 +++++++++++++++ odex25_ensan/odex_takaful/views/family_member.xml | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/odex25_ensan/odex_takaful/views/acount_move.xml b/odex25_ensan/odex_takaful/views/acount_move.xml index e69de29bb..81ac722c6 100644 --- a/odex25_ensan/odex_takaful/views/acount_move.xml +++ b/odex25_ensan/odex_takaful/views/acount_move.xml @@ -0,0 +1,15 @@ + + + + takaful.account.move.inherit.form + account.move + + + + {'invisible': False} + + + + + + \ No newline at end of file diff --git a/odex25_ensan/odex_takaful/views/family_member.xml b/odex25_ensan/odex_takaful/views/family_member.xml index a01667586..d10e6af69 100644 --- a/odex25_ensan/odex_takaful/views/family_member.xml +++ b/odex25_ensan/odex_takaful/views/family_member.xml @@ -13,21 +13,28 @@ widget="statinfo"/> + + + + + + + + - From dcdb4511678533a373b1200a06a48db7d613f714 Mon Sep 17 00:00:00 2001 From: Altahir Hassan Date: Tue, 4 Nov 2025 17:42:59 +0400 Subject: [PATCH 14/16] ADD Arabic translations for donation messages and UI elements in odex_takaful module --- odex25_ensan/odex_takaful/i18n/ar_001.po | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/odex25_ensan/odex_takaful/i18n/ar_001.po b/odex25_ensan/odex_takaful/i18n/ar_001.po index c9dcefb5d..b4c641cb8 100644 --- a/odex25_ensan/odex_takaful/i18n/ar_001.po +++ b/odex25_ensan/odex_takaful/i18n/ar_001.po @@ -7278,13 +7278,30 @@ msgstr "مكفول" msgid "Have not Kafala" msgstr "غير مكفول" - #. module: odex_takaful #: code:addons/odex_takaful/models/takaful_sponorship_model.py:0 #, python-format msgid "Please Check The Amount in donation Line!" msgstr "مبلغ التبرع صفر الرجاء ادخال قيمة لمبلغ التبرع" +#. module: odex_takaful +#: model_terms:ir.ui.view,arch_db:odex_takaful.product_product_view_kanban +msgid "" +msgstr "" + +#. module: odex_takaful +#: model_terms:ir.ui.view,arch_db:odex_takaful.product_product_view_kanban +msgid "" +msgstr "" + +#. module: odex_takaful +#: model_terms:ir.ui.view,arch_db:odex_takaful.product_template_view_kanban_odex_takaful +msgid "" +"\n" +" Add" +msgstr "" +"\n" +" إضافة" #. module: odex_takaful #: model_terms:ir.ui.view,arch_db:odex_takaful.family_member_form_inherit_donation_button From 3fa9b6f1cc1d6ec9c8220a699c0dce0962e09078 Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Tue, 4 Nov 2025 17:09:17 +0300 Subject: [PATCH 15/16] FIX inhert from account move to view invoice_origin --- odex25_ensan/odex_takaful/views/acount_move.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/odex25_ensan/odex_takaful/views/acount_move.xml b/odex25_ensan/odex_takaful/views/acount_move.xml index 81ac722c6..5f11baa99 100644 --- a/odex25_ensan/odex_takaful/views/acount_move.xml +++ b/odex25_ensan/odex_takaful/views/acount_move.xml @@ -7,6 +7,7 @@ {'invisible': False} + From 6ebd8e6257982e2d460305f3b467375baa980fd4 Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Tue, 4 Nov 2025 17:22:50 +0300 Subject: [PATCH 16/16] FIX family member kafala field --- odex25_ensan/odex_benefit/models/family_members.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/odex25_ensan/odex_benefit/models/family_members.py b/odex25_ensan/odex_benefit/models/family_members.py index 4fed4ac85..ed6315b9f 100644 --- a/odex25_ensan/odex_benefit/models/family_members.py +++ b/odex25_ensan/odex_benefit/models/family_members.py @@ -251,7 +251,9 @@ class FamilyMemberProfile(models.Model): default='auto') is_member_workflow = fields.Boolean('Is Member Workflow?') # sponsor_id = fields.Many2one('res.partner', string='Sponsor Partner',domain="[('account_type','=','sponsor')]") - + sponsor_id = fields.Many2one('res.partner', string='Sponsor Partner', domain="[('is_sponsor_portal', '=', True)]") + sponsor_related_id = fields.Many2one('res.partner', string='Sponsor') + sponsorship_id = fields.Many2one('takaful.sponsorship', string='Sponsorship') required_attach = fields.Selection(selection=[('true', 'True'), ('false', 'False')], compute='get_required_attach', store=True, string='Member Required Attach') # Exception fields