summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Caburnay <jcb@odoo.com>2021-05-25 09:26:16 +0000
committerJoseph Caburnay <jcb@odoo.com>2021-05-25 09:44:54 +0000
commitff58fb0fb588092f1d02500cd000d20a3f8b67b7 (patch)
tree2661bcd9dba584f1b985807f7c29888ceac247e9
parent02d9b51e43904420afe31e1f65ea455e3ed2c8ea (diff)
[FIX] point_of_sale: show pack lot input popup when scanning product
When scanned product is tracked by lot or SN, the popup that asks for lot should be shown, just like as when a tracked product is clicked from the product list. We accomplish this by introducing a new method that can be used both by `_clickProduct` and `_barcodeProductAction`, and by making the `_barcodeProductAction` be independent from `scan_product` method from `PosModel`. So instead of calling directly `scan_product`, we indentify the product first based on the barcode, then we call the newly introduced method to ask for the lot inputs, then we call `add_product` with proper options including the type of the parsed barcode. closes odoo/odoo#71209 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
-rw-r--r--addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js52
1 files changed, 36 insertions, 16 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 97daa35801d..6d3308ee3c3 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
@@ -62,11 +62,7 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
return true;
return false;
}
- async _clickProduct(event) {
- if (!this.currentOrder) {
- this.env.pos.add_new_order();
- }
- const product = event.detail;
+ async _getAddProductOptions(product) {
let price_extra = 0.0;
let draftPackLotLines, weight, description, packLotLinesToEdit;
@@ -141,14 +137,18 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
}
}
+ return { draftPackLotLines, quantity: weight, description, price_extra };
+ }
+ async _clickProduct(event) {
+ if (!this.currentOrder) {
+ this.env.pos.add_new_order();
+ }
+ const product = event.detail;
+ const options = await this._getAddProductOptions(product);
+ // Do not add product if options is undefined.
+ if (!options) return;
// Add the product after having the extra information.
- this.currentOrder.add_product(product, {
- draftPackLotLines,
- description: description,
- price_extra: price_extra,
- quantity: weight,
- });
-
+ this.currentOrder.add_product(product, options);
NumberBuffer.reset();
}
_setNumpadMode(event) {
@@ -203,11 +203,31 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
}
}
}
- _barcodeProductAction(code) {
- // NOTE: scan_product call has side effect in pos if it returned true.
- if (!this.env.pos.scan_product(code)) {
- this._barcodeErrorAction(code);
+ async _barcodeProductAction(code) {
+ const product = this.env.pos.db.get_product_by_barcode(code.base_code)
+ if (!product) {
+ return this._barcodeErrorAction(code);
+ }
+ const options = await this._getAddProductOptions(product);
+ // Do not proceed on adding the product when no options is returned.
+ // This is consistent with _clickProduct.
+ if (!options) return;
+
+ // update the options depending on the type of the scanned code
+ if (code.type === 'price') {
+ Object.assign(options, { price: code.value });
+ } else if (code.type === 'weight') {
+ Object.assign(options, {
+ quantity: code.value,
+ merge: false,
+ });
+ } else if (code.type === 'discount') {
+ Object.assign(options, {
+ discount: code.value,
+ merge: false,
+ });
}
+ this.currentOrder.add_product(product, options)
}
_barcodeClientAction(code) {
const partner = this.env.pos.db.get_partner_by_barcode(code.code);