Merge branch 'develop' of https://github.com/frappe/erpnext into party_account_currency_check
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index ca17265..ea9ac23 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -16,7 +16,7 @@
 from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import (
 	get_party_tax_withholding_details,
 )
-from erpnext.accounts.party import get_party_account
+from erpnext.accounts.party import get_party_account, get_party_gle_currency
 from erpnext.accounts.utils import (
 	check_if_stock_and_account_balance_synced,
 	get_account_currency,
@@ -47,6 +47,7 @@
 		self.clearance_date = None
 
 		self.validate_party()
+		self.validate_party_account_currency()
 		self.validate_entries_for_advance()
 		self.validate_multi_currency()
 		self.set_amounts_in_company_currency()
@@ -291,6 +292,16 @@
 				if not (d.party_type and d.party):
 					frappe.throw(_("Row {0}: Party Type and Party is required for Receivable / Payable account {1}").format(d.idx, d.account))
 
+	def validate_party_account_currency(self):
+		for d in self.get("accounts"):
+			if d.party_type in ('Customer', 'Supplier'):
+				party_gle_currency = get_party_gle_currency(d.party_type, d.party, self.company)
+				party_account_currency = get_account_currency(d.account)
+				party_currency = frappe.db.get_value(d.party_type, d.party, 'default_currency')
+
+				if not party_gle_currency and (party_account_currency != party_currency):
+					frappe.throw(_("Party Account {0} currency and default party currency should be same").format(frappe.bold(d.account)))
+
 	def check_credit_limit(self):
 		customers = list(set(d.party for d in self.get("accounts")
 			if d.party_type=="Customer" and d.party and flt(d.debit) > 0))
diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
index 030b4ca..3b6dd87 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
@@ -75,7 +75,8 @@
 			income_account="Sales - TPC",
 			expense_account="Cost of Goods Sold - TPC",
 			rate=400,
-			debit_to="Debtors - TPC"
+			debit_to="Debtors - TPC",
+			currency="USD"
 		)
 		create_sales_invoice(
 			company=company,
@@ -83,7 +84,8 @@
 			income_account="Sales - TPC",
 			expense_account="Cost of Goods Sold - TPC",
 			rate=200,
-			debit_to="Debtors - TPC"
+			debit_to="Debtors - TPC",
+			currency="USD"
 		)
 
 		pcv = self.make_period_closing_voucher(submit=False)
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 2c92820..3851cf4 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -33,6 +33,7 @@
 from erpnext.accounts.party import (
 	get_party_account,
 	get_party_account_currency,
+	get_party_gle_currency,
 	validate_party_frozen_disabled,
 )
 from erpnext.accounts.utils import get_account_currency, get_fiscal_years, validate_fiscal_year
@@ -144,6 +145,7 @@
 
 		self.validate_party()
 		self.validate_currency()
+		self.validate_party_account_currency()
 
 		if self.doctype in ['Purchase Invoice', 'Sales Invoice']:
 			pos_check_field = "is_pos" if self.doctype=="Sales Invoice" else "is_paid"
@@ -1155,6 +1157,22 @@
 				# at quotation / sales order level and we shouldn't stop someone
 				# from creating a sales invoice if sales order is already created
 
+	def validate_party_account_currency(self):
+		if self.doctype not in ('Sales Invoice', 'Purchase Invoice'):
+			return
+
+		if self.is_opening == 'Yes':
+			return
+
+		party_type, party = self.get_party()
+		party_gle_currency = get_party_gle_currency(party_type, party, self.company)
+		party_account = self.get('debit_to') if self.doctype == 'Sales Invoice' else self.get('credit_to')
+		party_account_currency = get_account_currency(party_account)
+
+		if not party_gle_currency and (party_account_currency != self.currency):
+			frappe.throw(_("Party Account {0} currency and document currency should be same").format(frappe.bold(party_account)))
+
+
 	def delink_advance_entries(self, linked_doc_name):
 		total_allocated_amount = 0
 		for adv in self.advances:
diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py
index beb38e2..7151a3c 100644
--- a/erpnext/non_profit/doctype/membership/membership.py
+++ b/erpnext/non_profit/doctype/membership/membership.py
@@ -12,6 +12,7 @@
 from frappe.utils import add_days, add_months, add_years, get_link_to_form, getdate, nowdate
 
 import erpnext
+from erpnext import get_company_currency
 from erpnext.non_profit.doctype.member.member import create_member
 
 
@@ -176,7 +177,7 @@
 		"doctype": "Sales Invoice",
 		"customer": member.customer,
 		"debit_to": settings.membership_debit_account,
-		"currency": membership.currency,
+		"currency": membership.currency or get_company_currency(settings.company),
 		"company": settings.company,
 		"is_pos": 0,
 		"items": [
diff --git a/erpnext/non_profit/doctype/membership/test_membership.py b/erpnext/non_profit/doctype/membership/test_membership.py
index fbe344c..38a33a7 100644
--- a/erpnext/non_profit/doctype/membership/test_membership.py
+++ b/erpnext/non_profit/doctype/membership/test_membership.py
@@ -82,7 +82,7 @@
 		"member": member,
 		"membership_status": "Current",
 		"membership_type": "_rzpy_test_milythm",
-		"currency": "INR",
+		"currency": "USD",
 		"paid": 1,
 		"from_date": nowdate(),
 		"amount": 100