Green indicator in the cart for non stock item (#11325)

This commit is contained in:
rohitwaghchaure 2017-10-25 13:59:29 +05:30 committed by Nabin Hait
parent 3dc21b099d
commit 4a60554b91
2 changed files with 28 additions and 4 deletions

View File

@ -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 `
<div class="list-item indicator ${indicator_class}" data-item-code="${item.item_code}" title="Item: ${item.item_name} Available Qty: ${item.actual_qty}">
<div class="item-name list-item__content list-item__content--flex-1.5 ellipsis">
@ -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() {

View File

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