Fixed merge conflict
This commit is contained in:
commit
1cc55fbbcb
@ -420,6 +420,7 @@ $.extend(erpnext.journal_entry, {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate",
|
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_exchange_rate",
|
||||||
args: {
|
args: {
|
||||||
|
posting_date: frm.doc.posting_date,
|
||||||
account: row.account,
|
account: row.account,
|
||||||
account_currency: row.account_currency,
|
account_currency: row.account_currency,
|
||||||
company: frm.doc.company,
|
company: frm.doc.company,
|
||||||
|
@ -326,8 +326,9 @@ class JournalEntry(AccountsController):
|
|||||||
if d.account_currency == self.company_currency:
|
if d.account_currency == self.company_currency:
|
||||||
d.exchange_rate = 1
|
d.exchange_rate = 1
|
||||||
elif not d.exchange_rate or d.exchange_rate == 1 or \
|
elif not d.exchange_rate or d.exchange_rate == 1 or \
|
||||||
(d.reference_type in ("Sales Invoice", "Purchase Invoice") and d.reference_name):
|
(d.reference_type in ("Sales Invoice", "Purchase Invoice") and d.reference_name and d.posting_date):
|
||||||
d.exchange_rate = get_exchange_rate(d.account, d.account_currency, self.company,
|
# Modified to include the posting date for which to retreive the exchange rate
|
||||||
|
d.exchange_rate = get_exchange_rate(self.posting_date, d.account, d.account_currency, self.company,
|
||||||
d.reference_type, d.reference_name, d.debit, d.credit, d.exchange_rate)
|
d.reference_type, d.reference_name, d.debit, d.credit, d.exchange_rate)
|
||||||
|
|
||||||
if not d.exchange_rate:
|
if not d.exchange_rate:
|
||||||
@ -648,7 +649,8 @@ def get_payment_entry(ref_doc, args):
|
|||||||
cost_center = frappe.db.get_value("Company", ref_doc.company, "cost_center")
|
cost_center = frappe.db.get_value("Company", ref_doc.company, "cost_center")
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
if args.get("party_account"):
|
if args.get("party_account"):
|
||||||
exchange_rate = get_exchange_rate(args.get("party_account"), args.get("party_account_currency"),
|
# Modified to include the posting date for which the exchange rate is required. Assumed to be the posting date in the reference document
|
||||||
|
exchange_rate = get_exchange_rate(ref_doc.posting_date, args.get("party_account"), args.get("party_account_currency"),
|
||||||
ref_doc.company, ref_doc.doctype, ref_doc.name)
|
ref_doc.company, ref_doc.doctype, ref_doc.name)
|
||||||
|
|
||||||
je = frappe.new_doc("Journal Entry")
|
je = frappe.new_doc("Journal Entry")
|
||||||
@ -681,7 +683,9 @@ def get_payment_entry(ref_doc, args):
|
|||||||
bank_account = get_default_bank_cash_account(ref_doc.company, "Bank", account=args.get("bank_account"))
|
bank_account = get_default_bank_cash_account(ref_doc.company, "Bank", account=args.get("bank_account"))
|
||||||
if bank_account:
|
if bank_account:
|
||||||
bank_row.update(bank_account)
|
bank_row.update(bank_account)
|
||||||
bank_row.exchange_rate = get_exchange_rate(bank_account["account"],
|
# Modified to include the posting date for which the exchange rate is required. Assumed to be the posting date of the
|
||||||
|
# reference date
|
||||||
|
bank_row.exchange_rate = get_exchange_rate(ref_doc.posting_date, bank_account["account"],
|
||||||
bank_account["account_currency"], ref_doc.company)
|
bank_account["account_currency"], ref_doc.company)
|
||||||
|
|
||||||
bank_row.cost_center = cost_center
|
bank_row.cost_center = cost_center
|
||||||
@ -805,7 +809,9 @@ def get_account_balance_and_party_type(account, date, company, debit=None, credi
|
|||||||
"party_type": party_type,
|
"party_type": party_type,
|
||||||
"account_type": account_details.account_type,
|
"account_type": account_details.account_type,
|
||||||
"account_currency": account_details.account_currency or company_currency,
|
"account_currency": account_details.account_currency or company_currency,
|
||||||
"exchange_rate": get_exchange_rate(account, account_details.account_currency,
|
# The date used to retreive the exchange rate here is the date passed in as an argument to this function.
|
||||||
|
# It is assumed to be the date on which the balance is sought
|
||||||
|
"exchange_rate": get_exchange_rate(date, account, account_details.account_currency,
|
||||||
company, debit=debit, credit=credit, exchange_rate=exchange_rate)
|
company, debit=debit, credit=credit, exchange_rate=exchange_rate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -815,8 +821,9 @@ def get_account_balance_and_party_type(account, date, company, debit=None, credi
|
|||||||
|
|
||||||
return grid_values
|
return grid_values
|
||||||
|
|
||||||
|
# Added posting_date as one of the parameters of get_exchange_rate
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_exchange_rate(account, account_currency=None, company=None,
|
def get_exchange_rate(posting_date, account, account_currency=None, company=None,
|
||||||
reference_type=None, reference_name=None, debit=None, credit=None, exchange_rate=None):
|
reference_type=None, reference_name=None, debit=None, credit=None, exchange_rate=None):
|
||||||
from erpnext.setup.utils import get_exchange_rate
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
account_details = frappe.db.get_value("Account", account,
|
account_details = frappe.db.get_value("Account", account,
|
||||||
@ -842,8 +849,9 @@ def get_exchange_rate(account, account_currency=None, company=None,
|
|||||||
(account_details.root_type == "Liability" and debit)):
|
(account_details.root_type == "Liability" and debit)):
|
||||||
exchange_rate = get_average_exchange_rate(account)
|
exchange_rate = get_average_exchange_rate(account)
|
||||||
|
|
||||||
if not exchange_rate and account_currency:
|
if not exchange_rate and account_currency and posting_date:
|
||||||
exchange_rate = get_exchange_rate(account_currency, company_currency)
|
# The date used to retreive the exchange rate here is the date passed in as an argument to this function.
|
||||||
|
exchange_rate = get_exchange_rate(posting_date, account_currency, company_currency)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
|
@ -327,6 +327,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
frappe.call({
|
frappe.call({
|
||||||
method: "erpnext.setup.utils.get_exchange_rate",
|
method: "erpnext.setup.utils.get_exchange_rate",
|
||||||
args: {
|
args: {
|
||||||
|
posting_date: frm.doc.posting_date,
|
||||||
from_currency: from_currency,
|
from_currency: from_currency,
|
||||||
to_currency: to_currency
|
to_currency: to_currency
|
||||||
},
|
},
|
||||||
@ -425,6 +426,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_outstanding_reference_documents',
|
method: 'erpnext.accounts.doctype.payment_entry.payment_entry.get_outstanding_reference_documents',
|
||||||
args: {
|
args: {
|
||||||
args: {
|
args: {
|
||||||
|
"posting_date": frm.doc.posting_date,
|
||||||
"company": frm.doc.company,
|
"company": frm.doc.company,
|
||||||
"party_type": frm.doc.party_type,
|
"party_type": frm.doc.party_type,
|
||||||
"payment_type": frm.doc.payment_type,
|
"payment_type": frm.doc.payment_type,
|
||||||
|
@ -152,11 +152,11 @@ class PaymentEntry(AccountsController):
|
|||||||
elif self.payment_type in ("Pay", "Internal Transfer"):
|
elif self.payment_type in ("Pay", "Internal Transfer"):
|
||||||
self.source_exchange_rate = get_average_exchange_rate(self.paid_from)
|
self.source_exchange_rate = get_average_exchange_rate(self.paid_from)
|
||||||
else:
|
else:
|
||||||
self.source_exchange_rate = get_exchange_rate(self.paid_from_account_currency,
|
self.source_exchange_rate = get_exchange_rate(self.posting_date, self.paid_from_account_currency,
|
||||||
self.company_currency)
|
self.company_currency)
|
||||||
|
|
||||||
if self.paid_to and not self.target_exchange_rate:
|
if self.paid_to and not self.target_exchange_rate:
|
||||||
self.target_exchange_rate = get_exchange_rate(self.paid_to_account_currency,
|
self.target_exchange_rate = get_exchange_rate(self.posting_date, self.paid_to_account_currency,
|
||||||
self.company_currency)
|
self.company_currency)
|
||||||
|
|
||||||
def validate_mandatory(self):
|
def validate_mandatory(self):
|
||||||
@ -482,12 +482,12 @@ def get_outstanding_reference_documents(args):
|
|||||||
d["exchange_rate"] = frappe.db.get_value(d.voucher_type, d.voucher_no, "conversion_rate")
|
d["exchange_rate"] = frappe.db.get_value(d.voucher_type, d.voucher_no, "conversion_rate")
|
||||||
|
|
||||||
# Get all SO / PO which are not fully billed or aginst which full advance not paid
|
# Get all SO / PO which are not fully billed or aginst which full advance not paid
|
||||||
orders_to_be_billed = get_orders_to_be_billed(args.get("party_type"), args.get("party"),
|
orders_to_be_billed = get_orders_to_be_billed(args.get("posting_date"),args.get("party_type"), args.get("party"),
|
||||||
party_account_currency, company_currency)
|
party_account_currency, company_currency)
|
||||||
|
|
||||||
return negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed
|
return negative_outstanding_invoices + outstanding_invoices + orders_to_be_billed
|
||||||
|
|
||||||
def get_orders_to_be_billed(party_type, party, party_account_currency, company_currency):
|
def get_orders_to_be_billed(posting_date, party_type, party, party_account_currency, company_currency):
|
||||||
voucher_type = 'Sales Order' if party_type == "Customer" else 'Purchase Order'
|
voucher_type = 'Sales Order' if party_type == "Customer" else 'Purchase Order'
|
||||||
|
|
||||||
ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total"
|
ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total"
|
||||||
@ -517,7 +517,8 @@ def get_orders_to_be_billed(party_type, party, party_account_currency, company_c
|
|||||||
order_list = []
|
order_list = []
|
||||||
for d in orders:
|
for d in orders:
|
||||||
d["voucher_type"] = voucher_type
|
d["voucher_type"] = voucher_type
|
||||||
d["exchange_rate"] = get_exchange_rate(party_account_currency, company_currency)
|
# This assumes that the exchange rate required is the one in the SO
|
||||||
|
d["exchange_rate"] = get_exchange_rate(posting_date,party_account_currency, company_currency)
|
||||||
order_list.append(d)
|
order_list.append(d)
|
||||||
|
|
||||||
return order_list
|
return order_list
|
||||||
@ -592,14 +593,16 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre
|
|||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
else:
|
else:
|
||||||
total_amount = ref_doc.grand_total
|
total_amount = ref_doc.grand_total
|
||||||
|
# Get the exchange rate from the original ref doc or get it based on the posting date of the ref doc
|
||||||
exchange_rate = ref_doc.get("conversion_rate") or \
|
exchange_rate = ref_doc.get("conversion_rate") or \
|
||||||
get_exchange_rate(party_account_currency, ref_doc.company_currency)
|
get_exchange_rate(ref_doc.posting_date, party_account_currency, ref_doc.company_currency)
|
||||||
|
|
||||||
outstanding_amount = ref_doc.get("outstanding_amount") \
|
outstanding_amount = ref_doc.get("outstanding_amount") \
|
||||||
if reference_doctype in ("Sales Invoice", "Purchase Invoice") \
|
if reference_doctype in ("Sales Invoice", "Purchase Invoice") \
|
||||||
else flt(total_amount) - flt(ref_doc.advance_paid)
|
else flt(total_amount) - flt(ref_doc.advance_paid)
|
||||||
else:
|
else:
|
||||||
exchange_rate = get_exchange_rate(party_account_currency, ref_doc.company_currency)
|
# Get the exchange rate based on the posting date of the ref doc
|
||||||
|
exchange_rate = get_exchange_rate(ref_doc.posting_date, party_account_currency, ref_doc.company_currency)
|
||||||
|
|
||||||
return frappe._dict({
|
return frappe._dict({
|
||||||
"due_date": ref_doc.get("due_date"),
|
"due_date": ref_doc.get("due_date"),
|
||||||
|
@ -9,6 +9,7 @@ from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_orde
|
|||||||
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
|
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request
|
||||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||||
from erpnext.setup.utils import get_exchange_rate
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
|
from frappe.utils import nowdate
|
||||||
# test_records = frappe.get_test_records('Payment Request')
|
# test_records = frappe.get_test_records('Payment Request')
|
||||||
|
|
||||||
test_dependencies = ["Currency Exchange", "Journal Entry", "Contact", "Address"]
|
test_dependencies = ["Currency Exchange", "Journal Entry", "Contact", "Address"]
|
||||||
@ -52,7 +53,7 @@ class TestPaymentRequest(unittest.TestCase):
|
|||||||
self.assertEquals(pr.reference_name, so_inr.name)
|
self.assertEquals(pr.reference_name, so_inr.name)
|
||||||
self.assertEquals(pr.currency, "INR")
|
self.assertEquals(pr.currency, "INR")
|
||||||
|
|
||||||
conversion_rate = get_exchange_rate("USD", "INR")
|
conversion_rate = get_exchange_rate(nowdate(), "USD", "INR")
|
||||||
|
|
||||||
si_usd = create_sales_invoice(currency="USD", conversion_rate=conversion_rate)
|
si_usd = create_sales_invoice(currency="USD", conversion_rate=conversion_rate)
|
||||||
pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com")
|
pr = make_payment_request(dt="Sales Invoice", dn=si_usd.name, recipient_id="saurabh@erpnext.com")
|
||||||
|
@ -64,7 +64,7 @@ def update_pos_profile_data(doc, pos_profile, company_data):
|
|||||||
doc.currency = pos_profile.get('currency') or company_data.default_currency
|
doc.currency = pos_profile.get('currency') or company_data.default_currency
|
||||||
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.conversion_rate = get_exchange_rate(doc.posting_date, doc.currency, company_data.default_currency)
|
||||||
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')
|
||||||
doc.naming_series = pos_profile.get('naming_series') or 'SINV-'
|
doc.naming_series = pos_profile.get('naming_series') or 'SINV-'
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from erpnext.setup.utils import get_exchange_rate
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
|
from erpnext.utils import nowdate
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
@ -39,7 +40,7 @@ def get_quote_list(item, qty_list):
|
|||||||
#Add a row for each supplier
|
#Add a row for each supplier
|
||||||
for root in set(suppliers):
|
for root in set(suppliers):
|
||||||
supplier_currency = frappe.db.get_value("Supplier",root,"default_currency")
|
supplier_currency = frappe.db.get_value("Supplier",root,"default_currency")
|
||||||
exg = get_exchange_rate(supplier_currency,company_currency)
|
exg = get_exchange_rate(nowdate(),supplier_currency,company_currency)
|
||||||
|
|
||||||
row = frappe._dict({
|
row = frappe._dict({
|
||||||
"supplier_name": root
|
"supplier_name": root
|
||||||
|
@ -127,6 +127,11 @@ class AccountsController(TransactionBase):
|
|||||||
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company)
|
validate_due_date(self.posting_date, self.due_date, "Supplier", self.supplier, self.company)
|
||||||
|
|
||||||
def set_price_list_currency(self, buying_or_selling):
|
def set_price_list_currency(self, buying_or_selling):
|
||||||
|
if self.meta.get_field("posting_date"):
|
||||||
|
translation_date = self.posting_date
|
||||||
|
else:
|
||||||
|
translation_date = self.transaction_date
|
||||||
|
|
||||||
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" \
|
fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
|
||||||
@ -139,7 +144,7 @@ class AccountsController(TransactionBase):
|
|||||||
self.plc_conversion_rate = 1.0
|
self.plc_conversion_rate = 1.0
|
||||||
|
|
||||||
elif not self.plc_conversion_rate:
|
elif not self.plc_conversion_rate:
|
||||||
self.plc_conversion_rate = get_exchange_rate(
|
self.plc_conversion_rate = get_exchange_rate(translation_date,
|
||||||
self.price_list_currency, self.company_currency)
|
self.price_list_currency, self.company_currency)
|
||||||
|
|
||||||
# currency
|
# currency
|
||||||
@ -149,7 +154,7 @@ class AccountsController(TransactionBase):
|
|||||||
elif self.currency == self.company_currency:
|
elif self.currency == self.company_currency:
|
||||||
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(translation_date, self.currency,
|
||||||
self.company_currency)
|
self.company_currency)
|
||||||
|
|
||||||
def set_missing_item_details(self, for_validate=False):
|
def set_missing_item_details(self, for_validate=False):
|
||||||
@ -602,7 +607,6 @@ class AccountsController(TransactionBase):
|
|||||||
for item in duplicate_list:
|
for item in duplicate_list:
|
||||||
self.remove(item)
|
self.remove(item)
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_tax_rate(account_head):
|
def get_tax_rate(account_head):
|
||||||
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
||||||
|
@ -205,7 +205,7 @@ def make_quotation(source_name, target_doc=None):
|
|||||||
if company_currency == quotation.currency:
|
if company_currency == quotation.currency:
|
||||||
exchange_rate = 1
|
exchange_rate = 1
|
||||||
else:
|
else:
|
||||||
exchange_rate = get_exchange_rate(quotation.currency, company_currency)
|
exchange_rate = get_exchange_rate(quotation.transaction_date, quotation.currency, company_currency)
|
||||||
|
|
||||||
quotation.conversion_rate = exchange_rate
|
quotation.conversion_rate = exchange_rate
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from erpnext.exceptions import InvalidCurrency
|
|||||||
from erpnext.stock.doctype.material_request.material_request import make_request_for_quotation
|
from erpnext.stock.doctype.material_request.material_request import make_request_for_quotation
|
||||||
from erpnext.buying.doctype.request_for_quotation.request_for_quotation import \
|
from erpnext.buying.doctype.request_for_quotation.request_for_quotation import \
|
||||||
make_supplier_quotation as make_quotation_from_rfq
|
make_supplier_quotation as make_quotation_from_rfq
|
||||||
|
from frappe.utils.nowdate
|
||||||
|
|
||||||
def work():
|
def work():
|
||||||
frappe.set_user(frappe.db.get_global('demo_purchase_user'))
|
frappe.set_user(frappe.db.get_global('demo_purchase_user'))
|
||||||
@ -56,7 +57,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(nowdate(), party_account_currency, company_currency)
|
||||||
|
|
||||||
# make supplier quotations
|
# make supplier quotations
|
||||||
if random.random() < 0.2:
|
if random.random() < 0.2:
|
||||||
|
@ -9,6 +9,7 @@ from frappe.utils.make_random import add_random_children, get_random
|
|||||||
from erpnext.setup.utils import get_exchange_rate
|
from erpnext.setup.utils import get_exchange_rate
|
||||||
from erpnext.accounts.party import get_party_account_currency
|
from erpnext.accounts.party import get_party_account_currency
|
||||||
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request, make_payment_entry
|
from erpnext.accounts.doctype.payment_request.payment_request import make_payment_request, make_payment_entry
|
||||||
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
def work():
|
def work():
|
||||||
frappe.set_user(frappe.db.get_global('demo_sales_user_2'))
|
frappe.set_user(frappe.db.get_global('demo_sales_user_2'))
|
||||||
@ -88,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(nowdate(), party_account_currency, company_currency)
|
||||||
|
|
||||||
qtn = frappe.get_doc({
|
qtn = frappe.get_doc({
|
||||||
"creation": frappe.flags.current_date,
|
"creation": frappe.flags.current_date,
|
||||||
|
@ -450,6 +450,10 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
currency: function() {
|
currency: function() {
|
||||||
|
/* manqala 19/09/2016: let the translation date be whichever of the transaction_date or posting_date is available */
|
||||||
|
translation_date = this.frm.doc.transaction_date || this.frm.doc.posting_date;
|
||||||
|
/* end manqala */
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
this.set_dynamic_labels();
|
this.set_dynamic_labels();
|
||||||
|
|
||||||
@ -457,7 +461,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
||||||
if(this.frm.doc.currency && this.frm.doc.currency !== company_currency
|
if(this.frm.doc.currency && this.frm.doc.currency !== company_currency
|
||||||
&& !this.frm.doc.ignore_pricing_rule) {
|
&& !this.frm.doc.ignore_pricing_rule) {
|
||||||
this.get_exchange_rate(this.frm.doc.currency, company_currency,
|
this.get_exchange_rate(translation_date, this.frm.doc.currency, company_currency,
|
||||||
function(exchange_rate) {
|
function(exchange_rate) {
|
||||||
me.frm.set_value("conversion_rate", exchange_rate);
|
me.frm.set_value("conversion_rate", exchange_rate);
|
||||||
});
|
});
|
||||||
@ -485,10 +489,11 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get_exchange_rate: function(from_currency, to_currency, callback) {
|
get_exchange_rate: function(translation_date, from_currency, to_currency, callback) {
|
||||||
return frappe.call({
|
return frappe.call({
|
||||||
method: "erpnext.setup.utils.get_exchange_rate",
|
method: "erpnext.setup.utils.get_exchange_rate",
|
||||||
args: {
|
args: {
|
||||||
|
translation_date: translation_date,
|
||||||
from_currency: from_currency,
|
from_currency: from_currency,
|
||||||
to_currency: to_currency
|
to_currency: to_currency
|
||||||
},
|
},
|
||||||
@ -505,7 +510,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
|||||||
var company_currency = this.get_company_currency();
|
var company_currency = this.get_company_currency();
|
||||||
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
// Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
|
||||||
if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
|
if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
|
||||||
this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency,
|
this.get_exchange_rate(this.frm.doc.posting_date, this.frm.doc.price_list_currency, company_currency,
|
||||||
function(exchange_rate) {
|
function(exchange_rate) {
|
||||||
me.frm.set_value("plc_conversion_rate", exchange_rate);
|
me.frm.set_value("plc_conversion_rate", exchange_rate);
|
||||||
});
|
});
|
||||||
|
@ -12,6 +12,33 @@
|
|||||||
"editable_grid": 0,
|
"editable_grid": 0,
|
||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"fieldname": "date",
|
||||||
|
"fieldtype": "Date",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 1,
|
||||||
|
"label": "Date",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 1,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0,
|
||||||
|
"width": "5"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -38,7 +65,8 @@
|
|||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0,
|
||||||
|
"width": "3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -51,8 +79,12 @@
|
|||||||
"ignore_user_permissions": 0,
|
"ignore_user_permissions": 0,
|
||||||
"ignore_xss_filter": 0,
|
"ignore_xss_filter": 0,
|
||||||
"in_filter": 0,
|
"in_filter": 0,
|
||||||
|
<<<<<<< HEAD
|
||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
|
=======
|
||||||
|
"in_list_view": 0,
|
||||||
|
>>>>>>> 4a0c8400762adb857c8e929d3af56ba83d8c3f76
|
||||||
"label": "To Currency",
|
"label": "To Currency",
|
||||||
"length": 0,
|
"length": 0,
|
||||||
"no_copy": 0,
|
"no_copy": 0,
|
||||||
@ -66,7 +98,8 @@
|
|||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0,
|
||||||
|
"width": "3"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
@ -94,7 +127,8 @@
|
|||||||
"reqd": 1,
|
"reqd": 1,
|
||||||
"search_index": 0,
|
"search_index": 0,
|
||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0,
|
||||||
|
"width": "3"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"hide_heading": 0,
|
"hide_heading": 0,
|
||||||
@ -108,7 +142,11 @@
|
|||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
|
<<<<<<< HEAD
|
||||||
"modified": "2016-11-07 05:28:09.772560",
|
"modified": "2016-11-07 05:28:09.772560",
|
||||||
|
=======
|
||||||
|
"modified": "2016-09-05 22:47:38.746711",
|
||||||
|
>>>>>>> 4a0c8400762adb857c8e929d3af56ba83d8c3f76
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Currency Exchange",
|
"name": "Currency Exchange",
|
||||||
@ -202,5 +240,8 @@
|
|||||||
"quick_entry": 1,
|
"quick_entry": 1,
|
||||||
"read_only": 0,
|
"read_only": 0,
|
||||||
"read_only_onload": 0,
|
"read_only_onload": 0,
|
||||||
|
"sort_field": "name",
|
||||||
|
"sort_order": "DESC",
|
||||||
|
"title_field": "",
|
||||||
"track_seen": 0
|
"track_seen": 0
|
||||||
}
|
}
|
@ -7,10 +7,12 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import get_datetime, get_datetime_str, formatdate
|
||||||
|
|
||||||
class CurrencyExchange(Document):
|
class CurrencyExchange(Document):
|
||||||
def autoname(self):
|
def autoname(self):
|
||||||
self.name = self.from_currency + "-" + self.to_currency
|
self.name = formatdate(get_datetime_str(self.date),"yyyy-MM-dd") + "-" + self.from_currency + "-" + self.to_currency
|
||||||
|
#self.name = self.date + "-" + self.from_currency + "-" + self.to_currency
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_value("exchange_rate", ">", 0)
|
self.validate_value("exchange_rate", ">", 0)
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"doctype": "Currency Exchange",
|
"doctype": "Currency Exchange",
|
||||||
|
"date": "01-01-2016",
|
||||||
"exchange_rate": 60.0,
|
"exchange_rate": 60.0,
|
||||||
"from_currency": "USD",
|
"from_currency": "USD",
|
||||||
"to_currency": "INR"
|
"to_currency": "INR"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Currency Exchange",
|
"doctype": "Currency Exchange",
|
||||||
|
"date": "01-01-2016",
|
||||||
"exchange_rate": 0.773,
|
"exchange_rate": 0.773,
|
||||||
"from_currency": "USD",
|
"from_currency": "USD",
|
||||||
"to_currency": "EUR"
|
"to_currency": "EUR"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"doctype": "Currency Exchange",
|
"doctype": "Currency Exchange",
|
||||||
|
"date": "01-01-2016",
|
||||||
"exchange_rate": 0.0167,
|
"exchange_rate": 0.0167,
|
||||||
"from_currency": "INR",
|
"from_currency": "INR",
|
||||||
"to_currency": "USD"
|
"to_currency": "USD"
|
||||||
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _, throw
|
from frappe import _, throw
|
||||||
from frappe.utils import flt
|
from frappe.utils import flt
|
||||||
|
from frappe.utils import get_datetime, get_datetime_str
|
||||||
|
|
||||||
def get_company_currency(company):
|
def get_company_currency(company):
|
||||||
currency = frappe.db.get_value("Company", company, "default_currency", cache=True)
|
currency = frappe.db.get_value("Company", company, "default_currency", cache=True)
|
||||||
@ -64,17 +65,19 @@ def before_tests():
|
|||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_exchange_rate(from_currency, to_currency):
|
def get_exchange_rate(translation_date, from_currency, to_currency):
|
||||||
if not (from_currency and to_currency):
|
if not (translation_date and from_currency and to_currency):
|
||||||
|
# manqala 19/09/2016: Should this be an empty return or should it throw and exception?
|
||||||
return
|
return
|
||||||
|
|
||||||
if from_currency == to_currency:
|
if from_currency == to_currency:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
exchange = "%s-%s" % (from_currency, to_currency)
|
# cksgb 19/09/2016: get all entries in Currency Exchange with from_currency and to_currency. Order by date desc. Top one is the required exchange rate
|
||||||
value = flt(frappe.db.get_value("Currency Exchange", exchange, "exchange_rate"))
|
entries = frappe.get_all("Currency Exchange", fields = ["*"], filters=[["date", "<=", get_datetime_str(translation_date)], ["from_currency", "=", from_currency], ["to_currency", "=", to_currency]], order_by="date desc")
|
||||||
|
if entries:
|
||||||
|
return flt(entries[0].exchange_rate)
|
||||||
|
|
||||||
if not value:
|
|
||||||
try:
|
try:
|
||||||
cache = frappe.cache()
|
cache = frappe.cache()
|
||||||
key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency)
|
key = "currency_exchange_rate:{0}:{1}".format(from_currency, to_currency)
|
||||||
@ -93,7 +96,5 @@ def get_exchange_rate(from_currency, to_currency):
|
|||||||
|
|
||||||
return flt(value)
|
return flt(value)
|
||||||
except:
|
except:
|
||||||
frappe.msgprint(_("Unable to find exchange rate for {0} to {1}").format(from_currency, to_currency))
|
frappe.msgprint(_("Unable to find exchange rate for {0} to {1} for key date {2}").format(from_currency, to_currency, translation_date))
|
||||||
return 0.0
|
return 0.0
|
||||||
else:
|
|
||||||
return value
|
|
||||||
|
@ -8,6 +8,7 @@ import frappe
|
|||||||
from frappe import _, msgprint
|
from frappe import _, msgprint
|
||||||
from frappe.utils import comma_and
|
from frappe.utils import comma_and
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import get_datetime, get_datetime_str, now_datetime
|
||||||
|
|
||||||
class ShoppingCartSetupError(frappe.ValidationError): pass
|
class ShoppingCartSetupError(frappe.ValidationError): pass
|
||||||
|
|
||||||
@ -39,10 +40,17 @@ class ShoppingCartSettings(Document):
|
|||||||
for currency in price_list_currency_map.values()
|
for currency in price_list_currency_map.values()
|
||||||
if currency != company_currency]
|
if currency != company_currency]
|
||||||
|
|
||||||
|
# manqala 20/09/2016: set up selection parameters for query from tabCurrency Exchange
|
||||||
|
from_currency = [currency for currency in price_list_currency_map.values() if currency != company_currency]
|
||||||
|
to_currency = company_currency
|
||||||
|
# manqala end
|
||||||
|
|
||||||
if expected_to_exist:
|
if expected_to_exist:
|
||||||
exists = frappe.db.sql_list("""select name from `tabCurrency Exchange`
|
# manqala 20/09/2016: modify query so that it uses date in the selection from Currency Exchange.
|
||||||
where name in (%s)""" % (", ".join(["%s"]*len(expected_to_exist)),),
|
# exchange rates defined with date less than the date on which this document is being saved will be selected
|
||||||
tuple(expected_to_exist))
|
exists = frappe.db.sql_list("""select CONCAT(from_currency,'-',to_currency) from `tabCurrency Exchange`
|
||||||
|
where from_currency in (%s) and to_currency = "%s" and date <= curdate()""" % (", ".join(["%s"]*len(from_currency)), to_currency), tuple(from_currency))
|
||||||
|
# manqala end
|
||||||
|
|
||||||
missing = list(set(expected_to_exist).difference(exists))
|
missing = list(set(expected_to_exist).difference(exists))
|
||||||
|
|
||||||
|
@ -481,7 +481,8 @@ def get_price_list_currency_and_exchange_rate(args):
|
|||||||
|
|
||||||
if (not plc_conversion_rate) or (price_list_currency and args.price_list_currency \
|
if (not plc_conversion_rate) or (price_list_currency and args.price_list_currency \
|
||||||
and price_list_currency != args.price_list_currency):
|
and price_list_currency != args.price_list_currency):
|
||||||
plc_conversion_rate = get_exchange_rate(price_list_currency, args.currency) or plc_conversion_rate
|
# cksgb 19/09/2016: added args.transaction_date as posting_date argument for get_exchange_rate
|
||||||
|
plc_conversion_rate = get_exchange_rate(args.transaction_date, price_list_currency, args.currency) or plc_conversion_rate
|
||||||
|
|
||||||
return frappe._dict({
|
return frappe._dict({
|
||||||
"price_list_currency": price_list_currency,
|
"price_list_currency": price_list_currency,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user