-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[ADD] barcode_scan: Added barcode scanning in SO/PO #849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hapt-odoo
wants to merge
2
commits into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-barcode-scan-hapt
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,14 @@ | ||
{ | ||
'name': "Barcode Scanning In SO/PO", | ||
'version': '0.1', | ||
'summary': 'Adds barcode scanning capabilities to product catalog', | ||
'depends': ['sale_management', 'stock_barcode', 'purchase'], | ||
'application': True, | ||
'installable': True, | ||
"assets": { | ||
'web.assets_backend': [ | ||
'barcode_scan/static/src/**/*', | ||
], | ||
}, | ||
'license': 'AGPL-3' | ||
} |
55 changes: 55 additions & 0 deletions
55
barcode_scan/static/src/product_catalog/kanban_controller.js
This file contains hidden or 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,55 @@ | ||
import { patch } from "@web/core/utils/patch"; | ||
import { rpc } from "@web/core/network/rpc"; | ||
import { useService, useBus } from "@web/core/utils/hooks"; | ||
import { ProductCatalogKanbanController } from "@product/product_catalog/kanban_controller"; | ||
|
||
patch(ProductCatalogKanbanController.prototype, { | ||
setup(){ | ||
super.setup(); | ||
this.orm = useService("orm"); | ||
this.barcodeService = useService("barcode"); | ||
useBus(this.barcodeService.bus, "barcode_scanned", (ev) => this.onBarcodeScannedHandler(ev.detail.barcode)); | ||
this.resModel = this.props.context.product_catalog_order_model; | ||
this.notification = useService("notification"); | ||
}, | ||
|
||
async onBarcodeScannedHandler(barcode) { | ||
const [product] = await this.orm.searchRead( | ||
"product.product", | ||
[["barcode", "=", barcode]], | ||
["id"], | ||
{ limit: 1 } | ||
); | ||
if (!product) { | ||
this.notification.add(("No product found with barcode: ") + barcode, { type: "danger" }); | ||
return; | ||
} | ||
|
||
const quantityFieldMap = { | ||
"sale.order": "product_uom_qty", | ||
"purchase.order": "product_qty", | ||
}; | ||
const productQuantity = quantityFieldMap[this.resModel]; | ||
if (!productQuantity) { | ||
this.notification.add("Unsupported model: " + this.resModel, { type: "danger" }); | ||
} | ||
|
||
const orderLines = await this.orm.searchRead( | ||
this.props.context.active_model, | ||
[["order_id", "=", this.props.context.order_id], | ||
["product_id", "=", product.id]], | ||
["id", productQuantity, "product_id"] | ||
); | ||
|
||
const existingQty = orderLines[0]?.[productQuantity] || 0; | ||
const finallyQuantity = existingQty + 1; | ||
await rpc("/product/catalog/update_order_line_info", { | ||
order_id: this.props.context.order_id, | ||
product_id: product.id, | ||
quantity: finallyQuantity, | ||
res_model: this.resModel, | ||
}); | ||
|
||
this.model.load(); | ||
} | ||
}); |
This file contains hidden or 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,36 @@ | ||
import { ProductCatalogKanbanModel } from "@product/product_catalog/kanban_model"; | ||
import { getFieldsSpec } from "@web/model/relational_model/utils"; | ||
import { rpc } from "@web/core/network/rpc"; | ||
|
||
export class CustomProductCatalogKanbanModel extends ProductCatalogKanbanModel { | ||
async _loadUngroupedList(config) { | ||
const ProductIds = await this.orm.search(config.resModel, config.domain); | ||
if (!ProductIds.length) { | ||
return { records: [], length: 0 }; | ||
} | ||
|
||
let orderLinesInfo = {}; | ||
if (config.context.order_id && config.context.product_catalog_order_model) { | ||
orderLinesInfo = await rpc("/product/catalog/order_lines_info", { | ||
order_id: config.context.order_id, | ||
product_ids: ProductIds, | ||
res_model: config.context.product_catalog_order_model, | ||
}); | ||
ProductIds.sort((a, b) => (orderLinesInfo[b].quantity || 0) - (orderLinesInfo[a].quantity || 0)); | ||
} | ||
|
||
const catalogPage = ProductIds.slice(config.offset, config.offset + config.limit); | ||
|
||
const kwargs = { | ||
specification: getFieldsSpec(config.activeFields, config.fields, config.context), | ||
}; | ||
|
||
const result = await this.orm.webSearchRead(config.resModel, [["id", "in", catalogPage]], kwargs); | ||
|
||
result.records.sort((a, b) => (orderLinesInfo[b.id].quantity || 0) - (orderLinesInfo[a.id].quantity || 0)); | ||
return { | ||
length: ProductIds.length, | ||
records: result.records, | ||
}; | ||
} | ||
} |
This file contains hidden or 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,11 @@ | ||
import { registry } from "@web/core/registry"; | ||
import { productCatalogKanbanView } from "@product/product_catalog/kanban_view"; | ||
import { CustomProductCatalogKanbanModel } from "./kanban_model"; | ||
|
||
export const customProductCatalogKanbanView = { | ||
...productCatalogKanbanView, | ||
Model: CustomProductCatalogKanbanModel, | ||
}; | ||
|
||
registry.category("views").remove("product_kanban_catalog"); | ||
registry.category("views").add("product_kanban_catalog", customProductCatalogKanbanView); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not { limit: 1 } ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If in any case there are more than 1 order line for any specific product, and if the limit: 1 is used, then the total quantity of the product will be shown wrong.