From bea0116aecad8dbf3f4e05f0c0f56ffba4e39c54 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Mon, 11 Sep 2023 11:12:30 +0000 Subject: [PATCH] [FIX] point_of_sale: use correct partner_id for invoiced orders Current behavior: When invoicing an order that was made in a closed PoS session, the wrong partner was used for the invoice. And so the total due was assigned to the wrong partner if you used the "Customer Account" payment method. Steps to reproduce: - Open PoS and make an order for a customer using the Customer Account payment method. - Close the PoS session. - Open the PoS session again, and invoice the order you made in the previous session. Fix: Use the commercial_partner_id of the order's partner instead of the partner_id directly. opw-3478670 closes odoo/odoo#135558 X-original-commit: a7ebb5151060f9435941b9da50182e4ec5b58db7 Signed-off-by: Vlad Stroia (vlst) Signed-off-by: Robin Engels (roen) --- addons/point_of_sale/models/pos_order.py | 2 +- addons/point_of_sale/tests/test_point_of_sale_flow.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index c9eb9256faf..6d902f0a415 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -805,7 +805,7 @@ class PosOrder(models.Model): aml_vals_entry_found[0]['balance'] += payment_id.amount else: aml_vals_list_per_nature['payment_terms'].append({ - 'partner_id': self.partner_id.id if is_split_transaction else False, + 'partner_id': commercial_partner.id if is_split_transaction else False, 'name': f"{reversed_move_receivable_account_id.code} {reversed_move_receivable_account_id.code}", 'account_id': reversed_move_receivable_account_id.id, 'currency_id': self.currency_id.id, diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index a272a7813f0..e5b97b17311 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -1542,6 +1542,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'type': 'product', 'categ_id': self.env.ref('product.product_category_all').id, }) + self.partner1.write({'parent_id': self.env['res.partner'].create({'name': 'Parent'}).id}) #add customer account payment method to pos config self.pos_config.write({ @@ -1601,8 +1602,9 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): #check that both use the same account self.assertEqual(len(reverser_customer_payment_entry), 2) - self.assertEqual(reverser_customer_payment_entry.filtered(lambda l: l.partner_id).balance, -4.0) - self.assertEqual(reverser_customer_payment_entry.filtered(lambda l: not l.partner_id).balance, -2.0) + self.assertTrue(order.account_move.line_ids.partner_id == self.partner1.commercial_partner_id) + self.assertEqual(reverser_customer_payment_entry[0].balance, -2.0) + self.assertEqual(reverser_customer_payment_entry[1].balance, -4.0) self.assertEqual(original_customer_payment_entry.account_id.id, reverser_customer_payment_entry.account_id.id) self.assertEqual(reverser_customer_payment_entry.partner_id, original_customer_payment_entry.partner_id)