From 999c9cdd79ae587afd219c9bc7f7cb671abfb7a3 Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Thu, 25 May 2023 09:38:33 +0000 Subject: [PATCH] [FIX] purchase: don't track_qty_received on PO when doing accrued expense entry Failing use case: While having purchase_stock installed, create and confirm a request for quotation, received some products but no bill for it. Now select the PO is the list, click on 'Action > Accrued Expense Entry'. Make sure the wizard will effectively create an accrued expense entry (it should be the case if you have some product received and not billed). Upon confirmation of the wizard, the system will recompute the received quantity on the original PO, logging notes that pollutes, confuses and spams its followers. The reason is that we use a new record to compute the difference between the received and billed quantities at a given date in the past, and even if track_qty_received is called on a newid, it will find back the original PO where doing line.order_id. The solution is to check in the context if we're in such use case before logging, because we know that calling the accrued expense entry wizard aims not to change the received quantity in any wase closes odoo/odoo#122720 X-original-commit: b31f1ad789e92c84f85654b67e6730e413f0e06b Signed-off-by: Florian Gilbert (flg) --- addons/purchase/models/purchase.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 6af4acb8310..96e9a9cecc8 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1457,6 +1457,10 @@ class PurchaseOrderLine(models.Model): def _track_qty_received(self, new_qty): self.ensure_one() + # don't track anything when coming from the accrued expense entry wizard, as it is only computing fields at a past date to get relevant amounts + # and doesn't actually change anything to the current record + if self.env.context.get('accrual_entry_date'): + return if new_qty != self.qty_received and self.order_id.state == 'purchase': self.order_id.message_post_with_source( 'purchase.track_po_line_qty_received_template',