Ecocentral/ecocentral#152: include in_refund invoices. rappel_pending readonly. vendor ref in invoice lines

This commit is contained in:
Luis 2026-06-23 12:16:47 +02:00
parent 4c07dd042d
commit 29ef56b800
5 changed files with 140 additions and 18 deletions

View file

@ -49,16 +49,17 @@ class AccountMoveRappelWizard(models.TransientModel):
active_ids = self.env.context.get("active_ids", [])
moves = self.env["account.move"].browse(active_ids)
# Filter only posted vendor bills
# Filter only posted vendor bills and refunds
valid_moves = moves.filtered(
lambda m: m.move_type == "in_invoice" and m.state == "posted"
lambda m: m.move_type in ("in_invoice", "in_refund")
and m.state == "posted"
)
if not valid_moves:
raise UserError(
_(
"No posted vendor bills found in the selection. "
"Only posted (validated) vendor bills can be used to create "
"rappel commission invoices."
"No posted vendor bills or refunds found in the selection. "
"Only posted (validated) vendor bills and refunds can be used to "
"create rappel commission invoices."
)
)
@ -135,14 +136,31 @@ class AccountMoveRappelWizard(models.TransientModel):
for bill in bills:
taxable_base = bill.amount_untaxed
commission_amount = taxable_base * rate / 100.0
name = _(
"Rappel commission %(rate)s%% — Bill %(bill)s "
"(taxable base: %(base)s %(currency)s)",
rate=rate,
bill=bill.name,
base=f"{taxable_base:,.2f}",
currency=bill.currency_id.name,
)
vendor_ref = bill.ref or bill.name
if bill.move_type == "in_refund":
# Vendor refunds reduce the commission: negate the amount so
# the resulting line subtracts from the rappel invoice total.
# amount_untaxed is always positive in Odoo, so we flip the
# sign here and display a negative base in the description.
commission_amount = -commission_amount
display_base = -taxable_base
name = _(
"Rappel commission %(rate)s%% — Refund %(bill)s "
"(taxable base: %(base)s %(currency)s)",
rate=rate,
bill=vendor_ref,
base=f"{display_base:,.2f}",
currency=bill.currency_id.name,
)
else:
name = _(
"Rappel commission %(rate)s%% — Bill %(bill)s "
"(taxable base: %(base)s %(currency)s)",
rate=rate,
bill=vendor_ref,
base=f"{taxable_base:,.2f}",
currency=bill.currency_id.name,
)
invoice_lines.append(
(
0,

View file

@ -24,6 +24,10 @@
<field name="move_ids">
<tree string="Vendor Bills" editable="0">
<field name="name"/>
<field name="move_type"
widget="badge"
decoration-info="move_type == 'in_invoice'"
decoration-danger="move_type == 'in_refund'"/>
<field name="partner_id"/>
<field name="invoice_date"/>
<field name="amount_untaxed"