From 548518750490687bf4c8aafed0ec16d54b997cfa Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 14 Aug 2023 17:43:12 +0000 Subject: [PATCH] [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 8e6a3d7269f81191ec8180e6d5ee8d403238f9a2, 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) --- addons/l10n_es_edi_sii/__init__.py | 4 ++++ addons/l10n_es_edi_sii/__manifest__.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/l10n_es_edi_sii/__init__.py b/addons/l10n_es_edi_sii/__init__.py index 557fa3d44c6..e8ea99b9472 100644 --- a/addons/l10n_es_edi_sii/__init__.py +++ b/addons/l10n_es_edi_sii/__init__.py @@ -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}) diff --git a/addons/l10n_es_edi_sii/__manifest__.py b/addons/l10n_es_edi_sii/__manifest__.py index 9958acad175..a101146bbe0 100644 --- a/addons/l10n_es_edi_sii/__manifest__.py +++ b/addons/l10n_es_edi_sii/__manifest__.py @@ -44,7 +44,6 @@ 'external_dependencies': { 'python': ['pyOpenSSL'], }, - 'auto_install': ['l10n_es'], 'post_init_hook': '_l10n_es_edi_post_init', 'license': 'LGPL-3', }