fix: removing get_value
call by returning is_stock_item in get_stock_availability
method
This commit is contained in:
parent
9e20fa85c1
commit
ac9a9fb229
@ -154,7 +154,7 @@ class POSInvoice(SalesInvoice):
|
||||
if allow_negative_stock:
|
||||
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)
|
||||
if flt(available_stock) <= 0:
|
||||
@ -465,15 +465,17 @@ class POSInvoice(SalesInvoice):
|
||||
@frappe.whitelist()
|
||||
def get_stock_availability(item_code, warehouse):
|
||||
if frappe.db.get_value('Item', item_code, 'is_stock_item'):
|
||||
is_stock_item = True
|
||||
bin_qty = get_bin_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:
|
||||
is_stock_item = False
|
||||
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:
|
||||
# Is a service item
|
||||
return 0
|
||||
return 0, is_stock_item
|
||||
|
||||
|
||||
def get_bundle_availability(bundle_item_code, warehouse):
|
||||
|
@ -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"],
|
||||
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': price_list,
|
||||
'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:
|
||||
item_code = item.item_code
|
||||
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.update(item)
|
||||
|
@ -630,23 +630,24 @@ erpnext.PointOfSale.Controller = class {
|
||||
}
|
||||
|
||||
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();
|
||||
const bold_item_code = item_row.item_code.bold();
|
||||
const bold_warehouse = warehouse.bold();
|
||||
const bold_available_qty = available_qty.toString().bold()
|
||||
if (!(available_qty > 0)) {
|
||||
frappe.db.get_value('Item', item_row.item_code, 'is_stock_item').then(({message}) => {
|
||||
const is_service_item = message.is_stock_item;
|
||||
if (!is_service_item) return;
|
||||
|
||||
if (is_stock_item) {
|
||||
frappe.model.clear_doc(item_row.doctype, item_row.name);
|
||||
frappe.throw({
|
||||
title: __("Not Available"),
|
||||
message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse])
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (available_qty < qty_needed) {
|
||||
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]),
|
||||
@ -681,7 +682,7 @@ erpnext.PointOfSale.Controller = class {
|
||||
callback(res) {
|
||||
if (!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];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user