Apply Pricing Rule in Shopping Cart
This commit is contained in:
parent
5f453e7779
commit
2c1f399479
@ -277,7 +277,7 @@ def filter_pricing_rules(args, pricing_rules):
|
||||
pricing_rules = filter(lambda x: x.for_price_list==args.price_list, pricing_rules) \
|
||||
or pricing_rules
|
||||
|
||||
if len(pricing_rules) > 1:
|
||||
if len(pricing_rules) > 1 and not args.for_shopping_cart:
|
||||
frappe.throw(_("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: {0}")
|
||||
.format("\n".join([d.name for d in pricing_rules])), MultiplePricingRuleConflict)
|
||||
elif pricing_rules:
|
||||
|
@ -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]
|
||||
|
@ -12,13 +12,13 @@ frappe.ready(function() {
|
||||
item_code: get_item_code()
|
||||
},
|
||||
callback: function(r) {
|
||||
$(".item-cart").toggleClass("hide", !!!r.message.price);
|
||||
$(".item-cart").toggleClass("hide", (!!!r.message.price || !!!r.message.stock));
|
||||
if(r.message && r.message.price) {
|
||||
$(".item-price")
|
||||
.html(r.message.price.formatted_price + " per " + r.message.uom);
|
||||
|
||||
if(r.message.stock==0) {
|
||||
$(".item-stock").html("<div class='help'>Not in stock</div>");
|
||||
$(".item-stock").html("<div style='color: red'>Not in stock</div>");
|
||||
}
|
||||
else if(r.message.stock==1) {
|
||||
$(".item-stock").html("<div style='color: green'>\
|
||||
|
Loading…
x
Reference in New Issue
Block a user