forked from OCA/l10n-spain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
37 lines (32 loc) · 1.55 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 2018 David Vidal <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, SUPERUSER_ID
def post_init_hook(cr, registry, vals=None):
"""For brand new installations"""
env = api.Environment(cr, SUPERUSER_ID, {})
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]))
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', "%s%s" %
(pos_name, pos._get_default_prefix())),
'padding': pos_vals.get('padding', pos._get_default_padding()),
'implementation': pos_vals.get('implementation', 'no_gap'),
'code': 'pos.config.simplified_invoice',
'company_id': pos_vals.get('company_id', pos.company_id.id),
})
def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.sequence'].search([
('code', '=', 'pos.config.simplified_invoice')]).unlink()