FIX translate partial payment for extend
This commit is contained in:
parent
1026af7175
commit
8b0ab0cfdb
|
|
@ -89,24 +89,64 @@ class DonationExtensionWizard(models.TransientModel):
|
|||
donation_line_ids += result[1]
|
||||
|
||||
if invoice_ids and 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:
|
||||
return
|
||||
|
||||
residual_map = {inv.id: float(inv.amount_residual) for inv in invoices}
|
||||
|
||||
invoices = invoices.sorted(key=lambda r: r.invoice_date or r.date or fields.Date.context_today(self))
|
||||
|
||||
for pay_line in self.payment_line_ids:
|
||||
remaining = float(pay_line.payment_amount or 0.0)
|
||||
if float_compare(remaining, 0.0, precision_digits=2) <= 0:
|
||||
continue
|
||||
|
||||
candidate_invoices = invoices.filtered(lambda inv: inv.partner_id == pay_line.partner_id)
|
||||
|
||||
if not candidate_invoices:
|
||||
candidate_invoices = invoices
|
||||
|
||||
for inv in candidate_invoices:
|
||||
if float_compare(remaining, 0.0, precision_digits=2) <= 0:
|
||||
break
|
||||
|
||||
inv_res = residual_map.get(inv.id, 0.0)
|
||||
if float_compare(inv_res, 0.0, precision_digits=2) <= 0:
|
||||
continue
|
||||
|
||||
pay_amount = min(remaining, inv_res)
|
||||
|
||||
payment_register_vals = {
|
||||
'payment_type': 'inbound',
|
||||
'partner_type': 'customer',
|
||||
'partner_id': pay_line.partner_id.id,
|
||||
'amount': pay_line.payment_amount,
|
||||
'amount': pay_amount,
|
||||
'journal_id': pay_line.journal_id.id,
|
||||
'payment_method_id': pay_line.payment_method.id,
|
||||
'communication': _("Extension Payment"),
|
||||
'communication': _("Extension Payment for %s") % inv.name,
|
||||
}
|
||||
|
||||
payment_register = self.env['account.payment.register'].sudo().with_context(
|
||||
active_model='account.move',
|
||||
active_ids=invoice_ids.ids,
|
||||
).create(payment_register_vals)
|
||||
print('.................',payment_register)
|
||||
payment_register.action_create_payments()
|
||||
ctx = {
|
||||
'active_model': 'account.move',
|
||||
'active_ids': [inv.id],
|
||||
'dont_redirect_to_payments': True,
|
||||
'sponsorship_line_ids': donation_line_ids.ids,
|
||||
'sponsorship_payment': True,
|
||||
'default_sponsorship_payment': True,
|
||||
}
|
||||
|
||||
payment_register = self.env['account.payment.register'].sudo().with_context(ctx).new(
|
||||
payment_register_vals)
|
||||
payments = payment_register._create_payments()
|
||||
|
||||
inv_sudo = inv.sudo()
|
||||
inv_sudo.invalidate_cache(['amount_residual'])
|
||||
new_residual = float(inv_sudo.amount_residual or 0.0)
|
||||
residual_map[inv.id] = new_residual
|
||||
|
||||
remaining = remaining - pay_amount
|
||||
|
||||
elif invoice_ids and not self.is_different_payment:
|
||||
return {
|
||||
|
|
|
|||
Loading…
Reference in New Issue