Fault: Undetected access error on Sales report by region

Context: I sell in Romania using company currency RON, and in Europe in EUR.
Using trytond / trytond_sale / tryton all 7.4.1 updated with pip.

While attempting to use Sale Reports under Sales / Reporting and then Sales by Region:
While browsing the regions I see exaggerated sales figures in EUR, and it appears to be a factor of the exchange rate.
It seems to me that the sales sum reported is in local currency, but with the sale currency symbol (EUR).

When I double click on the region I can see a tree of countries/regions where sales happened.
When I double click on the region where the company is, I get the following traceback:

Traceback (most recent call last):
  File "/trytond/wsgi.py", line 96, in dispatch_request
    return endpoint(request, **request.view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/trytond/protocols/dispatcher.py", line 44, in rpc
    return methods.get(request.rpc_method, _dispatch)(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/trytond/wsgi.py", line 76, in wrapper
    return func(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/trytond/protocols/wrappers.py", line 206, in wrapper
    result = func(request, pool, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/trytond/protocols/dispatcher.py", line 216, in _dispatch
    result = rpc.result(meth(*c_args, **c_kwargs))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/trytond/model/modelsql.py", line 1161, in read
    raise RuntimeError("Undetected access error")
RuntimeError: Undetected access error

Fault: Undetected access error

I have not been able to reproduce on demo, or on a fresh database.
This is the reason I have not filed a bug report.

I have read this: Undetected access error

Possible issues with my database: I have deactivated sale opportunity. Otherwise I don’t have custom sales modules.

Hi, do you have the error in a former version, also?
I tested in 6.0 and can not reproduce.
Do you also have the error when you remove the region == subdivision from your company?

I have not tested in 6.0, it was a long time ago.
I think the issue was also in 7.0, sales reports did not work as they should but I did not investigate further then.

For example I changed Company address to USA.
Now I can see the sale report for Eastern Europe (former company country), but I still get the crash when I try to see the report for North America.

I see a strange thing that I need to investigate.
When I moved company address to USA, I also see some sales in USA (?!).
Edit: These are the deliveries with pick-up from ware-house. So it is normal to have sales in company country if you allow shipment_address == company address.

Sale with delivery to company warehouse on demo does not cause this crash.

Got same problem with purchase report by suppliers

ERROR:tryton.gui.window.view_form.view.list_gtk.widget:Error calling get_textual_value for <tryton.gui.window.view_form.view.list_gtk.widget.M2O object at 0x7fcd4eb9ab10> with <Record 1298@purchase.reporting.supplier at 140519459643200>
Traceback (most recent call last):
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py", line 64, in wrapper
return func(self, record)
^^^^^^^^^^^^^^^^^^
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/gui/window/view_form/view/list_gtk/widget.py", line 360, in get_textual_value
record.load(self.attrs['name'], process_exception=False)
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/gui/window/view_form/model/record.py", line 173, in load
values = RPCExecute('model', self.model_name, 'read',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/common/common.py", line 1337, in RPCExecute
return RPCProgress('execute', args).run(process<em>exception, callback)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/common/common.py", line 1287, in run
return self.process()
^^^^^^^^^^^^^^
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/common/common.py", line 1327, in process
return return</em>()
^^^^^^^^^
File "/home/tbruyere/workspace/tryton/7.2/tryton/tryton/common/common.py", line 1319, in return_
raise RPCException(self.exception)
tryton.common.common.RPCException: Undetected access error

It would be nice if we can reproduce it on a new database, or on demo database…

Is this one of your production databases?
Does this happen on a new database?
Do you have some ideas what might be the issue?

Initially I was thinking the issue might be the different currency of some sales and the company currency.
Do you have supplier/purchases in other currency than company currency?

Do you use warehouse pick up?

Cannot reproduce on new database. Problem on our production database. (7.0 and 7.2)

This is a bug on the table query generating the report. Could you please fill an issue?

As you are double clicking in the record this is when you open the sale.reporting.country.tree which is an unnion of the country.country and country.subdivision models.

Normally this issues depend on the ids of the database, so it will be great to know the maxiumum ids of such tables. If you loaded using a script, it should be possible to reproduce the values on a fresh database as far as they have the same ids generated.
Note that if you deleted and re-imported the records, the ids will increase and they will be different from the ones created in a fresh database.

In my case, the problem seems linked when using different currencies for the same supplier. So id, which is party.id, is not unique.

In such case, the amounts should be converted to same currency and a single record for the party should be shown.

Please fill an issue as this is a differnt error, despite the error message beeing the same.

Which date should be used to convert currency ? Purchase date ? Delivery Date ?