-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] pos_lot_barcode: Migration to 17.0
- Loading branch information
1 parent
770f844
commit 193aca5
Showing
15 changed files
with
267 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
- Akim Juillerat \<<akim.juillerat@camptocamp.com>\> | ||
- Nguyen Minh Chien \<<chien@trobz.com>\> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
access_pos_lot_user,stock.lot pos user,stock.model_stock_lot,point_of_sale.group_pos_user,1,0,0,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** @odoo-module */ | ||
|
||
/* | ||
Copyright 2022 Camptocamp SA | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
*/ | ||
|
||
import {EditListPopup} from "@point_of_sale/app/store/select_lot_popup/select_lot_popup"; | ||
import {_t} from "@web/core/l10n/translation"; | ||
import {patch} from "@web/core/utils/patch"; | ||
import {useBarcodeReader} from "@point_of_sale/app/barcode/barcode_reader_hook"; | ||
|
||
patch(EditListPopup.prototype, { | ||
setup() { | ||
super.setup(...arguments); | ||
useBarcodeReader( | ||
{ | ||
lot: this._lotScanned, | ||
}, | ||
true | ||
); | ||
}, | ||
|
||
_lotScanned(code) { | ||
// Check we are on lot/SN selection popup | ||
if (this.props.title === _t("Lot/Serial Number(s) Required")) { | ||
this.state.array.push({text: code.code, _id: this._nextId()}); | ||
this.confirm(); | ||
} | ||
}, | ||
}); |
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
pos_lot_barcode/static/src/js/Popups/ErrorMultiLotBarcodePopup.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** @odoo-module */ | ||
|
||
/* | ||
Copyright 2022 Camptocamp SA | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
*/ | ||
import {ErrorBarcodePopup} from "@point_of_sale/app/barcode/error_popup/barcode_error_popup"; | ||
import {_lt} from "@web/core/l10n/translation"; | ||
|
||
export class ErrorMultiLotBarcodePopup extends ErrorBarcodePopup {} | ||
ErrorMultiLotBarcodePopup.template = "pos_lot_barcode.ErrorMultiLotBarcodePopup"; | ||
ErrorMultiLotBarcodePopup.defaultProps = { | ||
confirmText: _lt("Ok"), | ||
cancelText: _lt("Cancel"), | ||
title: _lt("Error"), | ||
body: "", | ||
message: _lt( | ||
"The Point of Sale can not process the scanned barcode, as it matches multiple products:" | ||
), | ||
}; |
31 changes: 0 additions & 31 deletions
31
pos_lot_barcode/static/src/js/Popups/ErrorMultiLotBarcodePopup.js
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
pos_lot_barcode/static/src/js/Screens/ProductScreen.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** @odoo-module **/ | ||
|
||
/* | ||
Copyright 2022 Camptocamp SA | ||
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) | ||
*/ | ||
import {ErrorBarcodePopup} from "@point_of_sale/app/barcode/error_popup/barcode_error_popup"; | ||
import {ErrorMultiLotBarcodePopup} from "@pos_lot_barcode/js/Popups/ErrorMultiLotBarcodePopup.esm"; | ||
import {ProductScreen} from "@point_of_sale/app/screens/product_screen/product_screen"; | ||
import {patch} from "@web/core/utils/patch"; | ||
import {useBarcodeReader} from "@point_of_sale/app/barcode/barcode_reader_hook"; | ||
|
||
patch(ProductScreen.prototype, { | ||
setup() { | ||
super.setup(); | ||
useBarcodeReader({ | ||
lot: this._barcodeLotAction, | ||
}); | ||
}, | ||
async _barcodeLotAction(code) { | ||
// Get the product according to lot barcode | ||
const product = await this._getProductByLotBarcode(code); | ||
// If we didn't get a product it must display a popup | ||
if (!product) { | ||
return this.popup.add(ErrorBarcodePopup, {code: code.base_code}); | ||
} | ||
if (product instanceof Array) { | ||
// If we found more than a single lot in backend, raise error | ||
return this.popup.add(ErrorMultiLotBarcodePopup, { | ||
code: code.base_code, | ||
products: product.map((lot) => lot.product_id[1]), | ||
}); | ||
} | ||
// Get possible options not linked to lot selection | ||
const options = await product.getAddProductOptions(code); | ||
// Do not proceed on adding the product when no options is returned. | ||
// This is consistent with _clickProduct. | ||
if (!options) return; | ||
this.currentOrder.add_product(product, options); | ||
}, | ||
async _getProductByLotBarcode(base_code) { | ||
const foundLotIds = await this._searchLotProduct(base_code.code); | ||
if (foundLotIds.length === 1) { | ||
let product = this.pos.db.get_product_by_id(foundLotIds[0].product_id[0]); | ||
if (!product) { | ||
// If product is not loaded in POS, load it | ||
await this.pos._addProducts([foundLotIds[0].product_id[0]]); | ||
// Assume that the result is unique. | ||
product = this.pos.db.get_product_by_id(foundLotIds[0].product_id[0]); | ||
} | ||
return product; | ||
} else if (foundLotIds.length > 1) { | ||
return foundLotIds; | ||
} | ||
return false; | ||
}, | ||
async _searchLotProduct(code) { | ||
const foundLotIds = await this.orm.silent.call("stock.lot", "search_read", [], { | ||
domain: [["name", "=", code]], | ||
fields: ["id", "product_id"], | ||
order: "id desc", | ||
limit: 2, | ||
}); | ||
return foundLotIds; | ||
}, | ||
}); |
Oops, something went wrong.