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:
parent
b547cdd8fa
commit
3f77852e93
@ -97,7 +97,7 @@ def update_pos_profile_data(doc, pos_profile, company_data):
|
|||||||
doc.conversion_rate = 1.0
|
doc.conversion_rate = 1.0
|
||||||
|
|
||||||
if doc.currency != company_data.default_currency:
|
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 \
|
doc.selling_price_list = pos_profile.get('selling_price_list') or \
|
||||||
frappe.db.get_value('Selling Settings', None, 'selling_price_list')
|
frappe.db.get_value('Selling Settings', None, 'selling_price_list')
|
||||||
|
@ -148,8 +148,13 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
if self.meta.get_field("currency"):
|
if self.meta.get_field("currency"):
|
||||||
# price list part
|
# price list part
|
||||||
fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
|
if buying_or_selling.lower() == "selling":
|
||||||
else "buying_price_list"
|
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):
|
if self.meta.get_field(fieldname) and self.get(fieldname):
|
||||||
self.price_list_currency = frappe.db.get_value("Price List",
|
self.price_list_currency = frappe.db.get_value("Price List",
|
||||||
self.get(fieldname), "currency")
|
self.get(fieldname), "currency")
|
||||||
@ -159,7 +164,7 @@ class AccountsController(TransactionBase):
|
|||||||
|
|
||||||
elif not self.plc_conversion_rate:
|
elif not self.plc_conversion_rate:
|
||||||
self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
|
self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
|
||||||
self.company_currency, transaction_date)
|
self.company_currency, transaction_date, args)
|
||||||
|
|
||||||
# currency
|
# currency
|
||||||
if not self.currency:
|
if not self.currency:
|
||||||
@ -169,7 +174,7 @@ class AccountsController(TransactionBase):
|
|||||||
self.conversion_rate = 1.0
|
self.conversion_rate = 1.0
|
||||||
elif not self.conversion_rate:
|
elif not self.conversion_rate:
|
||||||
self.conversion_rate = get_exchange_rate(self.currency,
|
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):
|
def set_missing_item_details(self, for_validate=False):
|
||||||
"""set missing item values"""
|
"""set missing item values"""
|
||||||
|
@ -227,7 +227,7 @@ def make_quotation(source_name, target_doc=None):
|
|||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
else:
|
else:
|
||||||
exchange_rate = get_exchange_rate(quotation.currency, company_currency,
|
exchange_rate = get_exchange_rate(quotation.currency, company_currency,
|
||||||
quotation.transaction_date)
|
quotation.transaction_date, args="for_selling")
|
||||||
|
|
||||||
quotation.conversion_rate = exchange_rate
|
quotation.conversion_rate = exchange_rate
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ def work():
|
|||||||
if company_currency == party_account_currency:
|
if company_currency == party_account_currency:
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
else:
|
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
|
# make supplier quotations
|
||||||
if random.random() < 0.2:
|
if random.random() < 0.2:
|
||||||
|
@ -89,7 +89,7 @@ def make_quotation():
|
|||||||
if company_currency == party_account_currency:
|
if company_currency == party_account_currency:
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
else:
|
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({
|
qtn = frappe.get_doc({
|
||||||
"creation": frappe.flags.current_date,
|
"creation": frappe.flags.current_date,
|
||||||
|
@ -303,7 +303,7 @@ class BOM(WebsiteGenerator):
|
|||||||
if self.currency == self.company_currency():
|
if self.currency == self.company_currency():
|
||||||
self.conversion_rate = 1
|
self.conversion_rate = 1
|
||||||
elif self.conversion_rate == 1 or flt(self.conversion_rate) <= 0:
|
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):
|
def validate_materials(self):
|
||||||
""" Validate raw material entries """
|
""" Validate raw material entries """
|
||||||
|
@ -667,9 +667,14 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) {
|
get_exchange_rate: function(transaction_date, from_currency, to_currency, callback) {
|
||||||
if (this.frm.doctype == "Purchase Order") {
|
var args;
|
||||||
var args = "for_buying";
|
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;
|
if (!transaction_date || !from_currency || !to_currency) return;
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.setup.utils.get_exchange_rate",
|
method: "erpnext.setup.utils.get_exchange_rate",
|
||||||
|
@ -628,6 +628,11 @@ def get_price_list_currency_and_exchange_rate(args):
|
|||||||
if not args.price_list:
|
if not args.price_list:
|
||||||
return {}
|
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_currency = get_price_list_currency(args.price_list)
|
||||||
price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
|
price_list_uom_dependant = get_price_list_uom_dependant(args.price_list)
|
||||||
plc_conversion_rate = args.plc_conversion_rate
|
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):
|
and price_list_currency != args.price_list_currency):
|
||||||
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
|
# 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,
|
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({
|
return frappe._dict({
|
||||||
"price_list_currency": price_list_currency,
|
"price_list_currency": price_list_currency,
|
||||||
|
Loading…
Reference in New Issue
Block a user