[FIX] account: Create multiple invoices with correct account

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) <flg@odoo.com>
Signed-off-by: Matheus Leal Viana (malv) <malv@odoo.com>
This commit is contained in:
Matheus Leal Viana (malv)
2023-07-25 21:22:51 +02:00
parent b6652e7d01
commit ebdb317a98
+2 -2
View File
@@ -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)