frappe / books

Free Accounting Software
https://frappe.io/books
GNU Affero General Public License v3.0
2.68k stars 614 forks source link

Stock Ledger/Stock Balance Failing to Load #842

Open JustinFowlerArt opened 4 months ago

JustinFowlerArt commented 4 months ago

Can't load stock ledger or stock balance

I recently completed a large (60 hr+) migration from another accounting and inventory software (Craftybase). I have quite a bit of feedback on the migration process and importing that I will provide separately. However, I am currently having an error with the final dataset that is preventing me from validating the accuracy of the inventory since the Stock Ledger and Stock Balance views are not able to load.

I believe that there is a data issue causing the error since it was only erroring when certain days were included in the range with a partial dataset imported (due to batching the imports to improve import speed). However, now that the entire dataset is imported, it is erroring on initial load of those views. I had numerous stock movements or shipments fail while importing, rolled back to a previous db backup, corrected internal data or made edits to the csv files before running the import again. All records wrote successfully on the final attempts.

I am a software developer and interested in contributing to this project, but am not yet familiar with the code base or Electron and curious of any things to check for in the data that might be triggering this error.

Thanks for any help.

Info

Note: This error also occurred in 0.20.1.

Error: Error: invalid input 'Infinity' of type 'string' value: 'Infinity', type: number

Stack:

Error: invalid input 'Infinity' of type 'string' value: 'Infinity', type: number
    at XX (app://assets/index-9daa0156.js:11:34056)
    at ZX (app://assets/index-9daa0156.js:11:33635)
    at kf._f (app://assets/index-9daa0156.js:11:38357)
    at set value [as value] (app://assets/index-9daa0156.js:11:36453)
    at new kf (app://assets/index-9daa0156.js:11:35380)
    at new Dv (app://assets/index-9daa0156.js:11:39496)
    at qX (app://assets/index-9daa0156.js:11:44205)
    at vK.pesa (app://assets/index-9daa0156.js:11:44263)
    at gK (app://assets/index-9daa0156.js:40:5806)
    at mK (app://assets/index-9daa0156.js:40:5610)

Version: 0.21.1 Platform: win32 Path: /report/StockBalance Language: - Country: us

JustinFowlerArt commented 4 months ago

I was able to get going with Electron (much easier than I expected) and found that the issue lies with valuation rates going below 0. I liquidated some of my inventory at the end of 2023, and due to JavaScript being bad with trailing decimals the valuation rates dipped below 0, resulting in my -Infinity. Here is one example prior to the final stock movement that put it negative:

valuationRate: 11.997499999999993 valueChange: -11.997500000000002

Here is the call stack: image

JustinFowlerArt commented 4 months ago

This fix worked for me:

stockQueue.ts line 20

if (Number.isNaN(valuation) || !Number.isFinite(valuation)) {
    return 0;
}