Payroll Entry - Sometimes uses the wrong exchange rate due to a race condition on ajax call #2169
Open
1 task done
Labels
bug
Something isn't working
Information about bug
You have multiple companies with different currencies, and you load the payroll entry page : very intermittently, due to a race condition (described below) it will select an incorrect exchange rate.
When you load the page it will load with the last company you ran payroll for. In our case, we have companies with currency of 'NZD" (lets call it 'NZD Company' and another with currency 'PHP' (lets call it 'PHP Company') for which we are running the payroll entry.
When you load the page, it will load the last company used eg 'PHP Company', but the currency will initially default to 'NZD'. This will then note that the currency ('NZD') is different from the default for that company ('PHP') and load the exchange rate for that currency via an ajax call. It will also fire a javascript hook setup on 'company' that sets the currency to the currency for the company ('PHP').
Depending on the timing of the asynchronous calls happening here, sometimes the ajax call to 'api/method/erpnext.setup.utils.get_exchange_rate' will return after the currency has been updated back to the correct 'php' value, thereby giving you an exchange rate conversion of 'PHP' to 'PHP' but with an exchange rate of 35 (rather than 1). When the payroll entry creates journal entries they will all end out incorrectly being multiplied by 35.
This happens in
hrms/payroll/doctype/payroll_entry/payroll_entry.js
hrms/hrms/payroll/doctype/payroll_entry/payroll_entry.js
Lines 274 to 305 in f64da73
Note that is hard to replicate this, since it is based on flukes of timing, network conditions etc, but one way to force it to happen is to edit https://github.com/frappe/erpnext/blob/5a1a37e915da542d44f1551f1e7b79db4104f1c8/erpnext/setup/utils.py#L50 and add
time.sleep(1)
to make that call take longer to return.One fix would be to check the currencies still differed in the callback of the ajax request and ignore it if they've changed
Module
Payroll
Version
Installation method
manual install
Relevant log output / Stack trace / Full Error Message.
Code of Conduct
The text was updated successfully, but these errors were encountered: