Skip to content

Commit

Permalink
Merge pull request #31411 from frappe/mergify/bp/version-13-hotfix/pr…
Browse files Browse the repository at this point in the history
…-31350

fix: Conversion rate validation for multi-currency invoices (backport #31350)
  • Loading branch information
deepeshgarg007 authored Jun 21, 2022
2 parents e982abb + da70b69 commit 760ba08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 deletions.
11 changes: 0 additions & 11 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ def set_missing_values(self, for_validate=False):

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)
Expand Down
1 change: 1 addition & 0 deletions erpnext/accounts/doctype/sales_invoice/sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def validate(self):
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
Expand Down
11 changes: 11 additions & 0 deletions erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,17 @@ def test_multi_currency_gle(self):

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

Expand Down
11 changes: 11 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,6 +1846,17 @@ def create_advance_and_reconcile(self, party_link):
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):
Expand Down

0 comments on commit 760ba08

Please sign in to comment.