Skip to content

Commit

Permalink
Merge pull request #39084 from deepeshgarg007/pricing_rule_remove
Browse files Browse the repository at this point in the history
fix: Pricing rule application/removal on qty change
  • Loading branch information
deepeshgarg007 authored Jan 13, 2024
2 parents ec5c0de + f52d7c7 commit a87bb21
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
5 changes: 5 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,12 +579,17 @@ def apply_price_discount_rule(pricing_rule, item_details, args):
item_details[field] += pricing_rule.get(field, 0) if pricing_rule else args.get(field, 0)


@frappe.whitelist()
def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, rate=None):
from erpnext.accounts.doctype.pricing_rule.utils import (
get_applied_pricing_rules,
get_pricing_rule_items,
)

if isinstance(item_details, str):
item_details = json.loads(item_details)
item_details = frappe._dict(item_details)

for d in get_applied_pricing_rules(pricing_rules):
if not d or not frappe.db.exists("Pricing Rule", d):
continue
Expand Down
41 changes: 35 additions & 6 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,9 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
let item = frappe.get_doc(cdt, cdn);
// item.pricing_rules = ''
frappe.run_serially([
() => this.remove_pricing_rule(item),
() => this.remove_pricing_rule_for_item(item),
() => this.conversion_factor(doc, cdt, cdn, true),
() => this.apply_price_list(item, true), //reapply price list before applying pricing rule
() => this.calculate_stock_uom_rate(doc, cdt, cdn),
() => this.apply_pricing_rule(item, true)
]);
Expand Down Expand Up @@ -1447,8 +1448,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe

ignore_pricing_rule() {
if(this.frm.doc.ignore_pricing_rule) {
var me = this;
var item_list = [];
let me = this;
let item_list = [];

$.each(this.frm.doc["items"] || [], function(i, d) {
if (d.item_code) {
Expand Down Expand Up @@ -1487,6 +1488,34 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
}
}

remove_pricing_rule_for_item(item) {
let me = this;
return this.frm.call({
method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.remove_pricing_rule_for_item",
args: {
pricing_rules: item.pricing_rules,
item_details: {
"doctype": item.doctype,
"name": item.name,
"item_code": item.item_code,
"pricing_rules": item.pricing_rules,
"parenttype": item.parenttype,
"parent": item.parent,
"price_list_rate": item.price_list_rate
},
item_code: item.item_code,
rate: item.price_list_rate,
},
callback: function(r) {
if (!r.exc && r.message) {
me.remove_pricing_rule(r.message);
me.calculate_taxes_and_totals();
if(me.frm.doc.apply_discount_on) me.frm.trigger("apply_discount_on");
}
}
});
}

apply_pricing_rule(item, calculate_taxes_and_totals) {
var me = this;
var args = this._get_args(item);
Expand Down Expand Up @@ -1711,8 +1740,8 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
this.frm.set_value("plc_conversion_rate", "");
}

var me = this;
var args = this._get_args(item);
let me = this;
let args = this._get_args(item);
if (!((args.items && args.items.length) || args.price_list)) {
return;
}
Expand Down Expand Up @@ -1754,7 +1783,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];

if(item.remove_free_item) {
var items = [];
let items = [];

me.frm.doc.items.forEach(d => {
if(d.item_code != item.remove_free_item || !d.is_free_item) {
Expand Down
4 changes: 2 additions & 2 deletions erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ def update_barcode_value(out):


def get_barcode_data(items_list):
# get itemwise batch no data
# exmaple: {'LED-GRE': [Batch001, Batch002]}
# get item-wise batch no data
# example: {'LED-GRE': [Batch001, Batch002]}
# where LED-GRE is item code, SN0001 is serial no and Pune is warehouse

itemwise_barcode = {}
Expand Down

0 comments on commit a87bb21

Please sign in to comment.