forked from OCA/l10n-spain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
37 lines (35 loc) · 1.49 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2021 Digital5, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
fiscal_positions = env["account.fiscal.position"].search([])
for position in fiscal_positions:
if not position.company_id.chart_template_id:
continue
fiscal_position_template = env["account.fiscal.position.template"].search(
[
(
"chart_template_id",
"=",
env.ref("l10n_es.account_chart_template_common").id,
),
("name", "=", position.name),
]
)
if 1 == len(fiscal_position_template):
vals = {}
if fiscal_position_template.tbai_vat_regime_purchase_key:
vals[
"tbai_vat_regime_purchase_key"
] = fiscal_position_template.tbai_vat_regime_purchase_key.id
if fiscal_position_template.tbai_vat_regime_purchase_key2:
vals[
"tbai_vat_regime_purchase_key2"
] = fiscal_position_template.tbai_vat_regime_purchase_key2.id
if fiscal_position_template.tbai_vat_regime_purchase_key3:
vals[
"tbai_vat_regime_purchase_key3"
] = fiscal_position_template.tbai_vat_regime_purchase_key3.id
if vals:
position.write(vals)