-
-
Notifications
You must be signed in to change notification settings - Fork 247
/
hooks.py
68 lines (61 loc) · 2.22 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (C) 2020 Renato Lima - Akretion <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import SUPERUSER_ID, api, tools
def post_init_hook(cr, registry):
cr.execute("select demo from ir_module_module where name='l10n_br_purchase';")
if cr.fetchone()[0]:
env = api.Environment(cr, SUPERUSER_ID, {})
purchase_orders = env["purchase.order"].search(
[("company_id", "!=", env.ref("base.main_company").id)]
)
for order in purchase_orders:
defaults = order.with_context(company_id=order.company_id.id).default_get(
order._fields
)
defaults.update(
{
"name": order.name,
"company_id": order.company_id.id,
"fiscal_operation_id": order.fiscal_operation_id.id,
}
)
order.write(defaults)
# Load COA Fiscal Operation properties
company = env.ref(
"l10n_br_base.empresa_simples_nacional", raise_if_not_found=False
)
# COA Simple Fiscal Operation properties
if company and env["ir.module.module"].search_count(
[
("name", "=", "l10n_br_coa_simple"),
("state", "=", "installed"),
]
):
tools.convert_file(
cr,
"l10n_br_purchase",
"demo/fiscal_operation_simple.xml",
None,
mode="init",
noupdate=True,
kind="init",
)
company_lc = env.ref(
"l10n_br_base.empresa_lucro_presumido", raise_if_not_found=False
)
# COA Generic Fiscal Operation properties
if company_lc and env["ir.module.module"].search_count(
[
("name", "=", "l10n_br_coa_generic"),
("state", "=", "installed"),
]
):
tools.convert_file(
cr,
"l10n_br_purchase",
"demo/fiscal_operation_generic.xml",
None,
mode="init",
noupdate=True,
kind="init",
)