Debian Codegraph @

addons/l10n_dk_nemhandel/__init__.py

raw
1 from odoo.tools.sql import column_exists, create_column
2
3 from . import models
4 from . import tools
5 from . import wizard
6
7
8 def _pre_init_nemhandel(env):
9 """
10 Force the creation of the columns to avoid having the ORM compute on potentially millions of records.
11 Mimic the compute method of nemhandel_identifier_type and nemhandel_identifier_value to fill these columns.
12 """
13 if not column_exists(env.cr, "account_move", "nemhandel_move_state"):
14 create_column(env.cr, "account_move", "nemhandel_move_state", "varchar")
15 create_column(env.cr, "res_partner", "nemhandel_identifier_type", "varchar")
16 create_column(env.cr, "res_partner", "nemhandel_identifier_value", "varchar")
17
18 query = """
19 WITH _dk AS (
20 SELECT p.id
21 FROM res_partner p
22 LEFT JOIN res_country c
23 ON c.id = p.country_id
24 WHERE p.vat ILIKE 'DK%'
25 OR c.code = 'DK'
26 )
27 UPDATE res_partner p
28 SET nemhandel_identifier_type = '0184',
29 nemhandel_identifier_value = p.company_registry
30 FROM _dk
31 WHERE _dk.id = p.id
32 """
33 env.cr.execute(query)
34
35
36 def uninstall_hook(env):
37 env["res.partner"]._clear_removed_edi_formats("oioubl_21")