Merge pull request #5452 from expsa/partial_extend_payment

Partial extend payment
This commit is contained in:
NossibaElhadi 2025-11-19 13:31:57 +03:00 committed by GitHub
commit e641b88b1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 26 deletions

View File

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

View File

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

View File

@ -10,7 +10,7 @@
<group>
<group string="Extension Details">
<field name="months"/>
<field name="is_different_payment"/>
<!-- <field name="is_different_payment"/>-->
</group>
</group>
<notebook>
@ -78,8 +78,8 @@
</form>
</field>
</page>
<page string="Sub Payments" attrs="{'invisible': [('is_different_payment', '=', False)]}">
<field name="payment_line_ids" attrs="{'invisible': [('is_different_payment', '=', False)]}" nolabel="1">
<page string="Sub Payments" >
<field name="payment_line_ids" nolabel="1">
<tree editable="bottom" delete="true" create="true">
<field name="payment_method" options="{'no_create': True, 'no_create_edit': True}"/>
<field name="currency_id" invisible="1"/>
@ -88,7 +88,7 @@
<field name="partner_id" invisible="1"/>
<field name="journal_id" string="Association Journal"/>
<field name="payment_amount" widget="monetary"
options="{'currency_field': 'currency_id'}" force_save="1"/>
options="{'currency_field': 'currency_id'}" force_save="1" sum="Total Amount"/>
<field name="check_number"
attrs="{
'invisible': [