fix: pricing rule not working for offline POS

This commit is contained in:
Rohit Waghchaure
2021-01-04 15:32:13 +05:30
parent 945c0e86de
commit bf490c3a27
2 changed files with 60 additions and 14 deletions

View File

@@ -153,8 +153,8 @@ def update_multi_mode_option(doc, pos_profile):
def get_mode_of_payment(doc):
return frappe.db.sql("""
select mpa.default_account, mpa.parent, mp.type as type
from `tabMode of Payment Account` mpa,`tabMode of Payment` mp
select mpa.default_account, mpa.parent, mp.type as type
from `tabMode of Payment Account` mpa,`tabMode of Payment` mp
where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""",
{'company': doc.company}, as_dict=1)
@@ -394,6 +394,14 @@ def get_pricing_rule_data(doc):
between ifnull(valid_from, '2000-01-01') and ifnull(valid_upto, '2500-12-31')
order by priority desc, name desc""",
{'company': doc.company, 'price_list': doc.selling_price_list, 'date': nowdate()}, as_dict=1)
for row in pricing_rules:
if row.apply_on:
doctype = "Pricing Rule " + row.apply_on
apply_on = frappe.scrub(row.apply_on)
row[apply_on] = [d.get(apply_on) for d in frappe.get_all(doctype,
filters = {"parent": row.name}, fields = [apply_on])]
return pricing_rules
@@ -434,10 +442,10 @@ def make_invoice(pos_profile, doc_list={}, email_queue_list={}, customers_list={
name_list.append(name)
email_queue = make_email_queue(email_queue_list)
if isinstance(pos_profile, string_types):
pos_profile = json.loads(pos_profile)
customers = get_customers_list(pos_profile)
return {
'invoice': name_list,

View File

@@ -2018,34 +2018,57 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
apply_pricing_rule: function () {
var me = this;
var remove_item = false;
$.each(this.frm.doc["items"], function (n, item) {
var pricing_rule = me.get_pricing_rule(item)
me.validate_pricing_rule(pricing_rule)
if (pricing_rule.length) {
item.pricing_rule = pricing_rule[0].name;
item.margin_type = pricing_rule[0].margin_type;
item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
me.apply_pricing_rule_on_item(item)
if (pricing_rule[0].price_or_product_discount == "Price") {
item.pricing_rule = pricing_rule[0].name;
item.margin_type = pricing_rule[0].margin_type;
item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
me.apply_pricing_rule_on_item(item)
} else {
me.child = frappe.model.add_child(me.frm.doc, me.frm.doc.doctype + " Item", "items");
me.child.item_code = pricing_rule[0].same_item ? item.item_code : pricing_rule[0].free_item;
me.child.item_name = pricing_rule[0].same_item ? item.item_name : pricing_rule[0].free_item;
me.child.stock_uom = pricing_rule[0].same_item ? item.stock_uom : pricing_rule[0].free_item_uom;
me.child.uom = pricing_rule[0].same_item ? item.uom : pricing_rule[0].free_item_uom;
me.child.conversion_factor = 1;
me.child.qty = pricing_rule.qty || 1;
me.child.is_free_item = 1;
me.child.brand = pricing_rule[0].same_item ? item.brand : "";
me.child.description = pricing_rule[0].same_item ? item.description : pricing_rule[0].free_item;
}
} else if (item.pricing_rule) {
item.price_list_rate = me.price_list_data[item.item_code]
item.margin_rate_or_amount = 0.0;
item.discount_percentage = 0.0;
item.pricing_rule = null;
me.apply_pricing_rule_on_item(item)
} else if (item.is_free_item) {
remove_item = true;
item.qty = 0
}
if(item.discount_percentage > 0) {
me.apply_pricing_rule_on_item(item)
}
})
});
if (remove_item) {
this.remove_zero_qty_items_from_cart();
}
},
get_pricing_rule: function (item) {
var me = this;
return $.grep(this.pricing_rules, function (data) {
if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
me.get_mixed_min_max_qty_and_amt(data, item);
if (data.mixed_qty >= data.min_qty && (data.mixed_qty <= (data.max_qty ? data.max_qty : data.mixed_qty))) {
if (me.validate_item_condition(data, item)) {
if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
return me.validate_condition(data)
@@ -2057,11 +2080,26 @@ erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
})
},
get_mixed_min_max_qty_and_amt: function(data, item) {
var apply_on = frappe.model.scrub(data.apply_on);
data.mixed_qty = 0.0
if (data.mixed_conditions && in_list(data[apply_on], item[apply_on])) {
this.frm.doc.items.forEach(d => {
if (in_list(data[apply_on], d[apply_on])) {
data.mixed_qty += d.qty;
data.mixed_amt += d.amount;
}
});
} else {
data.mixed_qty = item.qty;
data.mixed_amt = item.amount;
}
},
validate_item_condition: function (data, item) {
var apply_on = frappe.model.scrub(data.apply_on);
return (data.apply_on == 'Item Group')
? this.validate_item_group(data.item_group, item.item_group) : (data[apply_on] == item[apply_on]);
return in_list(data[apply_on], item[apply_on]);
},
validate_item_group: function (pr_item_group, cart_item_group) {