Skip to content
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

[New Feature]Scan Item Barcode label to quick create/update records in items child table #15731

Merged
merged 17 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion erpnext/accounts/doctype/purchase_invoice/purchase_invoice.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
Expand Down Expand Up @@ -1551,6 +1552,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "scan_barcode",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Scan Barcode",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 1,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -4593,7 +4626,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2018-09-11 14:44:31.220376",
"modified": "2018-10-18 04:43:39.792967",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",
Expand Down
35 changes: 34 additions & 1 deletion erpnext/accounts/doctype/sales_invoice/sales_invoice.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
Expand Down Expand Up @@ -1651,6 +1652,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "scan_barcode",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Scan Barcode",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 1,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -5546,7 +5579,7 @@
"istable": 0,
"max_attachments": 0,
"menu_index": 0,
"modified": "2018-09-07 14:24:58.854289",
"modified": "2018-10-18 04:43:08.998164",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
Expand Down
37 changes: 35 additions & 2 deletions erpnext/buying/doctype/purchase_order/purchase_order.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
Expand Down Expand Up @@ -1386,6 +1387,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "scan_barcode",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Scan Barcode",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 1,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -3736,8 +3769,8 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-08-29 12:16:12.886021",
"modified_by": "nabinhait@gmail.com",
"modified": "2018-10-18 04:40:58.392537",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order",
"owner": "Administrator",
Expand Down
56 changes: 56 additions & 0 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,62 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
this.set_dynamic_labels();
this.setup_sms();
this.setup_quality_inspection();
this.frm.fields_dict["scan_barcode"] && this.frm.fields_dict["scan_barcode"].set_value("");
this.frm.fields_dict["scan_barcode"] && this.frm.fields_dict["scan_barcode"].set_new_description("");
},

scan_barcode: function() {
let scan_barcode_field = this.frm.fields_dict["scan_barcode"];

let show_description = function(idx, item_code, exist=null) {
if(exist) {
scan_barcode_field.set_new_description(__('Row : ') + idx + ' ' +
item_code + __(' Qty increased by 1'));
} else {
scan_barcode_field.set_new_description(__('New row : ') + idx + ' ' +
item_code + __(' Created'));
}
}

if(this.frm.doc.scan_barcode) {
frappe.call({
method: "erpnext.selling.page.point_of_sale.point_of_sale.search_serial_or_batch_or_barcode_number",
args: { search_value: this.frm.doc.scan_barcode }
}).then(r => {

if(r && r.message && r.message.item_code) {
let child = "";
let add_row_index = -1;
let cur_grid= this.frm.fields_dict["items"].grid;

this.frm.doc.items.map(d => {
if(d.item_code==r.message.item_code){
add_row_index = d.idx;
return;
} else if(!d.item_code && add_row_index==-1) {
add_row_index = d.idx;
}
});

if(add_row_index == -1) {
child = frappe.model.add_child(this.frm.doc, cur_grid.doctype, "items", add_row_index);
} else {
child = cur_grid.get_grid_row(add_row_index-1).doc;
}
show_description(child.idx, r.message.item_code, child.item_code);

frappe.model.set_value(child.doctype, child.name, {
"item_code": r.message.item_code,
"qty": (child.qty || 0) + 1
});
}
else{
scan_barcode_field.set_new_description(this.frm.doc.scan_barcode +__(' does not exist!'));
}
});
scan_barcode_field.set_value("");
}
return false;
},

apply_default_taxes: function() {
Expand Down
35 changes: 34 additions & 1 deletion erpnext/selling/doctype/sales_order/sales_order.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
Expand Down Expand Up @@ -1204,6 +1205,38 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "scan_barcode",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Scan Barcode",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 1,
"allow_in_quick_entry": 0,
Expand Down Expand Up @@ -3918,7 +3951,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-08-21 14:44:44.011356",
"modified": "2018-10-18 04:41:28.111144",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order",
Expand Down
40 changes: 23 additions & 17 deletions erpnext/selling/page/point_of_sale/point_of_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@

@frappe.whitelist()
def get_items(start, page_length, price_list, item_group, search_value="", pos_profile=None):
serial_no = ""
batch_no = ""
barcode = ""
data = dict()
warehouse = ""
display_items_in_stock = 0
item_code = search_value

if pos_profile:
warehouse, display_items_in_stock = frappe.db.get_value('POS Profile', pos_profile, ['warehouse', 'display_items_in_stock'])
Expand All @@ -25,20 +22,12 @@ def get_items(start, page_length, price_list, item_group, search_value="", pos_p
item_group = get_root_of('Item Group')

if search_value:
# search serial no
serial_no_data = frappe.db.get_value('Serial No', search_value, ['name', 'item_code'])
if serial_no_data:
serial_no, item_code = serial_no_data
data = search_serial_or_batch_or_barcode_number(search_value)

if not serial_no:
batch_no_data = frappe.db.get_value('Batch', search_value, ['name', 'item'])
if batch_no_data:
batch_no, item_code = batch_no_data

if not serial_no and not batch_no:
barcode_data = frappe.db.get_value('Item Barcode', {'barcode': search_value}, ['parent', 'barcode'])
if barcode_data:
item_code, barcode = barcode_data
item_code = data.get("item_code") if data.get("item_code") else search_value
serial_no = data.get("serial_no") if data.get("serial_no") else ""
batch_no = data.get("batch_no") if data.get("batch_no") else ""
barcode = data.get("barcode") if data.get("barcode") else ""

item_code, condition = get_conditions(item_code, serial_no, batch_no, barcode)

Expand Down Expand Up @@ -119,6 +108,23 @@ def get_items(start, page_length, price_list, item_group, search_value="", pos_p

return res

@frappe.whitelist()
def search_serial_or_batch_or_barcode_number(search_value):
# search barcode no
barcode_data = frappe.db.get_value('Item Barcode', {'barcode': search_value}, ['barcode', 'parent as item_code'], as_dict=True)
if barcode_data:
return barcode_data

# search serial no
serial_no_data = frappe.db.get_value('Serial No', search_value, ['name as serial_no', 'item_code'], as_dict=True)
if serial_no_data:
Zlash65 marked this conversation as resolved.
Show resolved Hide resolved
return serial_no_data

# search batch no
batch_no_data = frappe.db.get_value('Batch', search_value, ['name as batch_no', 'item as item_code'], as_dict=True)
if batch_no_data:
return batch_no_data

def get_conditions(item_code, serial_no, batch_no, barcode):
if serial_no or batch_no or barcode:
return frappe.db.escape(item_code), "i.name = %(item_code)s"
Expand Down
Loading