Skip to content

Commit dcc872c

Browse files
committed
[FIX] l10n_hu_edi: Cleanup post-init code
This commit comes as an apology for the horrible code I wrote in PR odoo#166043 in order for the installation of `l10n_hu_edi` to not fail if some of the default Hungarian taxes (defined in `l10n_hu`) had been deleted. Instead of rolling back the loading of the EDI-specific fields if some taxes don't exist, we can just load those fields on the taxes that do exist. Which is a lot cleaner and simpler. Sorry again! task-none closes odoo#196471 Signed-off-by: Ricardo Gomes Rodrigues (rigr) <rigr@odoo.com>
1 parent d6e3671 commit dcc872c

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

addons/l10n_hu_edi/__init__.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,19 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

3-
import logging
4-
import psycopg2.errors
5-
6-
from odoo import _
7-
83
from . import models
94
from . import wizard
105

11-
_logger = logging.getLogger(__name__)
12-
136

147
def post_init(env):
158
for company in env['res.company'].search([('chart_template', '=', 'hu')], order="parent_path"):
169
# Apply default cash rounding configuration
1710
company._l10n_hu_edi_configure_company()
1811

1912
# Set Hungarian fields on taxes
20-
sql_logger = logging.getLogger('odoo.sql_db')
21-
previous_level = sql_logger.level
22-
sql_logger.setLevel(logging.CRITICAL)
23-
try:
24-
with env.cr.savepoint():
25-
env['account.chart.template'].with_company(company)._load_data({
26-
'account.tax': env['account.chart.template']._get_hu_account_tax()
27-
})
28-
except psycopg2.errors.NotNullViolation:
29-
_logger.warning(_(
30-
'Could not set NAV tax types on taxes because some taxes from l10n_hu are missing.\n'
31-
'You should set the type manually or reload the CoA before sending invoices to NAV.'
32-
))
33-
finally:
34-
sql_logger.setLevel(previous_level)
13+
env['account.chart.template'].with_company(company)._load_data({
14+
'account.tax': {
15+
xmlid: vals
16+
for xmlid, vals in env['account.chart.template']._get_hu_account_tax().items()
17+
if env['account.chart.template'].with_company(company).ref(xmlid, raise_if_not_found=False)
18+
}
19+
})

0 commit comments

Comments
 (0)