diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 3f8018f7a9a..5af0d9f1be6 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -23,6 +23,8 @@ class PricingRule(Document): self.validate_price_or_discount() self.validate_max_discount() + if not self.margin_type: self.margin_rate_or_amount = 0.0 + def validate_mandatory(self): for field in ["apply_on", "applicable_for"]: tocheck = frappe.scrub(self.get(field) or "") @@ -143,7 +145,7 @@ def get_pricing_rule_for_item(args): }) if args.ignore_pricing_rule or not args.item_code: - if frappe.db.exists(args.doctype, args.name) or args.get("pricing_rule"): + if args.get("pricing_rule"): item_details = remove_pricing_rule(args, item_details) return item_details diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index bcdfe5f52b1..742e59b4d69 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -199,9 +199,8 @@ class AccountsController(TransactionBase): if stock_qty != len(item.get('serial_no').split('\n')): item.set(fieldname, value) - elif fieldname in ["conversion_factor", "price_list_rate"]: - if for_validate and not item.get(fieldname): - item.set(fieldname, value) + elif fieldname == "conversion_factor" and not item.get("conversion_factor"): + item.set(fieldname, value) if ret.get("pricing_rule"): # if user changed the discount percentage then set user's discount percentage ? diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index d84a4fcbd9b..eec789a4ea8 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -570,7 +570,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ item.stock_qty = flt(item.qty * item.conversion_factor, precision("stock_qty", item)); refresh_field("stock_qty", item.name, item.parentfield); this.toggle_conversion_factor(item); - this.apply_price_list(); + this.apply_price_list(item, true); } }, @@ -581,7 +581,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ }, qty: function(doc, cdt, cdn) { - this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true); this.conversion_factor(doc, cdt, cdn); },