diff --git a/odex25_takaful/odex_takaful/models/res_partner.py b/odex25_takaful/odex_takaful/models/res_partner.py index 4167b994d..bb21ce779 100644 --- a/odex25_takaful/odex_takaful/models/res_partner.py +++ b/odex25_takaful/odex_takaful/models/res_partner.py @@ -135,6 +135,26 @@ class ResPartner(models.Model): if is_family_or_beneficiary and is_donor_vendor_sponsor: raise ValidationError(_("A contact cannot be both Family/Beneficiary and Donor/Member/Sponsor at the same time!")) + @api.model + def search(self, args, offset=0, limit=None, order=None, count=False): + + if not self.env.context.get('from_contact_search'): + return super().search(args, offset=offset, limit=limit, order=order, count=count) + + if self.env.context.get('mail_read') or self.env.context.get('mail_message_origin'): + return super().search(args, offset=offset, limit=limit, order=order, count=count) + + base_results = super().search(args, offset=offset, limit=limit, order=order) + + if not base_results: + return base_results + + children = super().search([('parent_id', 'in', base_results.ids)]) + + final_ids = list(set(base_results.ids + children.ids)) + + return super().search([('id', 'in', final_ids)], offset=0, limit=limit, order=order, count=count) + @api.model def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): if not args: diff --git a/odex25_takaful/odex_takaful/security/security_data.xml b/odex25_takaful/odex_takaful/security/security_data.xml index 6cd9e1484..d53169341 100644 --- a/odex25_takaful/odex_takaful/security/security_data.xml +++ b/odex25_takaful/odex_takaful/security/security_data.xml @@ -196,16 +196,7 @@ - - Branch Manager can only see all his branch sponsorships and donations Lines - - - [('branch_custom_id.branch.manager_id.user_id', 'in', [user.id, False])] - - - - - + Sponsorship System Manager diff --git a/odex25_takaful/odex_takaful/views/res_partner_bank.xml b/odex25_takaful/odex_takaful/views/res_partner_bank.xml index 07122d8ca..6ed26d1e7 100644 --- a/odex25_takaful/odex_takaful/views/res_partner_bank.xml +++ b/odex25_takaful/odex_takaful/views/res_partner_bank.xml @@ -13,7 +13,7 @@ - + diff --git a/odex25_takaful/odex_takaful/views/takaful_sponsor_view.xml b/odex25_takaful/odex_takaful/views/takaful_sponsor_view.xml index 66c8e8be6..972d02801 100644 --- a/odex25_takaful/odex_takaful/views/takaful_sponsor_view.xml +++ b/odex25_takaful/odex_takaful/views/takaful_sponsor_view.xml @@ -187,10 +187,10 @@ -
-
+ + + +
@@ -210,7 +210,8 @@ 'default_company_type': 'person', 'default_is_sponsor_portal': True, 'default_is_donor': True, - 'sponsor_contact': True + 'sponsor_contact': True, + 'from_contact_search': True } @@ -249,6 +250,20 @@ + + + + + + + + + + + + + + Make Active diff --git a/odex25_takaful/odex_takaful/wizards/account_payment_register.xml b/odex25_takaful/odex_takaful/wizards/account_payment_register.xml index eba168065..04fb2d473 100644 --- a/odex25_takaful/odex_takaful/wizards/account_payment_register.xml +++ b/odex25_takaful/odex_takaful/wizards/account_payment_register.xml @@ -45,7 +45,7 @@ - + diff --git a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py index 159eddb2e..9ec28ecb9 100644 --- a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py +++ b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.py @@ -263,6 +263,12 @@ class DonationExtensionWizardLine(models.TransientModel): compute='_compute_new_end_date', readonly=True ) + extension_invoice_id = fields.Many2one( + 'account.move', + string="Extension Invoice", + readonly=True + ) + direct_debit_partner_bank_id = fields.Many2one("res.partner.bank", string="Direct Debit Partner Bank", domain="[('partner_id', '=', partner_id)]") debit_payment_file_attachment = fields.Binary(string='Debit Payment Attachment', attachment=True) debit_payment_attachment_file_name = fields.Char('Debit Payment File Name', required=False) @@ -313,55 +319,56 @@ class DonationExtensionWizardLine(models.TransientModel): if not self.donation_line_id: raise ValidationError(_("No donation detail line selected.")) - - # Update the donation detail line - new_end_date = self.current_end_date + relativedelta(months=self.months) - old_end_date = self.current_end_date - - # Update end date - donation_line_new_vals = { - 'end_date': new_end_date, - 'payment_month_count': self.donation_line_id.payment_month_count + self.months, - } - if self.direct_debit: - donation_line_new_vals.update({ - 'direct_debit': self.direct_debit, - 'direct_debit_partner_bank_id': self.direct_debit_partner_bank_id.id, - 'journal_id': self.journal_id.id, - 'debit_payment_file_attachment': self.debit_payment_file_attachment, - 'debit_payment_attachment_file_name': self.debit_payment_attachment_file_name, - }) - self.donation_line_id.write(donation_line_new_vals) + if not self.extension_invoice_id: + # Update the donation detail line + new_end_date = self.current_end_date + relativedelta(months=self.months) + old_end_date = self.current_end_date - benefit_ids = self.donation_line_id.benefit_ids | self.donation_line_id.benefit_id - benefit_ids.write({ - 'sponsorship_end_date': new_end_date, - 'kafala_status': 'have_kafala', - }) - - # Create new scheduling lines for the extension period - if self.direct_debit: - self._create_extension_scheduling_lines() - - # Create invoice for the extension - invoice_id = self._create_extension_invoice() - - # Create extension history record - self.env['donation.extension.history'].create({ - 'donation_detail_id': self.donation_line_id.id, - 'sponsorship_id': self.donation_line_id.sponsorship_id.id or self.donation_line_id.sponsorship_mechanism_id.id, - 'extension_amount': self.total_donation_amount, - 'extension_months': self.months, - 'old_end_date': old_end_date, - 'new_end_date': new_end_date, - 'invoice_id': invoice_id.id if invoice_id else False, - 'old_direct_debit': self.donation_line_id.direct_debit, - 'new_direct_debit': self.direct_debit, - - }) + # Update end date + donation_line_new_vals = { + 'end_date': new_end_date, + 'payment_month_count': self.donation_line_id.payment_month_count + self.months, + } + if self.direct_debit: + donation_line_new_vals.update({ + 'direct_debit': self.direct_debit, + 'direct_debit_partner_bank_id': self.direct_debit_partner_bank_id.id, + 'journal_id': self.journal_id.id, + 'debit_payment_file_attachment': self.debit_payment_file_attachment, + 'debit_payment_attachment_file_name': self.debit_payment_attachment_file_name, + }) + self.donation_line_id.write(donation_line_new_vals) + + benefit_ids = self.donation_line_id.benefit_ids | self.donation_line_id.benefit_id + benefit_ids.write({ + 'sponsorship_end_date': new_end_date, + 'kafala_status': 'have_kafala', + }) + + # Create new scheduling lines for the extension period + if self.direct_debit: + self._create_extension_scheduling_lines() + + # Create invoice for the extension + invoice_id = self._create_extension_invoice() + self.extension_invoice_id = invoice_id + + # Create extension history record + self.env['donation.extension.history'].create({ + 'donation_detail_id': self.donation_line_id.id, + 'sponsorship_id': self.donation_line_id.sponsorship_id.id or self.donation_line_id.sponsorship_mechanism_id.id, + 'extension_amount': self.total_donation_amount, + 'extension_months': self.months, + 'old_end_date': old_end_date, + 'new_end_date': new_end_date, + 'invoice_id': invoice_id.id if invoice_id else False, + 'old_direct_debit': self.donation_line_id.direct_debit, + 'new_direct_debit': self.direct_debit, + + }) if not self.direct_debit: - return invoice_id, self.donation_line_id + return self.extension_invoice_id, self.donation_line_id return False diff --git a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.xml b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.xml index 51eb6fc1d..1422bc7dc 100644 --- a/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.xml +++ b/odex25_takaful/odex_takaful/wizards/donation_extension_wizard.xml @@ -60,7 +60,7 @@ + attrs="{'invisible': [('direct_debit', '=', False)], 'required': [('direct_debit', '=', True)]}" create="1" edit="1"/>