Skip to content

Commit

Permalink
fix: handle stock entry warehouse correctly, fix scan in transfer sto… (
Browse files Browse the repository at this point in the history
  • Loading branch information
agritheory authored Sep 13, 2023
1 parent 08bc19b commit 886d8c6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions beam/beam/scan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def get_form_action(barcode_doc: frappe._dict, context: frappe._dict) -> list[di
hu_details = get_handling_unit(barcode_doc.doc.name, context.frm)
if context.frm == "Stock Entry":
target = get_stock_entry_item_details(context.doc, hu_details.item_code)
target.warehouse = hu_details.warehouse
elif context.frm in ("Putaway Rule", "Warranty Claim", "Item Price", "Quality Inspection"):
target = frappe._dict(
{
Expand Down
52 changes: 44 additions & 8 deletions beam/public/js/scan/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ class ScanHandler {
barcode_context.forEach(field => {
if (
!cur_frm.doc.items.some(row => {
if (
cur_frm.doc.doctype == 'Stock Entry' &&
[
'Send to Subcontractor',
'Material Transfer for Manufacture',
'Material Transfer',
'Material Receipt',
'Manufacture',
].includes(cur_frm.doc.stock_entry_type)
) {
return row.item_code == field.context.item_code || row.handling_unit
}
return (
(row.item_code == field.context.item_code && row.stock_qty == field.context.stock_qty) ||
row.handling_unit == field.context.handling_unit
Expand All @@ -104,14 +116,38 @@ class ScanHandler {
if (!cur_frm.doc.items.length || !cur_frm.doc.items[0].item_code) {
cur_frm.doc.items = []
}
cur_frm.add_child('items', field.context)
let child = cur_frm.add_child('items', field.context)
if (cur_frm.doc.doctype == 'Stock Entry') {
frappe.model.set_value(child.doctype, child.name, 's_warehouse', field.context.warehouse)
}
} else {
for (let row of cur_frm.doc.items) {
if (
cur_frm.doc.doctype == 'Stock Entry' &&
[
'Send to Subcontractor',
'Material Transfer for Manufacture',
'Material Transfer',
'Material Receipt',
'Manufacture',
].includes(cur_frm.doc.stock_entry_type) &&
row.item_code == field.context.item_code &&
!row.handling_unit
) {
frappe.model.set_value(row.doctype, row.name, field.field, field.target)
continue
}
if (
(row.item_code == field.context.item_code && row.stock_qty == field.context.stock_qty) ||
row.handling_unit == field.context.handling_unit
) {
frappe.model.set_value(row.doctype, row.name, field.field, field.target)
if (cur_frm.doc.doctype == 'Stock Entry') {
if ((field.field = 'basic_rate')) {
cur_frm.events.set_basic_rate(cur_frm, row.doctype, row.name)
} else {
frappe.model.set_value(row.doctype, row.name, field.field, field.target)
}
}
}
}
}
Expand All @@ -124,14 +160,14 @@ class ScanHandler {
} else {
return
}
const source_warehouses = [
'Send to Subcontractor',
'Material Consumption for Manufacture',
'Material Issue',
const source_warehouses = ['Material Consumption for Manufacture', 'Material Issue']
const target_warehouses = ['Material Receipt', 'Manufacture']
const both_warehouses = [
'Material Transfer for Manufacture',
'Material Transfer',
'Send to Subcontractor',
'Repack',
]
const target_warehouses = ['Material Transfer', 'Material Receipt', 'Manufacture']
const both_warehouses = ['Repack']
if (barcode_context.doctype == 'Stock Entry' && source_warehouses.includes(cur_frm.doc.stock_entry_type)) {
cur_frm.set_value('from_warehouse', barcode_context.target)
for (let row of cur_frm.doc.items) {
Expand Down

0 comments on commit 886d8c6

Please sign in to comment.