From 29cd049268a25150c467e3ad13b08c5a478be636 Mon Sep 17 00:00:00 2001
From: Adrien Widart <awt@odoo.com>
Date: Tue, 7 Sep 2021 08:10:39 +0000
Subject: [PATCH] [FIX] point_of_sale: consider scanned price as manual price

In a POS session, when using the scanner, if the seller changes the
customer, the prices may become incorrect

To reproduce the issue
1. Create a product P:
    - Sales Price: 38
    - Barcode: 2312345000002
    - Available in POS: True
2. Start a POS session (with debug Window)
3. Scan 2312345010001
    - This is product P with price $10
4. Set a Customer

Error: The price is now $38

Because the price has not been set manually, when changing the customer,
the pricelist is updated and so does the price.

When scanning a barcode that includes a price, the latter should be
considered as manually set.

OPW-2618934

closes odoo/odoo#76076

X-original-commit: e66724272a5379c5d56f8fe48fa48ceac53cf12d
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Signed-off-by: Adrien Widart <adwid@users.noreply.github.com>
---
 .../static/src/js/Screens/ProductScreen/ProductScreen.js   | 7 ++++++-
 addons/point_of_sale/static/src/js/models.js               | 2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js
index 65daa7cc17a8..3123ad178bcf 100644
--- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js
+++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js
@@ -215,7 +215,12 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
 
             // update the options depending on the type of the scanned code
             if (code.type === 'price') {
-                Object.assign(options, { price: code.value });
+                Object.assign(options, {
+                    price: code.value,
+                    extras: {
+                        price_manually_set: true,
+                    },
+                });
             } else if (code.type === 'weight') {
                 Object.assign(options, {
                     quantity: code.value,
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 8c1242f794e6..bd9a9f230e53 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -1195,7 +1195,7 @@ exports.PosModel = Backbone.Model.extend({
         }
 
         if(parsed_code.type === 'price'){
-            selectedOrder.add_product(product, {price:parsed_code.value});
+            selectedOrder.add_product(product, {price:parsed_code.value, extras:{price_manually_set: true}});
         }else if(parsed_code.type === 'weight'){
             selectedOrder.add_product(product, {quantity:parsed_code.value, merge:false});
         }else if(parsed_code.type === 'discount'){
-- 
GitLab