fix: Allowing non stock items in POS

This commit is contained in:
Subin Tom 2021-12-22 19:14:47 +05:30
parent c1a0f649cb
commit ec37930404
3 changed files with 23 additions and 12 deletions

View File

@ -41,7 +41,7 @@ class POSInvoice(SalesInvoice):
self.validate_serialised_or_batched_item() self.validate_serialised_or_batched_item()
self.validate_stock_availablility() self.validate_stock_availablility()
self.validate_return_items_qty() self.validate_return_items_qty()
self.validate_non_stock_items() # self.validate_non_stock_items()
self.set_status() self.set_status()
self.set_account_for_mode_of_payment() self.set_account_for_mode_of_payment()
self.validate_pos() self.validate_pos()
@ -143,9 +143,11 @@ class POSInvoice(SalesInvoice):
def validate_stock_availablility(self): def validate_stock_availablility(self):
if self.is_return or self.docstatus != 1: if self.is_return or self.docstatus != 1:
return return
allow_negative_stock = frappe.db.get_single_value('Stock Settings', 'allow_negative_stock') allow_negative_stock = frappe.db.get_single_value('Stock Settings', 'allow_negative_stock')
for d in self.get('items'): for d in self.get('items'):
is_service_item = not (frappe.db.get_value('Item', d.get('item_code'), 'is_stock_item'))
if is_service_item:
return
if d.serial_no: if d.serial_no:
self.validate_pos_reserved_serial_nos(d) self.validate_pos_reserved_serial_nos(d)
self.validate_delivered_serial_nos(d) self.validate_delivered_serial_nos(d)
@ -475,9 +477,12 @@ def get_stock_availability(item_code, warehouse):
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
else: elif 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) #To continue the flow considering a service item
elif frappe.db.get_value('Item', item_code, 'is_stock_item') == 0:
return 0
def get_bundle_availability(bundle_item_code, warehouse): def get_bundle_availability(bundle_item_code, warehouse):
product_bundle = frappe.get_doc('Product Bundle', bundle_item_code) product_bundle = frappe.get_doc('Product Bundle', bundle_item_code)

View File

@ -99,7 +99,7 @@ def get_items(start, page_length, price_list, item_group, pos_profile, search_te
), {'warehouse': warehouse}, as_dict=1) ), {'warehouse': warehouse}, as_dict=1)
if items_data: if items_data:
items_data = filter_service_items(items_data) # items_data = filter_service_items(items_data)
items = [d.item_code for d in items_data] items = [d.item_code for d in items_data]
item_prices_data = frappe.get_all("Item Price", item_prices_data = frappe.get_all("Item Price",
fields = ["item_code", "price_list_rate", "currency"], fields = ["item_code", "price_list_rate", "currency"],
@ -146,7 +146,7 @@ def search_for_serial_or_batch_or_barcode_number(search_value):
def filter_service_items(items): def filter_service_items(items):
for item in items: for item in items:
if not item['is_stock_item']: if not item.get('is_stock_item'):
if not frappe.db.exists('Product Bundle', item['item_code']): if not frappe.db.exists('Product Bundle', item['item_code']):
items.remove(item) items.remove(item)

View File

@ -637,11 +637,17 @@ erpnext.PointOfSale.Controller = class {
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.model.clear_doc(item_row.doctype, item_row.name); frappe.db.get_value('Item', item_row.item_code, 'is_stock_item').then(({message}) => {
frappe.throw({ const is_service_item = message.is_stock_item;
title: __("Not Available"), console.log('is_service_item', is_service_item);
message: __('Item Code: {0} is not available under warehouse {1}.', [bold_item_code, bold_warehouse]) if (!is_service_item) return;
})
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 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]),