Stock account used as expense account in purchase invoice

I have an issue with my stock account being out of balance.
Looks like some non stock items on purchase invoices have had our stock account applied as their expense account.
When trying to fix this with a journal entry I receive the following error message:

Account: 12000 - Inventory - EWI can only be updated via Stock Transactions

I am wondering why there is no similar error when attempting to use the stock account in a purchase invoice. It seems there should be a validation that the account is only an expense account. Am I missing something?

Hi.
Beside the validation problem that you saw and just trying to identify the difference you can check this report.
https://docs.erpnext.com/docs/v13/user/manual/en/stock/stock-value-account-value-comparison
Maybe you already did it but another thing that you can do to solve the mistake, it´s make a credit note against the original invoice (if you can´t cancel it) and later make a new one or correct the canceled.
I hope it can helps.
Regards

Thank you. I’ll look into those suggestions. I hadn’t seen that stock report before.
Mostly I’m interested to know if there’s a reason that the code doesn’t validate that it’s an expense account. I’m going to add a validation into my custom app. But wondering if this is a bug that I should report.

Thanks!

I am not developer so i can´t say anything about the code.
At user level I have dealt with multiple issues but never saw a menssage like this.
From my experience I definitely recommend you first identify the origen of the problem before make any code changes.
I intuit you´ll find it looking for into the configurations, item master, user actions, negative stock allowed or postdated records for instance.
Once you find it if you still need help post the case information for a closer look.
Regards