From f7e5018ba1ca081991170bcaeb1aa7e7e00f11c2 Mon Sep 17 00:00:00 2001 From: Nossibaelhadi Date: Wed, 19 Nov 2025 13:21:59 +0300 Subject: [PATCH] [FIX] partial extend payment --- odex25_ensan/odex_takaful/i18n/ar_001.po | 2 +- .../wizards/donation_extension_wizard.py | 68 +++++++++++++------ .../wizards/donation_extension_wizard.xml | 8 +-- 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/odex25_ensan/odex_takaful/i18n/ar_001.po b/odex25_ensan/odex_takaful/i18n/ar_001.po index 74c96adec..41ac53d32 100644 --- a/odex25_ensan/odex_takaful/i18n/ar_001.po +++ b/odex25_ensan/odex_takaful/i18n/ar_001.po @@ -2234,7 +2234,7 @@ msgstr "تمديد" #: model_terms:ir.ui.view,arch_db:odex_takaful.donations_details_lines_view_form #, python-format msgid "Extend Donation" -msgstr "تمديد التبرع" +msgstr "تمديد الكفالة" #. module: odex_takaful #: model:ir.model.fields.selection,name:odex_takaful.selection__donations_details_lines__state__extended diff --git a/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.py b/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.py index 544aef59f..b14eb99c6 100644 --- a/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.py +++ b/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.py @@ -40,6 +40,8 @@ class DonationExtensionWizard(models.TransientModel): store=True, ) + + @api.depends('line_ids.total_donation_amount') def _compute_total_extension_amount(self): for rec in self: @@ -48,7 +50,7 @@ class DonationExtensionWizard(models.TransientModel): @api.constrains('is_different_payment', 'payment_line_ids') def _check_payment_sum_when_different(self): for rec in self: - if rec.is_different_payment: + if not rec.is_different_payment: sum_payments = sum(line.payment_amount for line in rec.payment_line_ids) if float_compare(sum_payments, rec.total_extension_amount, precision_digits=2) != 0: raise ValidationError(_("Total payment amounts (%s) must equal total extension amount (%s).") % @@ -75,7 +77,20 @@ class DonationExtensionWizard(models.TransientModel): for rec in self: if rec.months <= 0: raise ValidationError(_("Extension months must be greater than 0.")) - + + @api.onchange('payment_line_ids', 'total_extension_amount') + def _compute_lines(self): + remaining = self.total_extension_amount + + for line in self.payment_line_ids: + + if not line.payment_amount: + line.payment_amount = remaining + + remaining -= line.payment_amount + + line.remaining = remaining if remaining > 0 else 0 + def action_extend(self): """ Extend the donation detail line with new amount and months @@ -88,7 +103,7 @@ class DonationExtensionWizard(models.TransientModel): invoice_ids += result[0] donation_line_ids += result[1] - if invoice_ids and self.is_different_payment: + if invoice_ids and not self.is_different_payment: invoices = invoice_ids.filtered( lambda inv: inv.state == 'posted' and inv.move_type in ('out_invoice', 'out_refund')) if not invoices: @@ -121,10 +136,10 @@ class DonationExtensionWizard(models.TransientModel): payment_register_vals = { 'payment_type': 'inbound', 'partner_type': 'customer', - 'partner_id': pay_line.partner_id.id, + 'partner_id': inv.partner_id.id, 'amount': pay_amount, 'journal_id': pay_line.journal_id.id, - 'payment_method_id': pay_line.payment_method.id, + # 'payment_method_id': pay_line.payment_method.id, 'communication': _("Extension Payment for %s") % inv.name, 'transaction_file_attachment': pay_line.payment_file_attachment, @@ -150,22 +165,22 @@ class DonationExtensionWizard(models.TransientModel): remaining = remaining - pay_amount - elif invoice_ids and not self.is_different_payment: - return { - 'name': _('Register Payment'), - 'res_model': 'account.payment.register', - 'view_mode': 'form', - 'context': { - 'active_model': 'account.move', - 'active_ids': invoice_ids.ids, - 'dont_redirect_to_payments': True, - 'sponsorship_line_ids': donation_line_ids.ids, - 'sponsorship_payment': True, - 'default_sponsorship_payment': True, - }, - 'target': 'new', - 'type': 'ir.actions.act_window', - } + # elif invoice_ids and not self.is_different_payment: + # return { + # 'name': _('Register Payment'), + # 'res_model': 'account.payment.register', + # 'view_mode': 'form', + # 'context': { + # 'active_model': 'account.move', + # 'active_ids': invoice_ids.ids, + # 'dont_redirect_to_payments': True, + # 'sponsorship_line_ids': donation_line_ids.ids, + # 'sponsorship_payment': True, + # 'default_sponsorship_payment': True, + # }, + # 'target': 'new', + # 'type': 'ir.actions.act_window', + # } return { 'type': 'ir.actions.client', @@ -216,6 +231,8 @@ class ExtensionPaymentWizardLine(models.TransientModel): payment_amount = fields.Float(string='Payment Amount', help="Amount to be paid for this line (when different payments used).", default=0.0) + remaining = fields.Float(string="Remaining", readonly=True) + currency_id = fields.Many2one('res.currency', string='Currency', default=lambda self: self.env.company.currency_id, readonly=True) payment_method_type= fields.Selection(related='payment_method.payment_method') @@ -230,6 +247,15 @@ class ExtensionPaymentWizardLine(models.TransientModel): if self.wizard_id and not self.donation_line_ids: self.donation_line_ids = self.wizard_id.line_ids.mapped('donation_line_id').ids + # @api.onchange('payment_amount') + # def _onchange_payment_amount(self): + # amount = 0.0 + # for line in self.wizard_id.payment_line_ids: + # amount += line.payment_amount + # self.payment_amount = self.wizard_id.total_extension_amount - amount + + + @api.depends('donation_line_ids') def _compute_partner_id(self): for rec in self: diff --git a/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.xml b/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.xml index 51bea1b4c..de7e50f78 100644 --- a/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.xml +++ b/odex25_ensan/odex_takaful/wizards/donation_extension_wizard.xml @@ -10,7 +10,7 @@ - + @@ -78,8 +78,8 @@ - - + + @@ -88,7 +88,7 @@ + options="{'currency_field': 'currency_id'}" force_save="1" sum="Total Amount"/>