Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange Rate Revaluation throws error for account Stock In Hand #45201

Open
nikkothari22 opened this issue Jan 9, 2025 · 1 comment
Open
Labels

Comments

@nikkothari22
Copy link
Contributor

Information about bug

I am trying to post an Exchange Rate Revaluation entry since there's a difference between the amounts in company currency and the account currency.

image

When I am trying to create a Journal Entry, it throws an error: "Account: Stock In Hand - ATPL can only be updated via Stock Transactions"

image

We don't use any Stock accounts/features in the system, so it's weird that this shows up.

The site is hosted on Frappe Cloud.

Module

accounts

Version

Frappe: v15.51.2
ERPNext: v15.48.1
India Compliance: v15.14.7
Frappe HR: v15.37.2

Installation method

None

Relevant log output / Stack trace / Full Error Message.

{
    "exception": "erpnext.accounts.doctype.journal_entry.journal_entry.StockAccountInvalidTransaction: Account: Stock In Hand - ATPL can only be updated via Stock Transactions",
    "exc_type": "StockAccountInvalidTransaction",
    "_exc_source": "erpnext (app)",
    "exc": "[\"Traceback (most recent call last):\\n  File \\\"apps/frappe/frappe/app.py\\\", line 114, in application\\n    response = frappe.api.handle(request)\\n               ^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/api/__init__.py\\\", line 49, in handle\\n    data = endpoint(**arguments)\\n           ^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/api/v1.py\\\", line 36, in handle_rpc_call\\n    return frappe.handler.handle()\\n           ^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/handler.py\\\", line 50, in handle\\n    data = execute_cmd(cmd)\\n           ^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/handler.py\\\", line 86, in execute_cmd\\n    return frappe.call(method, **frappe.form_dict)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/__init__.py\\\", line 1726, in call\\n    return fn(*args, **newargs)\\n           ^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/handler.py\\\", line 332, in run_doc_method\\n    response = doc.run_method(method)\\n               ^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 974, in run_method\\n    out = Document.hook(fn)(self, *args, **kwargs)\\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 1334, in composer\\n    return composed(self, method, *args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 1316, in runner\\n    add_to_return_value(self, fn(self, *args, **kwargs))\\n                              ^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 971, in fn\\n    return method_object(*args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/utils/typing_validations.py\\\", line 31, in wrapper\\n    return func(*args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/erpnext/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py\\\", line 344, in make_jv_entries\\n    zero_balance_jv = self.make_jv_for_zero_balance()\\n                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/erpnext/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py\\\", line 469, in make_jv_for_zero_balance\\n    journal_entry.save()\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 342, in save\\n    return self._save(*args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 364, in _save\\n    return self.insert()\\n           ^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 295, in insert\\n    self.run_before_save_methods()\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 1103, in run_before_save_methods\\n    self.run_method(\\\"validate\\\")\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 974, in run_method\\n    out = Document.hook(fn)(self, *args, **kwargs)\\n          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 1334, in composer\\n    return composed(self, method, *args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 1316, in runner\\n    add_to_return_value(self, fn(self, *args, **kwargs))\\n                              ^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/frappe/frappe/model/document.py\\\", line 971, in fn\\n    return method_object(*args, **kwargs)\\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\n  File \\\"apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py\\\", line 133, in validate\\n    self.validate_stock_accounts()\\n  File \\\"apps/erpnext/erpnext/accounts/doctype/journal_entry/journal_entry.py\\\", line 274, in validate_stock_accounts\\n    frappe.throw(\\n  File \\\"apps/frappe/frappe/__init__.py\\\", line 603, in throw\\n    msgprint(\\n  File \\\"apps/frappe/frappe/__init__.py\\\", line 568, in msgprint\\n    _raise_exception()\\n  File \\\"apps/frappe/frappe/__init__.py\\\", line 519, in _raise_exception\\n    raise exc\\nerpnext.accounts.doctype.journal_entry.journal_entry.StockAccountInvalidTransaction: Account: Stock In Hand - ATPL can only be updated via Stock Transactions\\n\"]",
    "_server_messages": "[\"{\\\"message\\\": \\\"Account: Stock In Hand - ATPL can only be updated via Stock Transactions\\\", \\\"title\\\": \\\"Message\\\", \\\"indicator\\\": \\\"red\\\", \\\"raise_exception\\\": 1, \\\"__frappe_exc_id\\\": \\\"c24673ab5a18fe289a3e97caf70a658c8ad496d255452a1924ad2495\\\"}\"]"
}
@nikkothari22
Copy link
Contributor Author

nikkothari22 commented Jan 9, 2025

Okay, so on further investigation, I found that the Journal Entry that's being created doesn't have any accounts at all.

JE trying to be created (used a server script to print this as an error):
{"name": "ACC-JV-2025-00010", "owner": "[email protected]", "creation": "2025-01-10 00:08:41.796753", "modified": "2025-01-10 00:08:41.796753", "modified_by": "[email protected]", "docstatus": 0, "idx": 0, "is_system_generated": 0, "title": null, "voucher_type": "Exchange Gain Or Loss", "ineligibility_reason": "As per rules 42 & 43 of CGST Rules", "naming_series": "ACC-JV-.YYYY.-", "finance_book": null, "process_deferred_accounting": null, "reversal_of": null, "tax_withholding_category": null, "from_template": null, "company": "Algocode Technologies Private Limited", "company_gstin": null, "posting_date": "2024-04-01", "apply_tds": 0, "cheque_no": null, "cheque_date": null, "user_remark": null, "total_debit": 0.0, "total_credit": 0.0, "difference": 0.0, "multi_currency": 1, "total_amount_currency": null, "total_amount": 0.0, "total_amount_in_words": null, "clearance_date": null, "remark": null, "paid_loan": null, "inter_company_journal_entry_reference": null, "bill_no": null, "bill_date": null, "due_date": null, "write_off_based_on": "Accounts Receivable", "write_off_amount": 0.0, "pay_to_recd_from": null, "letter_head": "Default Letterhead", "select_print_heading": null, "mode_of_payment": null, "payment_order": null, "is_opening": "No", "stock_entry": null, "auto_repeat": null, "amended_from": null, "doctype": "Journal Entry", "accounts": [], "__islocal": true, "__unsaved": 1}

I looked at the code and it looks like the reason why that is is because in my Exchange Rate Revaluation:

  1. balance_in_account_currency and new_balance_in_account_currency are the same - this is fine.
  2. balance_in_base_currency is different from new_balance_in_base_currency - but none of them are zero - and hence this condition fails.

Am I using the Exchange Rate Revaluation voucher wrong? What I am trying to achieve is that on our system, the account "Debtors-USD" has zero balance in USD, but the Balance Sheet still shows a Debit of Rs. 4347.50 (in INR)

I summed up the "GL Entry" table for this account and found the following:

Sum of Debit Amount in Account Currency (USD): 469500
Sum of Credit Amount in Account Currency (USD): 469500

Sum of Debit Amount in Company Currency: 39177247.5
Sum of Credit Amount in Company Currency: 39172900

Hence the difference in USD is 0 (debits and credits match - which is correct since we do not have any receivable against this account), but in INR it's 4,347.50. I am not sure how we ended up here but this balance was brought over from the previous year's accounts which are now closed :/

Edit: I decided to try creating a Revaluation voucher with the posting date set to today (hence the new_balance_in_base_currency variable would be 0) and it worked. In my earlier example, I was using a posting date in the past where there was a difference but none of the balances were 0. However, should it not also work even if none of the balances are zero?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant