-
-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathhooks.py
48 lines (44 loc) · 1.85 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
# Copyright 2018 David Vidal <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
def post_init_hook(env, vals=None):
"""For brand new installations"""
IrSequence = env["ir.sequence"]
pos_config = env["pos.config"].search(
[("l10n_es_simplified_invoice_sequence_id", "=", False)]
)
pos_name_dupes = {}
vals = {} if vals is None else vals
for pos in pos_config:
pos_name_dupes.setdefault(pos.name, -1)
pos_name_dupes[pos.name] += 1
pos_vals = vals.get(pos, {})
pos_name = (
pos.name
if not pos_name_dupes[pos.name]
else "%s_%d" % (pos.name, pos_name_dupes[pos.name])
)
if not pos_vals.get("prefix"):
pos_vals["prefix"] = initial_prefix = "{}{}".format(
pos_name, pos._get_default_prefix()
)
ith = 0
while IrSequence.search_count([("prefix", "=", pos_vals["prefix"])]):
ith += 1
pos_vals["prefix"] = f"{initial_prefix}_{ith}"
pos.l10n_es_simplified_invoice_sequence_id = IrSequence.create(
{
"name": (
pos.with_context(lang=env.user.lang)._get_l10n_es_sequence_name()
% pos_name
),
"prefix": pos_vals.get(
"prefix", f"{pos_name}{pos._get_default_prefix()}"
),
"padding": pos_vals.get("padding", pos._get_default_padding()),
"implementation": pos_vals.get("implementation", "standard"),
"code": "pos.config.simplified_invoice",
"company_id": pos_vals.get("company_id", pos.company_id.id),
}
)
def uninstall_hook(env):
env["ir.sequence"].search([("code", "=", "pos.config.simplified_invoice")]).unlink()