frappe / books

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

bug: incorrect rounding of JPY amounts #770

Open mark-omarov opened 8 months ago

mark-omarov commented 8 months ago

Description

While working with JPY, I encountered an issue related to incorrect rounding of amounts. I've traced the problem, which appears to be related to how the system handles precision.

Expected behavior: 123.99 should be rounded down to 123 Current behavior: 123.99 rounded up to 124

JPY typically has no decimals, the minimal denominator is 1, and amounts with decimals are typically rounded down to the nearest whole yen.

Setting Display Precision does help hide decimals but does not resolve the incorrect amount.

It might have something to do with countryInfo.json and internalPrecision fields on the SystemSettings schema. I haven't figured out how to fix it yet. Changing currency_fraction and currency_fraction_units in the countryInfo.json doesn't seem to do anything, even after creating a new Organization to instantiate a new DB. Tinkering with internalPrecision didn't help it either.

Steps to Reproduce

Info

Version: 0.19.0 Platform: darwin Path: /edit/SalesInvoice/New Sales Invoice 01 Language: - Country: jp

mildred commented 6 months ago

The money library under the hood is : https://github.com/frappe/pesa

mildred commented 6 months ago

internalPrecision maps to pesa precision parameter, and displayPrecision maps to display in https://github.com/frappe/pesa#options-and-value

mildred commented 6 months ago

I would believe that setting internalPrecision to 0 should work

mildred commented 6 months ago

What if you open your book file with sqlite and try to update the settings like this

update SingleValue set value = 0 where (parent, fieldname) = ('SystemSettings', 'displayPrecision');
update SingleValue set value = 0 where (parent, fieldname) = ('SystemSettings', 'internalPrecision');

then reopen it in Books?

Always work on backup copies.

mildred commented 6 months ago

Apparently for tax calculation, the calculation is performed over integers with no decimals: https://docs.oracle.com/en/applications/jd-edwards/localizations/9.2/eoajp/what-you-should-know-about-tax-rounding-in-japan.html#u30184160

mark-omarov commented 6 months ago

I since moved on and no longer have the app nor records. Maybe updating values in the DB would help, but I'd imagine this isn't something most users would do themselves.