Skip to content

Commit

Permalink
[MIG] pos_lot_barcode: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenminhchien committed Nov 29, 2023
1 parent 770f844 commit 193aca5
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 300 deletions.
1 change: 1 addition & 0 deletions pos_lot_barcode/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Contributors
------------

- Akim Juillerat <akim.juillerat@camptocamp.com>
- Nguyen Minh Chien <chien@trobz.com>

Maintainers
-----------
Expand Down
12 changes: 9 additions & 3 deletions pos_lot_barcode/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
{
"name": "POS Lot Barcode",
"summary": "Scan barcode to enter lot/serial numbers",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"development_status": "Alpha",
"category": "Sales/Point of Sale",
"website": "https://github.com/OCA/pos",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"data": [
"security/ir.model.access.csv",
],
"depends": [
"point_of_sale",
],
"assets": {
"point_of_sale.assets": [
"pos_lot_barcode/static/src/js/**/*.js",
"point_of_sale._assets_pos": [
"pos_lot_barcode/static/src/js/**/*",
"pos_lot_barcode/static/src/xml/**/*.xml",
],
"web.assets_tests": [
"pos_lot_barcode/static/tests/tours/**/*",
],
},
}
1 change: 1 addition & 0 deletions pos_lot_barcode/readme/CONTRIBUTORS.md
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>\>
2 changes: 2 additions & 0 deletions pos_lot_barcode/security/ir.model.access.csv
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
1 change: 1 addition & 0 deletions pos_lot_barcode/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li>Akim Juillerat &lt;<a class="reference external" href="mailto:akim.juillerat&#64;camptocamp.com">akim.juillerat&#64;camptocamp.com</a>&gt;</li>
<li>Nguyen Minh Chien &lt;<a class="reference external" href="mailto:chien&#64;trobz.com">chien&#64;trobz.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
31 changes: 31 additions & 0 deletions pos_lot_barcode/static/src/js/Popups/EditListPopup.esm.js
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();
}
},
});
30 changes: 0 additions & 30 deletions pos_lot_barcode/static/src/js/Popups/EditListPopup.js

This file was deleted.

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 pos_lot_barcode/static/src/js/Popups/ErrorMultiLotBarcodePopup.js

This file was deleted.

66 changes: 66 additions & 0 deletions pos_lot_barcode/static/src/js/Screens/ProductScreen.esm.js
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;
},
});
Loading

0 comments on commit 193aca5

Please sign in to comment.