[minor] [selling] [fix] fetch available qty for given warehouse
diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js
index 45a9b5b..a03b289 100644
--- a/selling/doctype/sales_common/sales_common.js
+++ b/selling/doctype/sales_common/sales_common.js
@@ -189,6 +189,7 @@
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 @@
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 4368d5b..7eeb22d 100644
--- a/selling/doctype/sales_order/sales_order.js
+++ b/selling/doctype/sales_order/sales_order.js
@@ -97,11 +97,21 @@
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 cbfaee7..bf4f081 100644
--- a/selling/utils.py
+++ b/selling/utils.py
@@ -58,9 +58,15 @@
_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 @@
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 @@
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 \