From 4a60554b910460ff1e8355dc3d3060639827733e Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 25 Oct 2017 13:59:29 +0530 Subject: [PATCH] Green indicator in the cart for non stock item (#11325) --- .../page/point_of_sale/point_of_sale.js | 30 +++++++++++++++++-- .../page/point_of_sale/point_of_sale.py | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js index 7110d4c199..a810636646 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.js +++ b/erpnext/selling/page/point_of_sale/point_of_sale.js @@ -113,6 +113,9 @@ erpnext.pos.PointOfSale = class PointOfSale { }, on_select_change: () => { this.cart.numpad.set_inactive(); + }, + get_item_details: (item_code) => { + return this.items.get(item_code); } } }); @@ -408,6 +411,7 @@ erpnext.pos.PointOfSale = class PointOfSale { class POSCart { constructor({frm, wrapper, pos_profile, events}) { this.frm = frm; + this.item_data = {}; this.wrapper = wrapper; this.events = events; this.pos_profile = pos_profile; @@ -667,7 +671,8 @@ class POSCart { const $item = this.$cart_items.find(`[data-item-code="${item.item_code}"]`); if(item.qty > 0) { - const indicator_class = item.actual_qty >= item.qty ? 'green' : 'red'; + const is_stock_item = this.get_item_details(item.item_code).is_stock_item; + const indicator_class = (!is_stock_item || item.actual_qty >= item.qty) ? 'green' : 'red'; const remove_class = indicator_class == 'green' ? 'red' : 'green'; $item.find('.quantity input').val(item.qty); @@ -681,8 +686,9 @@ class POSCart { } get_item_html(item) { + const is_stock_item = this.get_item_details(item.item_code).is_stock_item; const rate = format_currency(item.rate, this.frm.doc.currency); - const indicator_class = item.actual_qty >= item.qty ? 'green' : 'red'; + const indicator_class = (!is_stock_item || item.actual_qty >= item.qty) ? 'green' : 'red'; return `
@@ -717,6 +723,14 @@ class POSCart { } } + get_item_details(item_code) { + if (!this.item_data[item_code]) { + this.item_data[item_code] = this.events.get_item_details(item_code); + } + + return this.item_data[item_code]; + } + exists(item_code) { let $item = this.$cart_items.find(`[data-item-code="${item_code}"]`); return $item.length > 0; @@ -965,11 +979,13 @@ class POSItems { this.search_index = this.search_index || {}; if (this.search_index[search_term]) { const items = this.search_index[search_term]; + this.items = items; this.render_items(items); this.set_item_in_the_cart(items); return; } } else if (item_group == "All Item Groups") { + this.items = this.all_items; return this.render_items(this.all_items); } @@ -979,6 +995,7 @@ class POSItems { this.search_index[search_term] = items; } + this.items = items; this.render_items(items); this.set_item_in_the_cart(items, serial_no, batch_no); }); @@ -1021,7 +1038,14 @@ class POSItems { } get(item_code) { - return this.items[item_code]; + let item = {}; + this.items.map(data => { + if (data.item_code === item_code) { + item = data; + } + }) + + return item } get_all() { diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.py b/erpnext/selling/page/point_of_sale/point_of_sale.py index b92c653030..7400e432ae 100644 --- a/erpnext/selling/page/point_of_sale/point_of_sale.py +++ b/erpnext/selling/page/point_of_sale/point_of_sale.py @@ -36,7 +36,7 @@ def get_items(start, page_length, price_list, item_group, search_value=""): lft, rgt = frappe.db.get_value('Item Group', item_group, ['lft', 'rgt']) # locate function is used to sort by closest match from the beginning of the value res = frappe.db.sql("""select i.name as item_code, i.item_name, i.image as item_image, - item_det.price_list_rate, item_det.currency + i.is_stock_item, item_det.price_list_rate, item_det.currency from `tabItem` i LEFT JOIN (select item_code, price_list_rate, currency from `tabItem Price` where price_list=%(price_list)s) item_det