diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 0ff7c2b3aa..d977133172 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -9,9 +9,9 @@ from frappe.utils.nestedset import NestedSet
from frappe.website.website_generator import WebsiteGenerator
from frappe.website.render import clear_cache
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
+from erpnext.shopping_cart.product_info import set_product_info_for_website
from erpnext.utilities.product import get_qty_in_stock
-
class ItemGroup(NestedSet, WebsiteGenerator):
nsm_parent_field = 'parent_item_group'
website = frappe._dict(
@@ -105,9 +105,11 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
query += """order by I.weightage desc, in_stock desc, I.modified desc limit %s, %s""" % (start, limit)
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
-
data = adjust_qty_for_expired_items(data)
+ for item in data:
+ set_product_info_for_website(item)
+
return [get_item_for_list_in_html(r) for r in data]
diff --git a/erpnext/shopping_cart/product_info.py b/erpnext/shopping_cart/product_info.py
index 6f9c8acf17..33cac17304 100644
--- a/erpnext/shopping_cart/product_info.py
+++ b/erpnext/shopping_cart/product_info.py
@@ -33,7 +33,8 @@ def get_product_info_for_website(item_code):
"in_stock": stock_status.in_stock if stock_status.is_stock_item else 1,
"qty": 0,
"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
- "show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0
+ "show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0,
+ "sales_uom": frappe.db.get_value("Item", item_code, "sales_uom")
}
if product_info["price"]:
@@ -42,4 +43,18 @@ def get_product_info_for_website(item_code):
if item:
product_info["qty"] = item[0].qty
- return product_info
\ No newline at end of file
+ return product_info
+
+def set_product_info_for_website(item):
+ """set product price uom for website"""
+ product_info = get_product_info_for_website(item.item_code)
+
+ if product_info:
+ item["stock_uom"] = product_info.get("uom")
+ item["sales_uom"] = product_info.get("sales_uom")
+ if product_info.get("price"):
+ item["price_stock_uom"] = product_info.get("price").get("formatted_price")
+ item["price_sales_uom"] = product_info.get("price").get("formatted_price_sales_uom")
+ else:
+ item["price_stock_uom"] = ""
+ item["price_sales_uom"] = ""
\ No newline at end of file
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 722283e6cb..e96263fb80 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -15,7 +15,8 @@ frappe.ready(function() {
$(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.in_stock));
if(r.message && r.message.price) {
$(".item-price")
- .html(r.message.price.formatted_price + " / " + r.message.uom);
+ .html(r.message.price.formatted_price_sales_uom + "
\
+ (" + r.message.price.formatted_price + " / " + r.message.uom + ")
");
if(r.message.in_stock==0) {
$(".item-stock").html(" {{ _("Not in stock") }}
");
diff --git a/erpnext/templates/includes/products_as_grid.html b/erpnext/templates/includes/products_as_grid.html
index 4a9692aff6..34c2ccda37 100644
--- a/erpnext/templates/includes/products_as_grid.html
+++ b/erpnext/templates/includes/products_as_grid.html
@@ -5,6 +5,13 @@
{{ product_image_square(thumbnail or website_image) }}
{{ item_name }}
+ {% if price_sales_uom %}
+
{{ price_sales_uom }}
+
({{ price_stock_uom }} / {{ stock_uom }})
+ {% else %}
+
 
+
 
+ {% endif %}
{% if in_stock or not is_stock_item %}
{{ _("In stock") }}
{% else %}
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index f2fd60024a..ff1dd7d6b6 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -5,6 +5,7 @@ from __future__ import unicode_literals
import frappe
from frappe.utils import cstr, nowdate, cint
from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
+from erpnext.shopping_cart.product_info import set_product_info_for_website
no_cache = 1
no_sitemap = 1
@@ -42,5 +43,8 @@ def get_product_list(search=None, start=0, limit=12):
"today": nowdate()
}, as_dict=1)
+ for item in data:
+ set_product_info_for_website(item)
+
return [get_item_for_list_in_html(r) for r in data]
diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py
index b0cfbae80a..85967760a8 100644
--- a/erpnext/utilities/product.py
+++ b/erpnext/utilities/product.py
@@ -19,14 +19,16 @@ def get_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
warehouse = frappe.db.get_value("Item", template_item_code, item_warehouse_field)
if warehouse:
- stock_qty = frappe.db.sql("""select GREATEST(actual_qty - reserved_qty, 0) from tabBin where
- item_code=%s and warehouse=%s""", (item_code, warehouse))
+ stock_qty = frappe.db.sql("""
+ select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
+ from tabBin S
+ inner join `tabItem` I on S.item_code = I.Item_code
+ left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
+ where S.item_code=%s and S.warehouse=%s""", (item_code, warehouse))
- if stock_qty:
- stock_qty = adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
-
- if stock_qty:
- in_stock = stock_qty[0][0] > 0 and 1 or 0
+ if stock_qty:
+ stock_qty = adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
+ in_stock = stock_qty[0][0] > 0 and 1 or 0
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item})
@@ -103,6 +105,14 @@ def get_price(item_code, price_list, customer_group, company, qty=1):
and (frappe.db.get_value("Currency", price_obj.currency, "symbol") or price_obj.currency) \
or ""
+ uom_conversion_factor = frappe.db.sql("""select C.conversion_factor
+ from `tabUOM Conversion Detail` C
+ inner join `tabItem` I on C.uom = I.sales_uom
+ where C.parent = %s""", item_code)
+
+ uom_conversion_factor = uom_conversion_factor[0][0] if uom_conversion_factor else 1
+ price_obj["formatted_price_sales_uom"] = fmt_money(price_obj["price_list_rate"] * uom_conversion_factor, currency=price_obj["currency"])
+
if not price_obj["price_list_rate"]:
price_obj["price_list_rate"] = 0