diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 55a5b0e513..05652642eb 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -345,9 +345,13 @@ def apply_price_discount_rule(pricing_rule, item_details, args): if ((pricing_rule.margin_type in ['Amount', 'Percentage'] and pricing_rule.currency == args.currency) or (pricing_rule.margin_type == 'Percentage')): item_details.margin_type = pricing_rule.margin_type - item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount item_details.has_margin = True + if pricing_rule.apply_multiple_pricing_rules and item_details.margin_rate_or_amount is not None: + item_details.margin_rate_or_amount += pricing_rule.margin_rate_or_amount + else: + item_details.margin_rate_or_amount = pricing_rule.margin_rate_or_amount + if pricing_rule.rate_or_discount == 'Rate': pricing_rule_rate = 0.0 if pricing_rule.currency == args.currency: diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py index 2c7cd14451..fb1fbe484e 100644 --- a/erpnext/accounts/doctype/pricing_rule/utils.py +++ b/erpnext/accounts/doctype/pricing_rule/utils.py @@ -164,7 +164,15 @@ def _get_tree_conditions(args, parenttype, table, allow_blank=True): frappe.throw(_("Invalid {0}").format(args.get(field))) parent_groups = frappe.db.sql_list("""select name from `tab%s` - where lft<=%s and rgt>=%s""" % (parenttype, '%s', '%s'), (lft, rgt)) + where lft>=%s and rgt<=%s""" % (parenttype, '%s', '%s'), (lft, rgt)) + + if parenttype in ["Customer Group", "Item Group", "Territory"]: + parent_field = "parent_{0}".format(frappe.scrub(parenttype)) + root_name = frappe.db.get_list(parenttype, + {"is_group": 1, parent_field: ("is", "not set")}, "name", as_list=1) + + if root_name and root_name[0][0]: + parent_groups.append(root_name[0][0]) if parent_groups: if allow_blank: parent_groups.append('')