[minor] [selling] [fix] fetch available qty for given warehouse

This commit is contained in:
Anand Doshi 2013-07-23 13:36:38 +05:30
parent 648a5c7e33
commit 1dc95ed865
3 changed files with 30 additions and 13 deletions

View File

@ -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,
},
});
}

View File

@ -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",

View File

@ -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 \