[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) <vlst@odoo.com>
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-09-15 08:08:34 +00:00
parent 6cc1c435fd
commit bea0116aec
2 changed files with 5 additions and 3 deletions
+1 -1
View File
@@ -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,
@@ -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)