Pass buying or selling as filter parameters

Wherever get_exchange_rate is called, pass filter buying or selling on the basis of doctype.
This commit is contained in:
Shreya 2018-05-15 16:59:20 +05:30
parent b547cdd8fa
commit 3f77852e93
8 changed files with 27 additions and 12 deletions

View File

@ -97,7 +97,7 @@ def update_pos_profile_data(doc, pos_profile, company_data):
doc.conversion_rate = 1.0
if doc.currency != company_data.default_currency:
doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date)
doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date, args="for_selling")
doc.selling_price_list = pos_profile.get('selling_price_list') or \
frappe.db.get_value('Selling Settings', None, 'selling_price_list')

View File

@ -148,8 +148,13 @@ class AccountsController(TransactionBase):
if self.meta.get_field("currency"):
# price list part
fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
else "buying_price_list"
if buying_or_selling.lower() == "selling":
fieldname = "selling_price_list"
args = "for_selling"
else:
fieldname = "buying_price_list"
args = "for_buying"
if self.meta.get_field(fieldname) and self.get(fieldname):
self.price_list_currency = frappe.db.get_value("Price List",
self.get(fieldname), "currency")
@ -159,7 +164,7 @@ class AccountsController(TransactionBase):
elif not self.plc_conversion_rate:
self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
self.company_currency, transaction_date)
self.company_currency, transaction_date, args)
# currency
if not self.currency:
@ -169,7 +174,7 @@ class AccountsController(TransactionBase):
self.conversion_rate = 1.0
elif not self.conversion_rate:
self.conversion_rate = get_exchange_rate(self.currency,
self.company_currency, transaction_date)
self.company_currency, transaction_date, args)
def set_missing_item_details(self, for_validate=False):
"""set missing item values"""

View File

@ -227,7 +227,7 @@ def make_quotation(source_name, target_doc=None):
exchange_rate = 1
else:
exchange_rate = get_exchange_rate(quotation.currency, company_currency,
quotation.transaction_date)
quotation.transaction_date, args="for_selling")
quotation.conversion_rate = exchange_rate

View File

@ -56,7 +56,7 @@ def work():
if company_currency == party_account_currency:
exchange_rate = 1
else:
exchange_rate = get_exchange_rate(party_account_currency, company_currency)
exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_buying")
# make supplier quotations
if random.random() < 0.2:

View File

@ -89,7 +89,7 @@ def make_quotation():
if company_currency == party_account_currency:
exchange_rate = 1
else:
exchange_rate = get_exchange_rate(party_account_currency, company_currency)
exchange_rate = get_exchange_rate(party_account_currency, company_currency, args="for_selling")
qtn = frappe.get_doc({
"creation": frappe.flags.current_date,

View File

@ -303,7 +303,7 @@ class BOM(WebsiteGenerator):
if self.currency == self.company_currency():
self.conversion_rate = 1
elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0:
self.conversion_rate = get_exchange_rate(self.currency, self.company_currency())
self.conversion_rate = get_exchange_rate(self.currency, self.company_currency(), args="for_buying")
def validate_materials(self):
""" Validate raw material entries """

View File

@ -667,9 +667,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
},
get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) {
if (this.frm.doctype == "Purchase Order") {
var args = "for_buying";
var args;
if (["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].includes(this.frm.doctype)) {
args = "for_selling";
}
else if (["Purchase Order", "Purchase Receipt", "Purchase Invoice"].includes(this.frm.doctype)) {
args = "for_buying";
}
if (!transaction_date || !from_currency || !to_currency) return;
return frappe.call({
method: "erpnext.setup.utils.get_exchange_rate",

View File

@ -628,6 +628,11 @@ def get_price_list_currency_and_exchange_rate(args):
if not args.price_list:
return {}
if args.doctype in ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']:
args.update({"exchange_rate": "for_selling"})
elif args.doctype in ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']:
args.update({"exchange_rate": "for_buying"})
price_list_currency = get_price_list_currency(args.price_list)
price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
plc_conversion_rate = args.plc_conversion_rate
@ -637,7 +642,7 @@ def get_price_list_currency_and_exchange_rate(args):
and price_list_currency != args.price_list_currency):
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
plc_conversion_rate = get_exchange_rate(price_list_currency, company_currency,
args.transaction_date) or plc_conversion_rate
args.transaction_date, args.exchange_rate) or plc_conversion_rate
return frappe._dict({
"price_list_currency": price_list_currency,