From af0d6378f1e8b22d97bc34de4abdd9d891835001 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sun, 13 Nov 2016 21:19:09 +0530 Subject: [PATCH 1/2] [Fix] Fetch Serial No by default for Delivery Note Item --- .../doctype/pricing_rule/pricing_rule.py | 16 +++++++-- erpnext/public/js/controllers/transaction.js | 4 ++- erpnext/selling/sales_common.js | 6 ++-- .../stock/doctype/stock_entry/stock_entry.js | 2 +- .../stock/doctype/stock_entry/stock_entry.py | 17 ++------- erpnext/stock/get_item_details.py | 36 ++++++++++++++++--- 6 files changed, 55 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index f298bc88f9..11bf9453b9 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -11,6 +11,7 @@ from frappe import throw, _ from frappe.utils import flt, cint from frappe.model.document import Document + class MultiplePricingRuleConflict(frappe.ValidationError): pass class PricingRule(Document): @@ -113,8 +114,19 @@ def apply_pricing_rule(args): args_copy = copy.deepcopy(args) args_copy.update(item) out.append(get_pricing_rule_for_item(args_copy)) - + out.append(get_serial_no_for_item(args_copy)) return out + +def get_serial_no_for_item(args): + from erpnext.stock.get_item_details import get_serial_no + item_details = frappe._dict({ + "doctype": args.doctype, + "name": args.name, + "serial_no": args.serial_no + }) + if args.get("parenttype") in ("Sales Invoice", "Delivery Note"): + item_details.serial_no = get_serial_no(args) + return item_details def get_pricing_rule_for_item(args): if args.get("parenttype") == "Material Request": return {} @@ -311,4 +323,4 @@ def set_transaction_type(args): elif args.customer: args.transaction_type = "selling" else: - args.transaction_type = "buying" + args.transaction_type = "buying" \ No newline at end of file diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 6c03706303..954b03b1f6 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -736,7 +736,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ "qty": d.qty, "parenttype": d.parenttype, "parent": d.parent, - "pricing_rule": d.pricing_rule + "pricing_rule": d.pricing_rule, + "warehouse": d.warehouse, + "serial_no": d.serial_no }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 97eca54fe1..fc3cb3df33 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -206,11 +206,13 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ if(item.item_code && item.warehouse) { return this.frm.call({ - method: "erpnext.stock.get_item_details.get_bin_details", + method: "erpnext.stock.get_item_details.get_bin_details_and_serial_nos", child: item, args: { item_code: item.item_code, warehouse: item.warehouse, + qty: item.qty, + serial_no:item.serial_no }, callback:function(r){ if (inList(['Delivery Note', 'Sales Invoice'], doc.doctype)) { @@ -375,4 +377,4 @@ frappe.ui.form.on(cur_frm.doctype,"project", function(frm) { }) } } -}) +}) \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 81b5c1bb0d..a5a6cedb40 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -502,7 +502,7 @@ frappe.ui.form.on('Stock Entry', { 'qty' : d.qty }; frappe.call({ - method: "erpnext.stock.doctype.stock_entry.stock_entry.get_serial_no", + method: "erpnext.stock.get_item_details.get_serial_no", args: {"args": args}, callback: function(r) { if (!r.exe){ diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 65b9d267db..c5a03e6edd 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -8,7 +8,7 @@ from frappe import _ from frappe.utils import cstr, cint, flt, comma_or, getdate, nowdate, formatdate, format_time from erpnext.stock.utils import get_incoming_rate from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError -from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor, process_args, get_serial_nos_by_fifo +from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor from erpnext.manufacturing.doctype.bom.bom import validate_bom_no import json @@ -867,17 +867,4 @@ def get_warehouse_details(args): "basic_rate" : get_incoming_rate(args) } - return ret - -@frappe.whitelist() -def get_serial_no(args): - if isinstance(args, basestring): - args = json.loads(args) - args = frappe._dict(args) - - if args.get('warehouse'): - if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1: - args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"qty": args.get('qty')}) - args = process_args(args) - serial_no = get_serial_nos_by_fifo(args) - return serial_no \ No newline at end of file + return ret \ No newline at end of file diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index f8410afef9..f16ebd5ccf 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -43,7 +43,7 @@ def get_item_details(args): get_party_item_code(args, item_doc, out) if out.get("warehouse"): - out.update(get_bin_details(args.item_code, out.warehouse)) + out.update(get_bin_details_and_serial_nos(args.item_code, out.warehouse, args.qty, args.serial_no)) if frappe.db.exists("Product Bundle", args.item_code): valuation_rate = 0.0 @@ -74,8 +74,7 @@ def get_item_details(args): out.update(get_pricing_rule_for_item(args)) if args.get("doctype") in ("Sales Invoice", "Delivery Note"): - if item_doc.has_serial_no == 1 and not args.serial_no: - out.serial_no = get_serial_nos_by_fifo(args) + out.serial_no = get_serial_no(out) if args.transaction_date and item.lead_time_days: out.schedule_date = out.lead_time_date = add_days(args.transaction_date, @@ -375,8 +374,21 @@ def get_projected_qty(item_code, warehouse): @frappe.whitelist() def get_bin_details(item_code, warehouse): return frappe.db.get_value("Bin", {"item_code": item_code, "warehouse": warehouse}, - ["projected_qty", "actual_qty"], as_dict=True) \ - or {"projected_qty": 0, "actual_qty": 0} + ["projected_qty", "actual_qty"], as_dict=True) \ + or {"projected_qty": 0, "actual_qty": 0} + +@frappe.whitelist() +def get_serial_no_details(item_code, warehouse, qty, serial_no): + args = frappe._dict({"item_code":item_code, "warehouse":warehouse, "qty":qty, "serial_no":serial_no}) + serial_no = get_serial_no(args) + return {'serial_no': serial_no} + +@frappe.whitelist() +def get_bin_details_and_serial_nos(item_code, warehouse, qty, serial_no): + bin_details_and_serial_nos = {} + bin_details_and_serial_nos.update(get_bin_details(item_code, warehouse)) + bin_details_and_serial_nos.update(get_serial_no_details(item_code, warehouse, qty, serial_no)) + return bin_details_and_serial_nos @frappe.whitelist() def get_batch_qty(batch_no,warehouse,item_code): @@ -512,3 +524,17 @@ def get_gross_profit(out): return out +@frappe.whitelist() +def get_serial_no(args): + if isinstance(args, basestring): + args = json.loads(args) + args = frappe._dict(args) + + if args.get('warehouse') and args.get('qty') and args.get('item_code'): + + if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1: + print "I am in too" + args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"qty": args.get('qty')}) + args = process_args(args) + serial_no = get_serial_nos_by_fifo(args) + return serial_no From 4306cc80d098ff752b9ecaa44cde4b8088adab52 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 5 Dec 2016 16:51:30 +0530 Subject: [PATCH 2/2] removed print --- erpnext/stock/get_item_details.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index f16ebd5ccf..57e2c063a3 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -533,7 +533,6 @@ def get_serial_no(args): if args.get('warehouse') and args.get('qty') and args.get('item_code'): if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1: - print "I am in too" args = json.dumps({"item_code": args.get('item_code'),"warehouse": args.get('warehouse'),"qty": args.get('qty')}) args = process_args(args) serial_no = get_serial_nos_by_fifo(args)