mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
Apply Pricing Rule in Shopping Cart
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
from frappe.utils import cint, fmt_money
|
||||
from frappe.utils import cint, fmt_money, flt
|
||||
from erpnext.shopping_cart.cart import _get_cart_quotation
|
||||
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled
|
||||
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings \
|
||||
import is_cart_enabled, get_shopping_cart_settings
|
||||
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
|
||||
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_product_info(item_code):
|
||||
@@ -51,12 +53,14 @@ def get_qty_in_stock(item_code, template_item_code):
|
||||
in_stock = in_stock[0][0] > 0 and 1 or 0
|
||||
|
||||
else:
|
||||
in_stock = -1
|
||||
in_stock = 0
|
||||
|
||||
return in_stock
|
||||
|
||||
def get_price(item_code, template_item_code, price_list):
|
||||
def get_price(item_code, template_item_code, price_list, qty=1):
|
||||
if price_list:
|
||||
cart_settings = get_shopping_cart_settings()
|
||||
|
||||
price = frappe.get_all("Item Price", fields=["price_list_rate", "currency"],
|
||||
filters={"price_list": price_list, "item_code": item_code})
|
||||
|
||||
@@ -65,4 +69,22 @@ def get_price(item_code, template_item_code, price_list):
|
||||
filters={"price_list": price_list, "item_code": template_item_code})
|
||||
|
||||
if price:
|
||||
pricing_rule = get_pricing_rule_for_item(frappe._dict({
|
||||
"item_code": item_code,
|
||||
"qty": qty,
|
||||
"transaction_type": "selling",
|
||||
"price_list": price_list,
|
||||
"customer_group": cart_settings.default_customer_group,
|
||||
"company": cart_settings.company,
|
||||
"conversion_rate": 1,
|
||||
"for_shopping_cart": True
|
||||
}))
|
||||
|
||||
if pricing_rule:
|
||||
if pricing_rule.pricing_rule_for == "Discount Percentage":
|
||||
price[0].price_list_rate = flt(price[0].price_list_rate * (1.0 - (pricing_rule.discount_percentage / 100.0)))
|
||||
|
||||
if pricing_rule.pricing_rule_for == "Price":
|
||||
price[0].price_list_rate = pricing_rule.price_list_rate
|
||||
|
||||
return price[0]
|
||||
|
||||
Reference in New Issue
Block a user