ef4579e4eb
- Minor wishlist UI refresh, actions on hover, new icon - Increase max length of wishlist card title - Dont fetch outdated price in wishlist - Translate 'out of stock' - Use ORM
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: GNU General Public License v3. See license.txt
|
|
import frappe
|
|
from erpnext.utilities.product import get_price
|
|
from erpnext.e_commerce.shopping_cart.cart import _set_price_list
|
|
|
|
def get_context(context):
|
|
settings = frappe.get_doc("E Commerce Settings")
|
|
items = get_wishlist_items()
|
|
selling_price_list = _set_price_list(settings)
|
|
|
|
for item in items:
|
|
if settings.show_stock_availability:
|
|
item.available = get_stock_availability(item.item_code, item.get("warehouse"))
|
|
|
|
price_details = get_price(
|
|
item.item_code,
|
|
selling_price_list,
|
|
settings.default_customer_group,
|
|
settings.company
|
|
)
|
|
|
|
if price_details:
|
|
item.formatted_price = price_details.get('formatted_price')
|
|
item.formatted_mrp = price_details.get('formatted_mrp')
|
|
if item.formatted_mrp:
|
|
item.discount = price_details.get('formatted_discount_percent') or \
|
|
price_details.get('formatted_discount_rate')
|
|
|
|
context.items = items
|
|
context.settings = settings
|
|
context.no_cache = 1
|
|
|
|
def get_stock_availability(item_code, warehouse):
|
|
stock_qty = frappe.utils.flt(
|
|
frappe.db.get_value("Bin",
|
|
{
|
|
"item_code": item_code,
|
|
"warehouse": warehouse
|
|
},
|
|
"actual_qty")
|
|
)
|
|
return bool(stock_qty)
|
|
|
|
def get_wishlist_items():
|
|
if not frappe.db.exists("Wishlist", frappe.session.user):
|
|
return []
|
|
|
|
return frappe.db.get_all(
|
|
"Wishlist Item",
|
|
filters={
|
|
"parent": frappe.session.user
|
|
},
|
|
fields=[
|
|
"web_item_name", "item_code", "item_name",
|
|
"website_item", "price", "warehouse",
|
|
"image", "item_group", "route"
|
|
])
|