Open fractalf opened 10 months ago
I'd like to bump this in hope that someone with greater knowledge can look at this. It's still a bug now 6 months later (tried today with latest from nightly)
It's really easy to reproduce. Just boot up a docker container with the latest Odoo17 from nightly (or any v17 I guess) and add the two files provided here above, install the module and bam, errors..
I want to add another debug point
l10n_no
and then this module => worksIf I manually install the l10n_no
module from Apps and then when done manually install the debug/test module provided here it works.
So the problem seems to be how Odoo handles dependencies
Hello @fractalf,
The accounts of a Chart of Accounts are instantiated once per company, from a template.
When the chart of accounts is installed, account.chart.template:_load
gets called, which calls _get_chart_template_data
. This second method gets models and to-be-called methods from self._template_register
, which is filled up by methods decorated with @template
such as _get_account_account
.
In the end, account.chart.template:_parse_csv
is called to actually load the files inside the {module}/data/template
folder.
This means that the record which you are trying to reference is not loaded at the module installation time, but at the time when the Chart of Accounts Template is instantiated for a company.
Furthermore, as a Chart of Account may be instantiated once for each company of a database, the XML ids are prefixed with the id of the company (hence the 1_
as if you only have one company it will have the id 1
).
About your need to reference an account from the chart of accounts directly from your module, I guess that the best way would be to provide your own template files and have them loaded along with the Chart of Accounts, but I am not sure neither how to do this, nor if this would also work if you first install the l10n_no
module, instantiate the CoA and then install your custom module. Maybe someone else with more knowledge about l10n modules than me could provide more information about this.
Error message
ValueError: External ID not found in the system: account.1_chart1918
(full exception at the end of the issue)
Version
Running version 17 in a docker container using the deb here: https://download.odoo.com/17.0/nightly/deb/odoo_17.0.20231116_all.deb
Setup (for reproduction)
__manifest__.py
my_test.xml
i10n_no
This is a short snippet from the record I'm trying to link up
addons/l10n_no/data/template/account.account-no.csv
Description
Ok, this is quite weird..
1 - Described setup => fails
Running the setup described above results in failure
ValueError: External ID not found in the system: account.1_chart1918
2 - Try doing it in two steps (debug) => works
Comment out the custom record like this
..then install the module, and check the database
...it's there.
Remove the comment to prepare the custom data record install
..then upgrade the module.
And it works!
Conclusion
Something is wrong here, step 1 above should work in one go, right?
Comment
I should mention that I think it's very strange that I should use the ref
1_chart1918
and not justchart1918
(without the1_
part which I don't know where comes from, but that's what's in the database..)Ofc I tried with with just ref to
chart1918
as well, but that failed alsoFull exception error stack