forked from OCA/l10n-brazil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
151 lines (138 loc) · 5.91 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# 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_stock_account';")
if cr.fetchone()[0]:
env = api.Environment(cr, SUPERUSER_ID, {})
# Load COA Fiscal Operation properties
company = env.ref(
"l10n_br_base.empresa_simples_nacional", raise_if_not_found=False
)
# Caso o modulo l10n_br_purcase ou l10n_br_sale esteja instalado,
# o que acontece na forma que o Travis faz os testes, acontece o
# erro abaixo:
# File "/odoo/src/odoo/sql_db.py", line 300, in execute
# res = self._obj.execute(query, params)
# psycopg2.IntegrityError: duplicate key value violates
# unique constraint "ir_property_unique_index"
# DETAIL: Key (fields_id, COALESCE(company_id, 0),
# COALESCE(res_id, ''::character varying))=(13446, 1,
# l10n_br_fiscal.operation,6) already exists.
# TODO: teria uma solução melhor?
l10n_br_sale_or_purchase_installed = False
if env["ir.module.module"].search_count(
[
("name", "=", "l10n_br_purchase"),
("state", "=", "installed"),
]
) or env["ir.module.module"].search_count(
[
("name", "=", "l10n_br_sale"),
("state", "=", "installed"),
]
):
l10n_br_sale_or_purchase_installed = True
# COA Simple Fiscal Operation properties
if company and env["ir.module.module"].search_count(
[
("name", "=", "l10n_br_coa_simple"),
("state", "=", "installed"),
]
):
if not l10n_br_sale_or_purchase_installed:
tools.convert_file(
cr,
"l10n_br_stock_account",
"demo/fiscal_operation_simple.xml",
None,
mode="init",
noupdate=True,
kind="init",
)
else:
env.ref("l10n_br_fiscal.fo_simples_remessa")
data_op_fiscal = "l10n_br_fiscal.operation," + str(
env.ref("l10n_br_fiscal.fo_simples_remessa").id
)
main_company = env.ref("base.main_company", raise_if_not_found=False)
simples_remessa_main_company = env["ir.property"].search(
[
("res_id", "=", data_op_fiscal),
("company_id", "=", main_company.id),
]
)
data_journal = "account.journal," + str(
env.ref(
"l10n_br_stock_account.simples_remessa_journal_main_company"
).id
)
simples_remessa_main_company.value_reference = data_journal
# Devolução de Vendas
data_op_fiscal = "l10n_br_fiscal.operation," + str(
env.ref("l10n_br_fiscal.fo_devolucao_venda").id
)
devolucao_vendas_main_company = env["ir.property"].search(
[
("res_id", "=", data_op_fiscal),
("company_id", "=", main_company.id),
]
)
data_journal = "account.journal," + str(
env.ref(
"l10n_br_stock_account.devolucao_vendas_journal_main_company"
).id
)
devolucao_vendas_main_company.value_reference = data_journal
# Devolução de Compras
data_op_fiscal = "l10n_br_fiscal.operation," + str(
env.ref("l10n_br_fiscal.fo_devolucao_compras").id
)
devolucao_compras_main_company = env["ir.property"].search(
[
("res_id", "=", data_op_fiscal),
("company_id", "=", main_company.id),
]
)
data_journal = "account.journal," + str(
env.ref(
"l10n_br_stock_account.devolucao_compras_journal_main_company"
).id
)
devolucao_compras_main_company.value_reference = data_journal
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"),
]
):
if not l10n_br_sale_or_purchase_installed:
tools.convert_file(
cr,
"l10n_br_stock_account",
"demo/fiscal_operation_generic.xml",
None,
mode="init",
noupdate=True,
kind="init",
)
else:
data_op_fiscal = "l10n_br_fiscal.operation," + str(
env.ref("l10n_br_fiscal.fo_simples_remessa").id
)
simples_remessa_company_lc = env["ir.property"].search(
[
("res_id", "=", data_op_fiscal),
("company_id", "=", company_lc.id),
]
)
data_journal = "account.journal," + str(
env.ref(
"l10n_br_stock_account.simples_remessa_journal_lucro_presumido"
).id
)
simples_remessa_company_lc.value_reference = data_journal