Merge pull request #33200 from deepeshgarg007/buying_selling_pricing_rule
fix: Buying and selling check in pricing rule
This commit is contained in:
commit
7d41f63c5d
@ -255,7 +255,7 @@ def apply_pricing_rule(args, doc=None):
|
|||||||
for item in item_list:
|
for item in item_list:
|
||||||
args_copy = copy.deepcopy(args)
|
args_copy = copy.deepcopy(args)
|
||||||
args_copy.update(item)
|
args_copy.update(item)
|
||||||
data = get_pricing_rule_for_item(args_copy, item.get("price_list_rate"), doc=doc)
|
data = get_pricing_rule_for_item(args_copy, doc=doc)
|
||||||
out.append(data)
|
out.append(data)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -292,7 +292,7 @@ def update_pricing_rule_uom(pricing_rule, args):
|
|||||||
pricing_rule.uom = row.uom
|
pricing_rule.uom = row.uom
|
||||||
|
|
||||||
|
|
||||||
def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=False):
|
def get_pricing_rule_for_item(args, doc=None, for_validate=False):
|
||||||
from erpnext.accounts.doctype.pricing_rule.utils import (
|
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||||
get_applied_pricing_rules,
|
get_applied_pricing_rules,
|
||||||
get_pricing_rule_items,
|
get_pricing_rule_items,
|
||||||
|
|||||||
@ -1123,7 +1123,7 @@ def make_pricing_rule(**args):
|
|||||||
"apply_on": args.apply_on or "Item Code",
|
"apply_on": args.apply_on or "Item Code",
|
||||||
"applicable_for": args.applicable_for,
|
"applicable_for": args.applicable_for,
|
||||||
"selling": args.selling or 0,
|
"selling": args.selling or 0,
|
||||||
"currency": "USD",
|
"currency": "INR",
|
||||||
"apply_discount_on_rate": args.apply_discount_on_rate or 0,
|
"apply_discount_on_rate": args.apply_discount_on_rate or 0,
|
||||||
"buying": args.buying or 0,
|
"buying": args.buying or 0,
|
||||||
"min_qty": args.min_qty or 0.0,
|
"min_qty": args.min_qty or 0.0,
|
||||||
|
|||||||
@ -250,6 +250,17 @@ def get_other_conditions(conditions, values, args):
|
|||||||
and ifnull(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
and ifnull(`tabPricing Rule`.valid_upto, '2500-12-31')"""
|
||||||
values["transaction_date"] = args.get("transaction_date")
|
values["transaction_date"] = args.get("transaction_date")
|
||||||
|
|
||||||
|
if args.get("doctype") in [
|
||||||
|
"Quotation",
|
||||||
|
"Sales Order",
|
||||||
|
"Delivery Note",
|
||||||
|
"Sales Invoice",
|
||||||
|
"POS Invoice",
|
||||||
|
]:
|
||||||
|
conditions += """ and ifnull(`tabPricing Rule`.selling, 0) = 1"""
|
||||||
|
else:
|
||||||
|
conditions += """ and ifnull(`tabPricing Rule`.buying, 0) = 1"""
|
||||||
|
|
||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|
||||||
@ -669,7 +680,7 @@ def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None):
|
|||||||
item_details.free_item_data.append(free_item_data_args)
|
item_details.free_item_data.append(free_item_data_args)
|
||||||
|
|
||||||
|
|
||||||
def apply_pricing_rule_for_free_items(doc, pricing_rule_args, set_missing_values=False):
|
def apply_pricing_rule_for_free_items(doc, pricing_rule_args):
|
||||||
if pricing_rule_args:
|
if pricing_rule_args:
|
||||||
items = tuple((d.item_code, d.pricing_rules) for d in doc.items if d.is_free_item)
|
items = tuple((d.item_code, d.pricing_rules) for d in doc.items if d.is_free_item)
|
||||||
|
|
||||||
|
|||||||
@ -197,7 +197,7 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
validate_einvoice_fields(self)
|
validate_einvoice_fields(self)
|
||||||
|
|
||||||
if self.doctype != "Material Request":
|
if self.doctype != "Material Request" and not self.ignore_pricing_rule:
|
||||||
apply_pricing_rule_on_transaction(self)
|
apply_pricing_rule_on_transaction(self)
|
||||||
|
|
||||||
def before_cancel(self):
|
def before_cancel(self):
|
||||||
|
|||||||
@ -1130,10 +1130,13 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
|
|
||||||
qty(doc, cdt, cdn) {
|
qty(doc, cdt, cdn) {
|
||||||
let item = frappe.get_doc(cdt, cdn);
|
let item = frappe.get_doc(cdt, cdn);
|
||||||
item.pricing_rules = ''
|
// item.pricing_rules = ''
|
||||||
this.conversion_factor(doc, cdt, cdn, true);
|
frappe.run_serially([
|
||||||
this.calculate_stock_uom_rate(doc, cdt, cdn);
|
() => this.remove_pricing_rule(item),
|
||||||
this.apply_pricing_rule(item, true);
|
() => this.conversion_factor(doc, cdt, cdn, true),
|
||||||
|
() => this.calculate_stock_uom_rate(doc, cdt, cdn),
|
||||||
|
() => this.apply_pricing_rule(item, true)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
calculate_stock_uom_rate(doc, cdt, cdn) {
|
calculate_stock_uom_rate(doc, cdt, cdn) {
|
||||||
@ -1357,16 +1360,21 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
|
|||||||
var item_list = [];
|
var item_list = [];
|
||||||
|
|
||||||
$.each(this.frm.doc["items"] || [], function(i, d) {
|
$.each(this.frm.doc["items"] || [], function(i, d) {
|
||||||
if (d.item_code && !d.is_free_item) {
|
if (d.item_code) {
|
||||||
item_list.push({
|
if (d.is_free_item) {
|
||||||
"doctype": d.doctype,
|
// Simply remove free items
|
||||||
"name": d.name,
|
me.frm.get_field("items").grid.grid_rows[i].remove();
|
||||||
"item_code": d.item_code,
|
} else {
|
||||||
"pricing_rules": d.pricing_rules,
|
item_list.push({
|
||||||
"parenttype": d.parenttype,
|
"doctype": d.doctype,
|
||||||
"parent": d.parent,
|
"name": d.name,
|
||||||
"price_list_rate": d.price_list_rate
|
"item_code": d.item_code,
|
||||||
})
|
"pricing_rules": d.pricing_rules,
|
||||||
|
"parenttype": d.parenttype,
|
||||||
|
"parent": d.parent,
|
||||||
|
"price_list_rate": d.price_list_rate
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return this.frm.call({
|
return this.frm.call({
|
||||||
|
|||||||
@ -113,7 +113,7 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru
|
|||||||
if args.get(key) is None:
|
if args.get(key) is None:
|
||||||
args[key] = value
|
args[key] = value
|
||||||
|
|
||||||
data = get_pricing_rule_for_item(args, out.price_list_rate, doc, for_validate=for_validate)
|
data = get_pricing_rule_for_item(args, doc=doc, for_validate=for_validate)
|
||||||
|
|
||||||
out.update(data)
|
out.update(data)
|
||||||
|
|
||||||
@ -1305,7 +1305,7 @@ def apply_price_list_on_item(args):
|
|||||||
item_doc = frappe.db.get_value("Item", args.item_code, ["name", "variant_of"], as_dict=1)
|
item_doc = frappe.db.get_value("Item", args.item_code, ["name", "variant_of"], as_dict=1)
|
||||||
item_details = get_price_list_rate(args, item_doc)
|
item_details = get_price_list_rate(args, item_doc)
|
||||||
|
|
||||||
item_details.update(get_pricing_rule_for_item(args, item_details.price_list_rate))
|
item_details.update(get_pricing_rule_for_item(args))
|
||||||
|
|
||||||
return item_details
|
return item_details
|
||||||
|
|
||||||
|
|||||||
@ -110,6 +110,7 @@ def get_price(item_code, price_list, customer_group, company, qty=1):
|
|||||||
"conversion_rate": 1,
|
"conversion_rate": 1,
|
||||||
"for_shopping_cart": True,
|
"for_shopping_cart": True,
|
||||||
"currency": frappe.db.get_value("Price List", price_list, "currency"),
|
"currency": frappe.db.get_value("Price List", price_list, "currency"),
|
||||||
|
"doctype": "Quotation",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user