Merge branch 'develop' of https://github.com/frappe/erpnext into sales_exchange_rate_validation
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 23ad223..4e0d1c9 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -165,17 +165,6 @@
super(PurchaseInvoice, self).set_missing_values(for_validate)
- def check_conversion_rate(self):
- default_currency = erpnext.get_company_currency(self.company)
- if not default_currency:
- throw(_("Please enter default currency in Company Master"))
- if (
- (self.currency == default_currency and flt(self.conversion_rate) != 1.00)
- or not self.conversion_rate
- or (self.currency != default_currency and flt(self.conversion_rate) == 1.00)
- ):
- throw(_("Conversion rate cannot be 0 or 1"))
-
def validate_credit_to_acc(self):
if not self.credit_to:
self.credit_to = get_party_account("Supplier", self.supplier, self.company)
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index a580d45..1a3164b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -114,6 +114,7 @@
self.set_income_account_for_fixed_assets()
self.validate_item_cost_centers()
self.validate_income_account()
+ self.check_conversion_rate()
validate_inter_company_party(
self.doctype, self.customer, self.company, self.inter_company_invoice_reference
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index b8154dd..1b20c29 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -1583,6 +1583,17 @@
self.assertTrue(gle)
+ def test_invoice_exchange_rate(self):
+ si = create_sales_invoice(
+ customer="_Test Customer USD",
+ debit_to="_Test Receivable USD - _TC",
+ currency="USD",
+ conversion_rate=1,
+ do_not_save=1,
+ )
+
+ self.assertRaises(frappe.ValidationError, si.save)
+
def test_invalid_currency(self):
# Customer currency = USD
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index ded9a30..fc6fdcd 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -1848,6 +1848,17 @@
jv.save()
jv.submit()
+ def check_conversion_rate(self):
+ default_currency = erpnext.get_company_currency(self.company)
+ if not default_currency:
+ throw(_("Please enter default currency in Company Master"))
+ if (
+ (self.currency == default_currency and flt(self.conversion_rate) != 1.00)
+ or not self.conversion_rate
+ or (self.currency != default_currency and flt(self.conversion_rate) == 1.00)
+ ):
+ throw(_("Conversion rate cannot be 0 or 1"))
+
@frappe.whitelist()
def get_tax_rate(account_head):