Currency filter in Pricing Rule (#11776)

* added currency filter

* modified files

* pull margin only if currency matches

* Renamed price to rate in pricing rule

* fetch rate only if currency matches

* rebase with develop

* rebase with develop

* patch to set currency in existing docs

* currency field mandatory in pricing rule

* modified test cases

* rebase with develop

* fixed test case
This commit is contained in:
Shreya Shah
2018-02-20 11:26:46 +05:30
committed by Nabin Hait
parent 9b74f8bd37
commit f718b0c0df
13 changed files with 261 additions and 51 deletions

View File

@@ -510,13 +510,22 @@ class calculate_taxes_and_totals(object):
self.doc.precision("base_write_off_amount"))
def calculate_margin(self, item):
rate_with_margin = 0.0
base_rate_with_margin = 0.0
if item.price_list_rate:
if item.pricing_rule and not self.doc.ignore_pricing_rule:
pricing_rule = frappe.get_doc('Pricing Rule', item.pricing_rule)
item.margin_type = pricing_rule.margin_type
item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
if pricing_rule.margin_type == 'Amount' and pricing_rule.currency == self.doc.currency:
item.margin_type = pricing_rule.margin_type
item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
elif pricing_rule.margin_type == 'Percentage':
item.margin_type = pricing_rule.margin_type
item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
else:
item.margin_type = None
item.margin_rate_or_amount = 0.0
if item.margin_type and item.margin_rate_or_amount:
margin_value = item.margin_rate_or_amount if item.margin_type == 'Amount' else flt(item.price_list_rate) * flt(item.margin_rate_or_amount) / 100