[FIX] point_of_sale: use partner invoicing address

Currently, when generating the invoice from the PoS shop, the invoicing address of the partner is not used. This differs from the invoice created using the sale app which uses the invoice address.

Steps to reproduce:
-------------------
* Go to the **Contacts** app
* Select any contact (ex: Azure Interior)
* Under **Contacts & Addresses** select Add
* Select **Invoice Address**
* Write the address then **Save & Close**
* Go to the **Point of Sale** app
* Add items
* For customer, select the contact we just modified
* Select **Payment**
* Select any payment method
* Select **Invoice**
* Validate
> Observation: The invoice address is not used

Why the fix:
------------
We observe a discrepancy between the sale and pos output for the same workflow.
* Sale
  * Sale order form: `Customer` -> Azure interior (Has a field for invoice address)
  * Account move form: `Customer` -> Azure interior, Az inv (Use the invoice address)
* PoS
  * PoS order form: `Customer` -> Azure interior (Does not have a field for invoice address)
  * Account move form: `Customer` -> Azure interior

In stable we can't add the invoice address on the PoS order form but we can still stay consistent with the sale workflow in terms of account move.

In the sale workflow, the move is created with `invoice_vals_list`
https://github.com/odoo/odoo/blob/d6973d3cd5ee48539b40f94b8444f5522a080438/addons/sale/models/sale_order.py#L1207

Having a look at `invoice_vals_list`, we can see that the customer_id is set using the invoice contact address.
https://github.com/odoo/odoo/blob/d6973d3cd5ee48539b40f94b8444f5522a080438/addons/sale/models/sale_order.py#L1004

With `partner_invoice_id` computed as follows:
https://github.com/odoo/odoo/blob/d6973d3cd5ee48539b40f94b8444f5522a080438/addons/sale/models/sale_order.py#L340-L342

Thus, we also send the invoicing contact address as partner_id when creating the move in pos;

opw-3797434

closes odoo/odoo#160154

X-original-commit: ab904c7e06f481f28cd581b9e677d0db9bf608f1
Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com>
This commit is contained in:
Sarah Bellefroid
2024-04-03 07:19:49 +00:00
parent 5041bb16b8
commit ac0837c21a
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -662,7 +662,7 @@ class PosOrder(models.Model):
'journal_id': self.session_id.config_id.invoice_journal_id.id,
'move_type': 'out_invoice' if self.amount_total >= 0 else 'out_refund',
'ref': self.name,
'partner_id': self.partner_id.id,
'partner_id': self.partner_id.address_get(['invoice'])['invoice'],
'partner_bank_id': self._get_partner_bank_id(),
'currency_id': self.currency_id.id,
'invoice_user_id': self.user_id.id,
@@ -543,6 +543,13 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
def test_order_to_invoice(self):
invoice_partner_address = self.env["res.partner"].create({
'name': "Test invoice address",
'street': "Invoice Street",
'type': 'invoice',
'parent_id': self.partner1.id,
})
self.pos_config.open_ui()
current_session = self.pos_config.current_session_id
@@ -597,6 +604,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
# I generate an invoice from the order
res = self.pos_order_pos1.action_pos_order_invoice()
self.assertIn('res_id', res, "Invoice should be created")
self.assertEqual(self.pos_order_pos1.account_move.partner_id.id, invoice_partner_address.id, "Invoice address should be used")
# I test that the total of the attached invoice is correct
invoice = self.env['account.move'].browse(res['res_id'])