Skip to content

Commit

Permalink
fix: Account currency validation for first transaction
Browse files Browse the repository at this point in the history
(cherry picked from commit 80c85dd)

# Conflicts:
#	erpnext/controllers/accounts_controller.py
  • Loading branch information
deepeshgarg007 authored and mergify[bot] committed May 25, 2022
1 parent 3528d6f commit 228f10b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
set_print_templates_for_taxes,
)
from erpnext.controllers.sales_and_purchase_return import validate_return
<<<<<<< HEAD
=======
from erpnext.accounts.party import get_party_account_currency, validate_party_frozen_disabled, get_party_gle_currency
from erpnext.accounts.doctype.pricing_rule.utils import (apply_pricing_rule_on_transaction,
apply_pricing_rule_for_free_items, get_applied_pricing_rules)
>>>>>>> 80c85dd17c (fix: Account currency validation for first transaction)
from erpnext.exceptions import InvalidCurrency
from erpnext.setup.utils import get_exchange_rate
from erpnext.stock.doctype.packed_item.packed_item import make_packing_list
Expand Down Expand Up @@ -169,6 +175,7 @@ def validate(self):

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"
Expand Down Expand Up @@ -1445,6 +1452,19 @@ def validate_currency(self):
# 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

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:
Expand Down

0 comments on commit 228f10b

Please sign in to comment.