Skip to content

Commit

Permalink
fix: barcode not fetched on selection of item
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Apr 2, 2024
1 parent 8e52218 commit b073029
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
10 changes: 9 additions & 1 deletion erpnext/stock/doctype/item/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
test_dependencies = ["Warehouse", "Item Group", "Item Tax Template", "Brand", "Item Attribute"]


def make_item(item_code=None, properties=None, uoms=None):
def make_item(item_code=None, properties=None, uoms=None, barcode=None):
if not item_code:
item_code = frappe.generate_hash(length=16)

Expand Down Expand Up @@ -61,6 +61,14 @@ def make_item(item_code=None, properties=None, uoms=None):
for uom in uoms:
item.append("uoms", uom)

if barcode:
item.append(
"barcodes",
{
"barcode": barcode,
},
)

item.insert()

return item
Expand Down
14 changes: 13 additions & 1 deletion erpnext/stock/doctype/stock_entry/stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
OpeningEntryAccountError,
)
from erpnext.stock.get_item_details import (
get_barcode_data,
get_bin_details,
get_conversion_factor,
get_default_cost_center,
Expand Down Expand Up @@ -428,7 +429,14 @@ def validate_item(self):
for field in reset_fields:
item.set(field, item_details.get(field))

update_fields = ("uom", "description", "expense_account", "cost_center", "conversion_factor")
update_fields = (
"uom",
"description",
"expense_account",
"cost_center",
"conversion_factor",
"barcode",
)

for field in update_fields:
if not item.get(field):
Expand Down Expand Up @@ -1634,6 +1642,10 @@ def get_item_details(self, args=None, for_update=False):
if subcontract_items and len(subcontract_items) == 1:
ret["subcontracted_item"] = subcontract_items[0].main_item_code

barcode_data = get_barcode_data(item_code=item.name)
if barcode_data and len(barcode_data.get(item.name)) == 1:
ret["barcode"] = barcode_data.get(item.name)[0]

return ret

@frappe.whitelist()
Expand Down
6 changes: 6 additions & 0 deletions erpnext/stock/doctype/stock_entry/test_stock_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def test_auto_material_request(self):
self._test_auto_material_request("_Test Item")
self._test_auto_material_request("_Test Item", material_request_type="Transfer")

def test_barcode_item_stock_entry(self):
item_code = make_item("_Test Item Stock Entry For Barcode", barcode="BDD-1234567890")

se = make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1, basic_rate=100)
self.assertEqual(se.items[0].barcode, "BDD-1234567890")

def test_auto_material_request_for_variant(self):
fields = [{"field_name": "reorder_levels"}]
set_item_variant_settings(fields)
Expand Down
19 changes: 19 additions & 0 deletions erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ frappe.ui.form.on("Stock Reconciliation", {
if (frm.doc.company) {
frm.trigger("toggle_display_account_head");
}

frm.events.set_fields_onload_for_line_item(frm);
},

set_fields_onload_for_line_item(frm) {
if (frm.is_new() && frm.doc?.items && cint(frappe.user_defaults?.use_serial_batch_fields) === 1) {
frm.doc.items.forEach((item) => {
if (!item.serial_and_batch_bundle) {
frappe.model.set_value(item.doctype, item.name, "use_serial_batch_fields", 1);
}
});
}
},

scan_barcode: function (frm) {
Expand Down Expand Up @@ -155,6 +167,9 @@ frappe.ui.form.on("Stock Reconciliation", {

item.qty = item.qty || 0;
item.valuation_rate = item.valuation_rate || 0;
item.use_serial_batch_fields = cint(
frappe.user_defaults?.use_serial_batch_fields
);
});
frm.refresh_field("items");
},
Expand Down Expand Up @@ -298,6 +313,10 @@ frappe.ui.form.on("Stock Reconciliation Item", {
if (!item.warehouse && frm.doc.set_warehouse) {
frappe.model.set_value(cdt, cdn, "warehouse", frm.doc.set_warehouse);
}

if (item.docstatus === 0 && cint(frappe.user_defaults?.use_serial_batch_fields) === 1) {
frappe.model.set_value(item.doctype, item.name, "use_serial_batch_fields", 1);
}
},

add_serial_batch_bundle(frm, cdt, cdn) {
Expand Down
11 changes: 10 additions & 1 deletion erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,21 @@ def update_barcode_value(out):
out["barcode"] = barcode_data.get(out.item_code)[0]


def get_barcode_data(items_list):
def get_barcode_data(items_list=None, item_code=None):
# get item-wise batch no data
# example: {'LED-GRE': [Batch001, Batch002]}
# where LED-GRE is item code, SN0001 is serial no and Pune is warehouse

itemwise_barcode = {}
if not items_list and item_code:
_dict_item_code = frappe._dict(
{
"item_code": item_code,
}
)

items_list = [frappe._dict(_dict_item_code)]

for item in items_list:
barcodes = frappe.db.get_all("Item Barcode", filters={"parent": item.item_code}, fields="barcode")

Expand Down

0 comments on commit b073029

Please sign in to comment.