From 1bfcbe4b3c80fcdca3ca148e0d9685e3e723e7eb Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Thu, 21 Nov 2019 09:25:17 +0000 Subject: [PATCH] [FIX] point_of_sale: duplicate orders When you create a pos order, it is possible that the request timeout or the client loose the connection with the server, that will lead to not have the server_id of the order sent to the server. So when the client will try to synchronize the order again, it'll not send the server_id to the server, and the server will create a new order which is a duplicate of the one created when the client lost the connection. To avoid this duplication, we are using the pos_reference to find if there is an existing order like in 12.0 to avoid duplication. closes odoo/odoo#40837 Task-id: 2127656 X-original-commit: cddf29e70008dc1fcb6ec41b4dfc739d4d06cf6d Signed-off-by: Nicolas Martinelli (nim) --- addons/point_of_sale/models/pos_order.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 472c9fb802b..22d924dcfc6 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -435,8 +435,9 @@ class PosOrder(models.Model): for order in orders: existing_order = False if 'server_id' in order['data']: - existing_order = self.env['pos.order'].search([('id', '=', order['data']['server_id'])], limit=1) - order_ids.append(self._process_order(order, draft, existing_order)) + existing_order = self.env['pos.order'].search(['|', ('id', '=', order['data']['server_id']), ('pos_reference', '=', order['data']['name'])], limit=1) + if (existing_order and existing_order.state == 'draft') or not existing_order: + order_ids.append(self._process_order(order, draft, existing_order)) return self.env['pos.order'].search_read(domain = [('id', 'in', order_ids)], fields = ['id', 'pos_reference'])