From ebdb317a989cb66b4d9b23e42e1ccc91c13be59a Mon Sep 17 00:00:00 2001 From: "Matheus Leal Viana (malv)" Date: Wed, 19 Jul 2023 14:37:05 +0000 Subject: [PATCH] [FIX] account: Create multiple invoices with correct account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: ------------------- * Go to Contacts and create two contacts, each with a personalized account receivable; * Go to Sales and create a quotation for each contact; * Confirm the quotations and deliver the products; * From the sale.order view list, select the two SOs and click on Action to create invoices. * Go to the new invoices -> Journal items * One of the invoices has wrong account receivable Issue: ------------------- When creating two invoices for two different quotations and customers, where each customer has a personalized account receivable, only one of the new invoices assign it correctly. Cause: ------------------- When computing the account_id for the move lines, a SQL query selects distinct based on property.company_id, property.name but since the property.name is the same for both customers “property_account_receivable_id” and they have the same company_id it only consider the first one and the second is discarded. To fix the issue, we need to ensure that all users are being considered in the computations. OPW-3376865 closes odoo/odoo#129607 X-original-commit: c66d9ee2a160c3bad745b1394308c3e48f5f2e91 Signed-off-by: Florian Gilbert (flg) Signed-off-by: Matheus Leal Viana (malv) --- addons/account/models/account_move_line.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move_line.py b/addons/account/models/account_move_line.py index 81deecbb2ce..c2e93c996e8 100644 --- a/addons/account/models/account_move_line.py +++ b/addons/account/models/account_move_line.py @@ -505,7 +505,7 @@ class AccountMoveLine(models.Model): AND line.id != ANY(%(current_ids)s) ), properties AS( - SELECT DISTINCT ON (property.company_id, property.name) + SELECT DISTINCT ON (property.company_id, property.name, property.res_id) 'res.partner' AS model, SPLIT_PART(property.res_id, ',', 2)::integer AS id, CASE @@ -518,7 +518,7 @@ class AccountMoveLine(models.Model): WHERE property.name IN ('property_account_receivable_id', 'property_account_payable_id') AND property.company_id = ANY(%(company_ids)s) AND property.res_id = ANY(%(partners)s) - ORDER BY property.company_id, property.name, account_id + ORDER BY property.company_id, property.name, property.res_id, account_id ), default_properties AS( SELECT DISTINCT ON (property.company_id, property.name)