From b05a1cb72191c2b1b477970414e799bd996a272e Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Wed, 26 Jun 2024 22:22:47 +0200 Subject: [PATCH 1/2] feat: Additional flags to ignore pricing rules in transactions --- erpnext/controllers/accounts_controller.py | 14 ++++++++++++-- erpnext/controllers/taxes_and_totals.py | 6 +++++- erpnext/public/js/controllers/transaction.js | 2 +- erpnext/stock/get_item_details.py | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 03345272c0..7d3ac4ba6b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -245,7 +245,11 @@ class AccountsController(TransactionBase): with temporary_flag("company", self.company): validate_regional(self) - if self.doctype != "Material Request" and not self.ignore_pricing_rule: + if ( + self.doctype != "Material Request" + and not self.ignore_pricing_rule + and not self.flags.ignore_pricing_rule + ): apply_pricing_rule_on_transaction(self) self.set_total_in_words() @@ -688,7 +692,13 @@ class AccountsController(TransactionBase): args["child_docname"] = item.name args["ignore_pricing_rule"] = ( self.ignore_pricing_rule if hasattr(self, "ignore_pricing_rule") else 0 - ) + ) or self.flags.ignore_pricing_rule + + if not args["ignore_pricing_rule"]: + args["ignore_pricing_rule"] = item.get("ignore_pricing_rule", 0) + + if args["ignore_pricing_rule"]: + args["pricing_rules"] = "" if not args.get("transaction_date"): args["transaction_date"] = args.get("posting_date") diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 80aec45ae2..8bd840d8a0 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -899,7 +899,11 @@ class calculate_taxes_and_totals(object): rate_with_margin = 0.0 base_rate_with_margin = 0.0 if item.price_list_rate: - if item.pricing_rules and not self.doc.ignore_pricing_rule: + if ( + item.pricing_rules + and not self.doc.ignore_pricing_rule + and not self.doc.flags.ignore_pricing_rule + ): has_margin = False for d in get_applied_pricing_rules(item.pricing_rules): pricing_rule = frappe.get_cached_doc("Pricing Rule", d) diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index be7ef44a51..3b13c7473f 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -571,7 +571,7 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe is_pos: cint(me.frm.doc.is_pos), is_return: cint(me.frm.doc.is_return), is_subcontracted: me.frm.doc.is_subcontracted, - ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, + ignore_pricing_rule: me.frm.doc.ignore_pricing_rule || item.ignore_pricing_rule, doctype: me.frm.doc.doctype, name: me.frm.doc.name, project: item.project || me.frm.doc.project, diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 13341b970f..6827c0c9a4 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -370,7 +370,7 @@ def get_basic_details(args, item, overwrite_warehouse=True): "base_amount": 0.0, "net_rate": 0.0, "net_amount": 0.0, - "discount_percentage": 0.0, + "discount_percentage": flt(args.discount_percentage) or 0.0, "discount_amount": flt(args.discount_amount) or 0.0, "update_stock": args.get("update_stock") if args.get("doctype") in ["Sales Invoice", "Purchase Invoice"] -- GitLab From 373b5e20b55197b8ced6a4f18388ab9d0279ce13 Mon Sep 17 00:00:00 2001 From: Charles-Henri Decultot Date: Thu, 27 Jun 2024 16:06:23 +0200 Subject: [PATCH 2/2] fix: pass an explicit flag to remove pricing rules from arguments --- erpnext/controllers/accounts_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 7d3ac4ba6b..6e04e335ce 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -697,7 +697,7 @@ class AccountsController(TransactionBase): if not args["ignore_pricing_rule"]: args["ignore_pricing_rule"] = item.get("ignore_pricing_rule", 0) - if args["ignore_pricing_rule"]: + if args["ignore_pricing_rule"] and self.flags.ignore_pricing_rule: args["pricing_rules"] = "" if not args.get("transaction_date"): -- GitLab