Skip to content

Commit 49d0d87

Browse files
committed
[FIX] point_of_sale: update partner self invoice
When doing a self invoice with the QR code on the PoS receipt, if a partner was linked to the order, the record would not be updated with the values entered in the self invoice form. Steps to reproduce: ------------------- * Enable the self service invoice feature in the PoS settings. * Open a PoS session. * Make and order with a partner set on it. * Finalize the order and scan the QRCode on the receipt. * Fill the form with some new informations (like a new VAT number) > Observation: Check the partner on the backend, the values are not updated. Why the fix: ------------ We update all the mandatory and optionnal fields of the partner record with the values entered in the self invoice form. opw-4676244 closes odoo#214552 Signed-off-by: David Monnom (moda) <[email protected]>
1 parent b74dba3 commit 49d0d87

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

addons/point_of_sale/controllers/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def _parse_additional_values(fields, prefix, kwargs):
225225
def _get_invoice(self, partner_values, invoice_values, pos_order, additional_invoice_fields, kwargs):
226226
# If the user is not connected, then we will simply create a new partner with the form values.
227227
# Matching with existing partner was tried, but we then can't update the values, and it would force the user to use the ones from the first invoicing.
228-
if request.env.user._is_public() and not pos_order.partner_id.id:
228+
if kwargs:
229229
partner_values.update({key: kwargs[key] for key in self._get_mandatory_fields()})
230230
partner_values.update({key: kwargs[key] for key in self._get_optional_fields() if key in kwargs})
231231
for field in {'country_id', 'state_id'} & set(partner_values.keys()):
@@ -234,6 +234,7 @@ def _get_invoice(self, partner_values, invoice_values, pos_order, additional_inv
234234
except Exception:
235235
partner_values[field] = False
236236
partner_values.update({'zip': partner_values.pop('zipcode', '')})
237+
if request.env.user._is_public() and not pos_order.partner_id.id:
237238
partner = request.env['res.partner'].sudo().create(partner_values) # In this case, partner_values contains the whole partner info form.
238239
# If the user is connected, then we can update if needed its fields with the additional localized fields if any, then proceed.
239240
else:

addons/point_of_sale/tests/test_pos_controller.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,56 @@ def test_qr_code_receipt_user_connected(self):
108108
res = self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', timeout=30000)
109109
self.assertTrue(self.pos_order.is_invoiced, "The pos order should have an invoice")
110110
self.assertTrue("my/invoices" in res.url)
111+
112+
def test_qr_code_receipt_user_updated(self):
113+
"""This test make sure that when the user is already connected he correctly gets redirected to the invoice."""
114+
self.authenticate(None, None)
115+
self.partner_1 = self.env['res.partner'].create({
116+
'name': 'Valid Lelitre',
117+
'email': '[email protected]',
118+
})
119+
120+
self.product1 = self.env['product.product'].create({
121+
'name': 'Test Product 1',
122+
'is_storable': True,
123+
'list_price': 10.0,
124+
'taxes_id': False,
125+
})
126+
self.main_pos_config.open_ui()
127+
self.pos_order = self.env['pos.order'].create({
128+
'session_id': self.main_pos_config.current_session_id.id,
129+
'company_id': self.env.company.id,
130+
'partner_id': self.partner_1.id,
131+
'access_token': '1234567890',
132+
'lines': [(0, 0, {
133+
'name': "OL/0001",
134+
'product_id': self.product1.id,
135+
'price_unit': 10,
136+
'discount': 0.0,
137+
'qty': 1.0,
138+
'tax_ids': False,
139+
'price_subtotal': 10,
140+
'price_subtotal_incl': 10,
141+
})],
142+
'amount_tax': 10,
143+
'amount_total': 10,
144+
'amount_paid': 10.0,
145+
'amount_return': 10.0,
146+
})
147+
self.main_pos_config.current_session_id.close_session_from_ui()
148+
get_invoice_data = {
149+
'access_token': self.pos_order.access_token,
150+
'name': 'New Name',
151+
'email': "[email protected]",
152+
'vat': 'VAT_TEST_NUMBER_123',
153+
'street': "Test street",
154+
'city': "Test City",
155+
'zipcode': '12345',
156+
'country_id': self.company.country_id.id,
157+
'phone': "123456789",
158+
'csrf_token': odoo.http.Request.csrf_token(self)
159+
}
160+
self.url_open(f'/pos/ticket/validate?access_token={self.pos_order.access_token}', data=get_invoice_data, timeout=30000)
161+
self.assertEqual(self.partner_1.vat, 'VAT_TEST_NUMBER_123')
162+
self.assertEqual(self.partner_1.name, 'New Name')
163+
self.assertEqual(self.partner_1.zip, '12345')

0 commit comments

Comments
 (0)