|
|
for rec in self:
amount_untaxed = rec.sale_id._origin.amount_untaxed
if not amount_untaxed:
continue
# With invoice already created, no recompute
if rec.invoiced:
rec.amount = rec.amount_invoiced
rec.percent = rec.amount / amount_untaxed * 100
continue
# For last line, amount is the left over
if rec.last:
installments = rec.sale_id.invoice_plan_ids.filtered(
lambda plan: plan.invoice_type == "installment"
)
prev_amount = sum((installments - rec).mapped("amount"))
rec.amount = amount_untaxed - prev_amount
continue
rec.amount = rec.percent * amount_untaxed / 100
|
|