fix: Pricing rule application/removal on qty change (#39084)
fix: Pricing rule application/removal on qty change (cherry picked from commit f52d7c7665d4097b19a8bb6c5f99acf38cd8adcf) Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
This commit is contained in:
parent
e76f59803c
commit
f31070741a
@ -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
|
||||
|
@ -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)
|
||||
]);
|
||||
@ -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) {
|
||||
@ -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);
|
||||
@ -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;
|
||||
}
|
||||
@ -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) {
|
||||
|
@ -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 = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user