Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Pricing rule application/removal on qty change (backport #39084) #39656

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1200,8 +1200,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 @@ -1448,8 +1449,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 @@ -1488,6 +1489,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 @@ -1712,8 +1741,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 @@ -1755,7 +1784,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
Loading