Friday, February 17, 2023
3 changes · master
Code cleanup and technical improvements
This change removes unused internal code from Odoo's core field handling. It should not change how users work with Odoo, but it reduces unnecessary complexity in a heavily used area and may slightly improve maintainability and efficiency.
Original PR description
[REM] core: simplify `_update` of `_RelationalMulti` The `_update` of `_RelationalMulti` return a bool but the others `_update` methods doesn't return anything. It is actually not used. Also, the…
[REM] core: simplify `_update` of `_RelationalMulti` The `_update` of `_RelationalMulti` return a bool but the others `_update` methods doesn't return anything. It is actually not used. Also, the `_update` is always called with a recordset as `value`, then the first part of the method is useless. [REM] core: remove useless assert and set creation `write_batch` made an useless assertion (mathematically always true) and create a set for it, it is not free and this method is heavily used. Remove the assert, avoid creating the set and use the `all` method directly. [REM] base: remove useless `_remove_inverses` of `Many2oneReference` The `_remove_inverses` method of `Many2oneReference` class has been unused since its introduction. Remove it. [REM] core: remove small deadcode from `Selection` field `convert_to_cache` of the `Selection` field type, check that the column_type is 'int4'. But nowadays (since a0e05e2ab9055fa060b1f3b5adf7aa322e2617fd), a `Selection` field can only be a Varchar type. [REM] core: remove unused `null` method on `Field` class This method was unused since 8bc7d8565c3e4f954c479e3b51b863e4c03dc582.
This change rewrites how accounting chart templates are stored and installed, moving away from database-stored templates toward code and CSV files. It significantly speeds up first-time localization setup, reduces maintenance effort, and makes legally required accounting updates easier to deliver.
Original PR description
Rewrite the whole chart template mechanism, removing the templates stored in the database. The new format will mainly use CSV. Speed up install time --------------------- * About half of the time of…
Rewrite the whole chart template mechanism, removing the templates
stored in the database. The new format will mainly use CSV.
Speed up install time
---------------------
* About half of the time of installing a localization for the first time is
taken by creating the template records. This new in code format gets
completely rid of this.
* Creating the template records could often not be done in batch because
of parent/children relations.
* The instanciation of the accounts on the company has been entirely
reworked too, by
- optimizing the order of creation of records to avoid UPDATE queries
- using precomputed fields to avoid UPDATE queries
- updating the translation in batch
- deactivating logging in the chatter
- avoiding access rights checks by checking the rights at the start
Overall, when installing a chart template for the first time, it is 4
times faster because half of the time spent on saving the template in
the database is not done at all anymore, and the instanciation on the
company is more than twice as fast.
Reduce technical debt
---------------------
There is no need to synchronize the templates with the real records
anymore. No need to use hooks to copy the data from one to the other.
It is easier to change a template in a stable version, which can often
be necessary due to legal reasons (i.e. a change of tax rates, reporting
tags,...)
Two modules have been removed:
* `l10n_generic_coa`: since there is nothing left datawise in this
module, it can be integrated in `account` for free. It is just code
and CSV.
* `l10n_multilang`: the fields that this module modified to be
translatable are now always translatable:
- there was an issue when updating modules that deleted all the
translations because the fields were not translatable at some point
during the loading of the registry, then they because translatable
again but lost all translations because of the column type change.
- most devs are not able to understand all the languages needed for
all the localization available. Therefore, english has been added in
the sources in most localization to understand better issues while
debugging.
- no need to call post init hooks anymore, doing the sync with the
templates.
- more: see "Translations" section
Because most of the data is now in CSV, it is also easier for product
owners to edit, audit, modify files themselves, removing one layer
during trivial development processes when only data should be changed.
More flexibility for declaration
--------------------------------
The data declaration can now be done easily in python or CSV.
A nice feature is that you can declare everything at once, even for some
more complex chart of accounts:
* if you have to set default taxes on accounts, would need to
- declare the accounts because accounts are required on the taxes
- declare the taxes
- declare the taxes to put on the accounts
This would lead to scatter information in multiple files. Now,
everything can be declared in the same place and the loading of the
chart of accounts will do the 3 steps automatically.
* if you have a relation of child/parent, you would first need to
declare the parents then the children, and the loading would not be
efficient because done one by one. Now, everything is done in batch
automatically without having to think about it.
It is also easier to update fields on records where there was no field
for that on the templates, like
* setting a restriction for journals on accounts
* setting specific values on the company
* modifying journals and linking them easily by using the xml_id instead
of having to compute it manually
Translations
------------
Some countries have multiple languages (i.e. Belgium uses officially
French, Dutch and German, and the CoA also has an official English
version) and we must support the languages in all these countries.
All these translations are known, and hard coded without using out
translation platform (Transifex). We also like to have the English
version (even if an official one doesn't exist) so that support can be
done more easily in databases using chart templates in other languages
(especially using a non roman alphabet).
Because the translations were not on Transifex for these records, it was
really hard to maintain: the translation templates (`.pot` files) were
not easy to extract as the automatic export would give values mixing
both the CoA and the menuitmes, the fields' strings,... But we don't
want to translate the CoA as we already know the value.
Managing the translations in the `.po` files was also annoying:
- it is easy to forget that the translations need an update too
- it requires a special editor, special terminal commands that everyone
is not familiar with
- it is easy to make mistakes in the source string
The new format is the following: `field@en_US` where `field` is the
translatable field (usually `name`) and `en_US` is the locale code.
This allows to have the whole declaration on one line, everything in one
file. It also makes the process easier when debugging: instead of
searching for the translation in the `.po` files, it directly appears
next to the configuration of the account/tax/... .
Update of the code
------------------
The code can be updated using this script
https://github.com/william-andre/transform_coa
Forward ports can be managed too by stashing/resetting/checkout the new
modules or the changes in the modules updated in the same PR.
[task-2687567](https://www.odoo.com/web#id=2687567&model=project.task)This update removes older chart template structures and shifts related accounting reports and localization logic to the newer setup approach. It helps keep accounting configuration more consistent and easier to maintain, with little expected day-to-day impact for business users.