[FIX] l10n_es_edi_sii: fix post-install, remove auto-install

This commit fixes 2 problems that currently crash database
installations for Spanish companies:

1. Since 8e6a3d7269, the post-init hook
installing tax data uses `_load_data()` and crashes when the taxes to be
updated are not installed. The taxes have not been created yet, to it
tries to create them with only partial info, and missing required
fields:

```
Database initialization failed: null value in column "name" of relation "account_tax" violates not-null constraint DETAIL: Failing row contains (3, 1, 1, 1, null, 233, 1, 1, sale, consu, percent, on_invoice, null, null, null, 0.0000, t, f, f, t, null, 2023-08-14 14:15:43.048823, 2023-08-14 14:15:43.048823, 01, null, sujeto, f).
```

The post-init hook should be more robust and at least not attempt to
load the taxes when no chart is loaded for the company.

2. In #130836 the `l10n_es_edi_sii` module was made auto-installed on
`l10n_es`, but the goal of that PR was only to remove the auto-installation
of `account_edi`.
That seems an unforeseen and undesired change of behavior, so this PR is
partially reverted, to reduce other side-effects of this
auto-installation of `l10n_es_edi_sii`.

opw-3461739
opw-3463573
and more...

closes odoo/odoo#131974

X-original-commit: c031d1bf3dba9afbc86f5a8a2867d5624a40c683
Signed-off-by: Olivier Dony (odo) <odo@odoo.com>
This commit is contained in:
Olivier Dony
2023-08-17 20:49:01 +02:00
parent 594bf0c200
commit 5485187504
2 changed files with 4 additions and 1 deletions
+4
View File
@@ -5,6 +5,10 @@ from . import models
def _l10n_es_edi_post_init(env):
for company in env['res.company'].search([('partner_id.country_id.code', '=', 'ES')]):
if not (company.chart_template and company.chart_template.startswith('es_')):
# only attempt to update tax definitions for companies where a spanish CoA
# is already installed
continue
ChartTemplate = env['account.chart.template'].with_company(company)
taxes_data = ChartTemplate._get_es_edi_sii_account_tax()
ChartTemplate._load_data({'account.tax': taxes_data})
-1
View File
@@ -44,7 +44,6 @@
'external_dependencies': {
'python': ['pyOpenSSL'],
},
'auto_install': ['l10n_es'],
'post_init_hook': '_l10n_es_edi_post_init',
'license': 'LGPL-3',
}