Dolibarr / dolibarr

Dolibarr ERP CRM is a modern software package to manage your company or foundation's activity (contacts, suppliers, invoices, orders, stocks, agenda, accounting, ...). it's an open source Web application (written in PHP) designed for businesses of any sizes, foundations and freelancers.
https://www.dolibarr.org
GNU General Public License v3.0
5.2k stars 2.72k forks source link

Bug - Foreign currency vendor invoice paid in foreign currency may remain open even when settled in foreign currency #25898

Open Ashley-Butcher opened 11 months ago

Ashley-Butcher commented 11 months ago

Bug

When creating a vendor invoice in a foreign currency, and settling that invoice in that foreign currency, the invoice may remain "unpaid" even then the amount in foreign currency is settled in the foreign currency (currency of the document).

This occurs because Dolibarr only evaluates the value of the document in the company currency, and not the document currency. For example, the invoice may be fully paid (so remainder in foreign currency is 0.00), but the invoice may remain open for 0.01 in company currency.

In most ERP systems, this the foreign currency is referred to as "document currency" and it's this document currency that should be evaluated when determining if the document is settled (paid) or not.

Environment Version

18.0.1 (also older versions)

Environment OS

Debian 12.1

Environment Web server

Apache 2.4.57

Environment PHP

7.4.33

Environment Database

MySQL 8.0.33

Environment URL(s)

No response

Expected and actual behavior

Actual: Dolibarr tests for settlement of the invoice (i.e. if the invoice has been paid) based on the company currency values. If a document is in foreign currency, it relies on currency conversion, which may be inadequate for this role.

Expected: Dolibarr should test for settlement (payment completion) on document currency values (the currency of the invoice) instead of the company currency.

Steps to reproduce the behavior

Example 1:

Company currency = EUR Document currency = SEK

Prerequisites:

Example 2:

Company currency = GBP Document currency = EUR

Attached files

No response

Ashley-Butcher commented 11 months ago

This is a part of a larger problem Dolibarr has in multicurrency environments, but given the high number of open issues on github I'm only posting some issues here and won't get into the larger issues yet.

Ashley-Butcher commented 11 months ago

Another example. Dolibarr makes the mistake of working in company currency instead of document currency, resulting in these errors. ERP systems normally work in the currency of the document to avoid these errors, because this is the true value of the document (the value in company currency is the realised value).

image

When settling the total amount in document currency (in this case, SEK), the document cannot even be closed because of an apparent rounding error in company (system) currency (EUR):

image

The document should be settled and the open amount should be nil. This is a ridiculous situation easily overcome by always working in document currency.

Ashley-Butcher commented 11 months ago

Another example from a user, settled entirely in SEK, but this time it can be marked as closed, further highlighting the rounding discrepancies created by not working entirely in document currency.

image

leninrivas commented 1 month ago

It seems to be an accuracy issue. If increase total MAIN_MAX_DECIMALS_TOT from 2 to 3?

Ashley-Butcher commented 1 month ago

@leninrivas No the problem is related to how Dolibarr uses document currency in general. As with any ERP system (SAP, Dynamics AX, JD Edwards, Sage, ...) a document (invoice/sales order/etc.) needs to be treated in its actual currency and not the company currency. Dolibarr only ever considers the system currency - this is wrong.

When dealing with a document in a currency other than the company's currency, it's normal for there to be rounding errors, especially when dealing with currencies with wide rate difference ratios (such as SEK to EUR). Dolibarr should first consider the document in the document's currency (i.e. SEK) and see if the balance in that currency is zero when considering if the document is closed (settled). Then, the amount in the company currency (i.e. EUR) can be checked - if there is a cent or two, it can offset into a ledger account as a penny difference on currency exchange (or ignored, in the case of accounting being switched off).

Normally the rounding rules are followed based on the rules of the currency with a few exceptions (pricing, for example). This is how you can settle a document in its original currency but it's also acceptable to have penny differences in the company currency. This happens all the time, and it isn't an accuracy issue, but instead Dolibarr is simply looking at the wrong amounts.

Dolibarr should instead be only treating the documents in their source currency, and the value of the document in the company currency should be facultative.

These rules are very standard in business, and I would assume that it's a legacy issue from the days before Dolibarr supported multicurrency.

This of course leads me to further problems with Dolibarr's multicurrency implementation, such exchange rate adjustments on documents, and a future need for unrealised exchange adjustments (on open documents, i.e. at the end of the month, for valuation and reporting purposes) and realised adjustments (at settlement, for example), but this is a whole other issue.

Unfortunately I don't have the free time to spend on developing a fix for Dolibarr :(