[Website] Price in items list and sales uom management (#13335)
* Price in items list and sales uom management * Price in product search page * Display website stock in sales uom * Add set_product_info_for_website to avoid duplicate code * Add price uom in item list and page * Update product.py
This commit is contained in:
parent
9a01baac1d
commit
e3a9b9fe49
@ -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]
|
||||
|
||||
|
||||
|
@ -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
|
||||
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"] = ""
|
@ -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 + "<div style='font-size: small'>\
|
||||
(" + r.message.price.formatted_price + " / " + r.message.uom + ")</div>");
|
||||
|
||||
if(r.message.in_stock==0) {
|
||||
$(".item-stock").html("<div style='color: red'> <i class='fa fa-close'></i> {{ _("Not in stock") }}</div>");
|
||||
|
@ -5,6 +5,13 @@
|
||||
<div class="product-image-img">
|
||||
{{ product_image_square(thumbnail or website_image) }}
|
||||
<div class="product-text" itemprop="name">{{ item_name }}</div>
|
||||
{% if price_sales_uom %}
|
||||
<div>{{ price_sales_uom }}</div>
|
||||
<div style='font-size: small; margin-bottom: 10px;'>({{ price_stock_uom }} / {{ stock_uom }})</div>
|
||||
{% else %}
|
||||
<div> </div>
|
||||
<div style='font-size: small; margin-bottom: 10px;'> </div>
|
||||
{% endif %}
|
||||
{% if in_stock or not is_stock_item %}
|
||||
<div style='color: green'> <i class='fa fa-check'></i> {{ _("In stock") }}</div>
|
||||
{% else %}
|
||||
|
@ -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]
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user