fix: removing get_value call by returning is_stock_item in get_stock_availability method

This commit is contained in:
Subin Tom 2022-01-17 19:38:05 +05:30
parent 9e20fa85c1
commit ac9a9fb229
3 changed files with 16 additions and 13 deletions

View File

@ -154,7 +154,7 @@ class POSInvoice(SalesInvoice):
if allow_negative_stock: if allow_negative_stock:
return return
available_stock = get_stock_availability(d.item_code, d.warehouse) available_stock, is_stock_item = get_stock_availability(d.item_code, d.warehouse)
item_code, warehouse, qty = frappe.bold(d.item_code), frappe.bold(d.warehouse), frappe.bold(d.qty) item_code, warehouse, qty = frappe.bold(d.item_code), frappe.bold(d.warehouse), frappe.bold(d.qty)
if flt(available_stock) <= 0: if flt(available_stock) <= 0:
@ -465,15 +465,17 @@ class POSInvoice(SalesInvoice):
@frappe.whitelist() @frappe.whitelist()
def get_stock_availability(item_code, warehouse): def get_stock_availability(item_code, warehouse):
if frappe.db.get_value('Item', item_code, 'is_stock_item'): if frappe.db.get_value('Item', item_code, 'is_stock_item'):
is_stock_item = True
bin_qty = get_bin_qty(item_code, warehouse) bin_qty = get_bin_qty(item_code, warehouse)
pos_sales_qty = get_pos_reserved_qty(item_code, warehouse) pos_sales_qty = get_pos_reserved_qty(item_code, warehouse)
return bin_qty - pos_sales_qty return bin_qty - pos_sales_qty, is_stock_item
else: else:
is_stock_item = False
if frappe.db.exists('Product Bundle', item_code): if frappe.db.exists('Product Bundle', item_code):
return get_bundle_availability(item_code, warehouse) return get_bundle_availability(item_code, warehouse), is_stock_item
else: else:
# Is a service item # Is a service item
return 0 return 0, is_stock_item
def get_bundle_availability(bundle_item_code, warehouse): def get_bundle_availability(bundle_item_code, warehouse):

View File

@ -24,7 +24,7 @@ def search_by_term(search_term, warehouse, price_list):
["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"], ["name as item_code", "item_name", "description", "stock_uom", "image as item_image", "is_stock_item"],
as_dict=1) as_dict=1)
item_stock_qty = get_stock_availability(item_code, warehouse) item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse)
price_list_rate, currency = frappe.db.get_value('Item Price', { price_list_rate, currency = frappe.db.get_value('Item Price', {
'price_list': price_list, 'price_list': price_list,
'item_code': item_code 'item_code': item_code
@ -111,7 +111,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
for item in items_data: for item in items_data:
item_code = item.item_code item_code = item.item_code
item_price = item_prices.get(item_code) or {} item_price = item_prices.get(item_code) or {}
item_stock_qty = get_stock_availability(item_code, warehouse) item_stock_qty, is_stock_item = get_stock_availability(item_code, warehouse)
row = {} row = {}
row.update(item) row.update(item)

View File

@ -630,23 +630,24 @@ erpnext.PointOfSale.Controller = class {
} }
async check_stock_availability(item_row, qty_needed, warehouse) { async check_stock_availability(item_row, qty_needed, warehouse) {
const available_qty = (await this.get_available_stock(item_row.item_code, warehouse)).message; const resp = (await this.get_available_stock(item_row.item_code, warehouse)).message;
const available_qty = resp[0];
const is_stock_item = resp[1];
frappe.dom.unfreeze(); frappe.dom.unfreeze();
const bold_item_code = item_row.item_code.bold(); const bold_item_code = item_row.item_code.bold();
const bold_warehouse = warehouse.bold(); const bold_warehouse = warehouse.bold();
const bold_available_qty = available_qty.toString().bold() const bold_available_qty = available_qty.toString().bold()
if (!(available_qty > 0)) { if (!(available_qty > 0)) {
frappe.db.get_value('Item', item_row.item_code, 'is_stock_item').then(({message}) => { if (is_stock_item) {
const is_service_item = message.is_stock_item;
if (!is_service_item) return;
frappe.model.clear_doc(item_row.doctype, item_row.name); frappe.model.clear_doc(item_row.doctype, item_row.name);
frappe.throw({ frappe.throw({
title: __("Not Available"), title: __("Not Available"),
message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse])
}); });
}); } else {
return;
}
} else if (available_qty < qty_needed) { } else if (available_qty < qty_needed) {
frappe.show_alert({ frappe.show_alert({
message: __('Stock quantity not enough for Item Code: {0} under warehouse {1}. Available quantity {2}.', [bold_item_code, bold_warehouse, bold_available_qty]), message: __('Stock quantity not enough for Item Code: {0} under warehouse {1}. Available quantity {2}.', [bold_item_code, bold_warehouse, bold_available_qty]),
@ -681,7 +682,7 @@ erpnext.PointOfSale.Controller = class {
callback(res) { callback(res) {
if (!me.item_stock_map[item_code]) if (!me.item_stock_map[item_code])
me.item_stock_map[item_code] = {} me.item_stock_map[item_code] = {}
me.item_stock_map[item_code][warehouse] = res.message; me.item_stock_map[item_code][warehouse] = res.message[0];
} }
}); });
} }