From 29d24cddcf7f9c918ea510a1dd0898841d082d75 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 25 Aug 2020 16:18:44 +0530 Subject: [PATCH 1/3] fix(hot): Pricing Rule encoding fixed --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 8 +++++--- erpnext/accounts/doctype/pricing_rule/utils.py | 11 ++++++++--- erpnext/controllers/accounts_controller.py | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 0c2b5475cb8..6219f68ffe5 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -241,7 +241,7 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa update_args_for_pricing_rule(args) - pricing_rules = (get_applied_pricing_rules(args) + pricing_rules = (get_applied_pricing_rules(args.get('pricing_rules')) if for_validate and args.get("pricing_rules") else get_pricing_rules(args, doc)) if pricing_rules: @@ -369,8 +369,10 @@ def set_discount_amount(rate, item_details): item_details.rate = rate def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): - from erpnext.accounts.doctype.pricing_rule.utils import get_pricing_rule_items - for d in json.loads(pricing_rules): + from erpnext.accounts.doctype.pricing_rule.utils import (get_applied_pricing_rules, + get_pricing_rule_items) + + for d in get_applied_pricing_rules(pricing_rules): if not d or not frappe.db.exists("Pricing Rule", d): continue pricing_rule = frappe.get_cached_doc('Pricing Rule', d) diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 7d20208fc79..09feb7d97bc 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -470,9 +470,14 @@ def apply_pricing_rule_on_transaction(doc): apply_pricing_rule_for_free_items(doc, item_details.free_item_data) doc.set_missing_values() -def get_applied_pricing_rules(item_row): - return (json.loads(item_row.get("pricing_rules")) - if item_row.get("pricing_rules") else []) +def get_applied_pricing_rules(pricing_rules): + if pricing_rules: + if pricing_rules.startswith('['): + return json.loads(pricing_rules) + else: + return pricing_rules.split(',') + + return [] def get_product_discount_rule(pricing_rule, item_details, args=None, doc=None): free_item = pricing_rule.free_item diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 56b872bcfba..4f34f7f3ce4 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -325,7 +325,7 @@ class AccountsController(TransactionBase): apply_pricing_rule_for_free_items(self, pricing_rule_args.get('free_item_data')) elif pricing_rule_args.get("validate_applied_rule"): - for pricing_rule in get_applied_pricing_rules(item): + for pricing_rule in get_applied_pricing_rules(item.get('pricing_rules')): pricing_rule_doc = frappe.get_cached_doc("Pricing Rule", pricing_rule) for field in ['discount_percentage', 'discount_amount', 'rate']: if item.get(field) < pricing_rule_doc.get(field): From 0407a435d7a33f55df21026a5a77721166a587d6 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 25 Aug 2020 18:32:46 +0530 Subject: [PATCH 2/3] fix: mixed condition pricing rule not working on js side --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 3 ++- erpnext/public/js/controllers/transaction.js | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 6219f68ffe5..c5571970595 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -395,7 +395,8 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None): items = get_pricing_rule_items(pricing_rule) item_details.apply_on = (frappe.scrub(pricing_rule.apply_rule_on_other) if pricing_rule.apply_rule_on_other else frappe.scrub(pricing_rule.get('apply_on'))) - item_details.applied_on_items = ','.join(items) + item_details.applied_on_items = json.dumps(items) + item_details.price_or_product_discount = pricing_rule.price_or_product_discount item_details.pricing_rules = '' diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 53c70936c6d..b64a68753b5 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -1413,9 +1413,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ if (data && data.apply_rule_on_other_items) { me.frm.doc.items.forEach(d => { - if (in_list(data.apply_rule_on_other_items, d[data.apply_rule_on])) { + if (in_list(JSON.parse(data.apply_rule_on_other_items), d[data.apply_rule_on])) { for(var k in data) { - if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'price' || k === 'pricing_rules')) { + if (in_list(fields, k) && data[k] && (data.price_or_product_discount === 'Price' || k === 'pricing_rules')) { frappe.model.set_value(d.doctype, d.name, k, data[k]); } } @@ -1499,9 +1499,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ me.frm.doc.items = items; refresh_field('items'); } else if(item.applied_on_items && item.apply_on) { - const applied_on_items = item.applied_on_items.split(','); + const applied_on_items = JSON.parse(item.applied_on_items); me.frm.doc.items.forEach(row => { - if(applied_on_items.includes(row[item.apply_on])) { + if(in_list(applied_on_items, row[item.apply_on])) { fields.forEach(f => { row[f] = 0; }); From f26e66b2b56baf3cd81c73b5a1c064e30bdf2416 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 25 Aug 2020 20:21:54 +0550 Subject: [PATCH 3/3] bumped to version 12.11.1 --- erpnext/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/__init__.py b/erpnext/__init__.py index 7f793f90196..037555c7e49 100644 --- a/erpnext/__init__.py +++ b/erpnext/__init__.py @@ -5,7 +5,7 @@ import frappe from erpnext.hooks import regional_overrides from frappe.utils import getdate -__version__ = '12.11.0' +__version__ = '12.11.1' def get_default_company(user=None): '''Get default company for user'''