frappe / erpnext

Free and Open Source Enterprise Resource Planning (ERP)
https://erpnext.com
GNU General Public License v3.0
20.38k stars 7.08k forks source link

Bank Reconciliation Tool missing foreign currency validation for customer #37498

Open jalajc opened 11 months ago

jalajc commented 11 months ago

Information about bug

Inside Bank reconciliation tool, create new voucher for payment entry in local currency where mapped to party_type customer successfully, but when wanted to cancel to payment entry (for the reason, the entries should have been made in GBP), cancellation results in Customer % has accounting entries in currency GBP for company %. Please select a receivable or payable account with currency GBP. Ideally, in first place itself this validation shouldn't have allowed the payment entry creation in local currency from the Bank reconciliation tool.

Module

accounts

Version

ERPNext: v14.44.0 (version-14)

Frappe Framework: v14.52.0 (version-14)

Frappe HR: v14.13.1 (version-14)

India Compliance: v14.17.1 (version-14)

Installation method

None

Relevant log output / Stack trace / Full Error Message.

desk.bundle.KLNNNWG5.js:446 Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 95, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 54, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 47, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1622, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 47, in cancel
    doc.cancel()
  File "apps/frappe/frappe/model/document.py", line 1013, in cancel
    return self._cancel()
  File "apps/frappe/frappe/model/document.py", line 993, in _cancel
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 307, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 358, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1095, in run_post_save_methods
    self.run_method("on_cancel")
  File "apps/frappe/frappe/model/document.py", line 917, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1279, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1261, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 914, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/accounts/doctype/payment_entry/payment_entry.py", line 114, in on_cancel
    self.make_gl_entries(cancel=1)
  File "apps/erpnext/erpnext/accounts/doctype/payment_entry/payment_entry.py", line 1014, in make_gl_entries
    make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)
  File "apps/erpnext/erpnext/accounts/general_ledger.py", line 52, in make_gl_entries
    make_reverse_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)
  File "apps/erpnext/erpnext/accounts/general_ledger.py", line 606, in make_reverse_gl_entries
    make_entry(new_gle, adv_adj, "Yes")
  File "apps/erpnext/erpnext/accounts/general_ledger.py", line 375, in make_entry
    gle.submit()
  File "apps/frappe/frappe/model/document.py", line 1008, in submit
    return self._submit()
  File "apps/frappe/frappe/model/document.py", line 987, in _submit
    return self.save()
  File "apps/frappe/frappe/model/document.py", line 307, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 329, in _save
    return self.insert()
  File "apps/frappe/frappe/model/document.py", line 261, in insert
    self.run_before_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1056, in run_before_save_methods
    self.run_method("validate")
  File "apps/frappe/frappe/model/document.py", line 917, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1279, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1261, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 914, in fn
    return method_object(*args, **kwargs)
  File "apps/erpnext/erpnext/accounts/doctype/gl_entry/gl_entry.py", line 50, in validate
    self.validate_currency()
  File "apps/erpnext/erpnext/accounts/doctype/gl_entry/gl_entry.py", line 285, in validate_currency
    validate_party_gle_currency(self.party_type, self.party, self.company, self.account_currency)
  File "apps/erpnext/erpnext/accounts/party.py", line 470, in validate_party_gle_currency
    frappe.throw(
  File "apps/frappe/frappe/__init__.py", line 534, in throw
    msgprint(
  File "apps/frappe/frappe/__init__.py", line 502, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 451, in _raise_exception
    raise raise_exception(msg)
erpnext.exceptions.InvalidAccountCurrency: <strong>Customer</strong> <strong>CYBER</strong> has accounting entries in currency <strong>GBP</strong> for company <strong>FY22</strong>. Please select a receivable or payable account with currency <strong>GBP</strong>.

(anonymous) @ desk.bundle.KLNNNWG5.js:446
jalajc commented 11 months ago

I have not dwelled deep, but the related code lines at https://github.com/frappe/erpnext/blob/5167fb2baee742d152691c3e9c996a07d94240ea/erpnext/accounts/party.py#L466 seems of flawed with limit=1, , in absence of any 'order by', no consideration for is_cancelled field, no consider for against field.