From 1dc95ed86546f8cdcefde137acac2400928e4efa Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 23 Jul 2013 13:36:38 +0530 Subject: [PATCH] [minor] [selling] [fix] fetch available qty for given warehouse --- selling/doctype/sales_common/sales_common.js | 5 +++-- selling/doctype/sales_order/sales_order.js | 18 ++++++++++++++---- selling/utils.py | 20 +++++++++++++------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index 45a9b5b7f0..a03b2894bc 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -189,6 +189,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ barcode: item.barcode, warehouse: item.warehouse, doctype: me.frm.doc.doctype, + parentfield: item.parentfield, customer: me.frm.doc.customer, currency: me.frm.doc.currency, conversion_rate: me.frm.doc.conversion_rate, @@ -287,13 +288,13 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ warehouse: function(doc, cdt, cdn) { var item = wn.model.get_doc(cdt, cdn); - if(item.item_code && (item.warehouse || item.reserved_warehouse)) { + if(item.item_code && item.warehouse) { this.frm.call({ method: "selling.utils.get_available_qty", child: item, args: { item_code: item.item_code, - warehouse: item.warehouse || item.reserved_warehouse, + warehouse: item.warehouse, }, }); } diff --git a/selling/doctype/sales_order/sales_order.js b/selling/doctype/sales_order/sales_order.js index 4368d5ba75..7eeb22d23e 100644 --- a/selling/doctype/sales_order/sales_order.js +++ b/selling/doctype/sales_order/sales_order.js @@ -97,11 +97,21 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend( tc_name: function() { this.get_terms(); }, - - reserved_warehouse: function(doc, cdt, cdn) { - this.warehouse(doc, cdt, cdn); - }, + reserved_warehouse: function(doc, cdt, cdn) { + var item = wn.model.get_doc(cdt, cdn); + if(item.item_code && item.reserved_warehouse) { + this.frm.call({ + method: "selling.utils.get_available_qty", + child: item, + args: { + item_code: item.item_code, + warehouse: item.reserved_warehouse, + }, + }); + } + }, + make_material_request: function() { wn.model.open_mapped_doc({ method: "selling.doctype.sales_order.sales_order.make_material_request", diff --git a/selling/utils.py b/selling/utils.py index cbfaee736d..bf4f0811ec 100644 --- a/selling/utils.py +++ b/selling/utils.py @@ -58,9 +58,15 @@ def get_item_details(args): _validate_item_details(args, item_bean.doc) - out = _get_basic_details(args, item_bean) - meta = webnotes.get_doctype(args.doctype) + + # hack! for Sales Order Item + warehouse_fieldname = "warehouse" + if meta.get_field("reserved_warehouse", parentfield=args.parentfield): + warehouse_fieldname = "reserved_warehouse" + + out = _get_basic_details(args, item_bean, warehouse_fieldname) + if meta.get_field("currency"): out.base_ref_rate = out.basic_rate = out.ref_rate = out.export_rate = 0.0 @@ -69,8 +75,8 @@ def get_item_details(args): out.update(_get_item_discount(out.item_group, args.customer)) - if out.warehouse or out.reserved_warehouse: - out.update(get_available_qty(args.item_code, out.warehouse or out.reserved_warehouse)) + if out.get(warehouse_fieldname): + out.update(get_available_qty(args.item_code, out.get(warehouse_fieldname))) out.customer_item_code = _get_customer_item_code(args, item_bean) @@ -108,13 +114,13 @@ def _validate_item_details(args, item): msgprint(_("Item") + (" %s: " % item.name) + _("not a sales item"), raise_exception=True) -def _get_basic_details(args, item_bean): +def _get_basic_details(args, item_bean, warehouse_fieldname): item = item_bean.doc + out = webnotes._dict({ "item_code": item.name, "description": item.description_html or item.description, - "reserved_warehouse": item.default_warehouse or args.warehouse or args.reserved_warehouse, - "warehouse": item.default_warehouse or args.warehouse, + warehouse_fieldname: item.default_warehouse or args.get(warehouse_fieldname), "income_account": item.default_income_account or args.income_account \ or webnotes.conn.get_value("Company", args.company, "default_income_account"), "expense_account": item.purchase_account or args.expense_account \