odoo/odoo#98496

Created by fw-bot
Merged at 993aa4f921d956720f9eb033dc2d236ab14639c1

Statuses:

label
odoo-dev:saas-15.2-15.0-opw-2896797-invoicing_switch_threshold_wrong_qty_invoiced-sesn-vr3h-fw
head
449f30637171798fabbeec456e183aad1b5afd37
merged
3 years ago by Bugfix, Séna Serge Nshimiyimana (sesn)
odoo/odoo
15.0 #97186
saas-15.2 #98496
saas-15.3 #98879
16.0
17.0
18.0
saas-18.1
saas-18.2
saas-18.3
master #98909

[FW][FIX] sale, purchase: fix invoicing interaction with “Invoicing Switch Threshold”

Steps to reproduce

  • Create a sale order with a product that's invoiced on delivered quantities.
  • Set delivered quantity (partial delivery) and create an invoice based on the delivered quantity. Set the "Invoice Date" to sometime in the past.
  • Go to the settings and set "Invoicing Switch Threshold" to any date in the future (so that the invoice you created has a date BEFORE the new threshold)
  • The invoice will get the label "invoicing app legacy".
  • Go back to the sales order and change the delivered quantity.

You should see that the invoiced quantity is automatically set to 0.
A similar behavior can be observed with purchase orders.

Why this is happening

When a new “Invoicing Switch Threshold” is set, all posted invoices before the threshold are marked as canceled. In v15, changing the delivered quantities triggers the invoiced quantities to be recalculated as well. However, computing invoiced quantities doesn't take into account invoices that are marked as canceled. This mean that the newly computed invoiced quantities won't include invoices posted before threshold.

opw-2896797

Forward-Port-Of: #97186