Skip to content

Commit 71320ff

Browse files
committed
[IMP] barcode_scan: On barcode scan ,product is added to catalog
On barcode scanning of any product, the product is added to the first page on a catalog based on the quantity added to a sale or purchase order.
1 parent 98b1db6 commit 71320ff

File tree

4 files changed

+56
-11
lines changed

4 files changed

+56
-11
lines changed

barcode_scan/__manifest__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
'name': "Barcode Scanning In SO/PO",
3-
'category': '',
43
'version': '0.1',
5-
'depends': ['product', 'barcodes', 'sale', 'web', 'stock_barcode', 'purchase'],
6-
'sequence': 1,
4+
'summary': 'Adds barcode scanning capabilities to product catalog',
5+
'depends': ['product','barcodes','sale_management','web','stock_barcode','purchase'],
76
'application': True,
87
'installable': True,
98
"assets": {

barcode_scan/static/src/js/kanban_controller.js renamed to barcode_scan/static/src/product_catalog/kanban_controller.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ patch(ProductCatalogKanbanController.prototype, {
2525
return;
2626
}
2727

28-
let productQuantity;
29-
if (this.resModel == "sale.order") {
30-
productQuantity = "product_uom_qty";
31-
} else if (this.resModel == "purchase.order") {
32-
productQuantity = "product_qty";
33-
} else {
34-
console.error("Model not found");
35-
return;
28+
const quantityFieldMap = {
29+
"sale.order": "product_uom_qty",
30+
"purchase.order": "product_qty",
31+
};
32+
const productQuantity = quantityFieldMap[this.resModel];
33+
if (!productQuantity) {
34+
this.notification.add("Unsupported model: " + this.resModel, { type: "danger" });
3635
}
3736

3837
const orderLines = await this.orm.searchRead(
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ProductCatalogKanbanModel } from "@product/product_catalog/kanban_model";
2+
import { getFieldsSpec } from "@web/model/relational_model/utils";
3+
import { rpc } from "@web/core/network/rpc";
4+
5+
export class CustomProductCatalogKanbanModel extends ProductCatalogKanbanModel {
6+
async _loadUngroupedList(config) {
7+
const ProductIds = await this.orm.search(config.resModel, config.domain);
8+
if (!ProductIds.length) {
9+
return { records: [], length: 0 };
10+
}
11+
12+
let orderLinesInfo = {};
13+
if (config.context.order_id && config.context.product_catalog_order_model) {
14+
orderLinesInfo = await rpc("/product/catalog/order_lines_info", {
15+
order_id: config.context.order_id,
16+
product_ids: ProductIds,
17+
res_model: config.context.product_catalog_order_model,
18+
});
19+
ProductIds.sort((a, b) => (orderLinesInfo[b].quantity || 0) - (orderLinesInfo[a].quantity || 0));
20+
}
21+
22+
const catalogPage = ProductIds.slice(config.offset, config.offset + config.limit);
23+
24+
const kwargs = {
25+
specification: getFieldsSpec(config.activeFields, config.fields, config.context),
26+
};
27+
28+
const result = await this.orm.webSearchRead(config.resModel, [["id", "in", catalogPage]], kwargs);
29+
30+
result.records.sort((a, b) => (orderLinesInfo[b.id].quantity || 0) - (orderLinesInfo[a.id].quantity || 0));
31+
return {
32+
length: ProductIds.length,
33+
records: result.records,
34+
};
35+
}
36+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { registry } from "@web/core/registry";
2+
import { productCatalogKanbanView } from "@product/product_catalog/kanban_view";
3+
import { CustomProductCatalogKanbanModel } from "./kanban_model";
4+
5+
export const customProductCatalogKanbanView = {
6+
...productCatalogKanbanView,
7+
Model: CustomProductCatalogKanbanModel,
8+
};
9+
10+
registry.category("views").remove("product_kanban_catalog");
11+
registry.category("views").add("product_kanban_catalog", customProductCatalogKanbanView);

0 commit comments

Comments
 (0)