[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#71496 X-original-commit: 4383cacefd01a318df70857cddf5aedda7011318 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
@@ -60,11 +60,7 @@ odoo.define('point_of_sale.ProductScreen', function(require) {
|
||||
get currentOrder() {
|
||||
return this.env.pos.get_order();
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -139,14 +135,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) {
|
||||
@@ -201,11 +201,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);
|
||||
|
||||
Reference in New Issue
Block a user