forked from OCA/l10n-spain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.py
34 lines (31 loc) · 1.54 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
# -*- coding: utf-8 -*-
# © 2015 Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from .constants import ALLOWED_JOURNAL_TYPES
from openerp import SUPERUSER_ID, _
def fill_invoice_sequences(cr, registry):
company_obj = registry['res.company']
journal_obj = registry['account.journal']
model_data_obj = registry['ir.model.data']
sequence_obj = registry['ir.sequence']
company_ids = company_obj.search(cr, SUPERUSER_ID, [])
for company in company_obj.browse(cr, SUPERUSER_ID, company_ids):
if company.country_id and company.country_id.code != 'ES':
# Discard non spanish companies (by the country of the address)
# Companies with no country are not discarded
continue
journal_ids = journal_obj.search(
cr, SUPERUSER_ID, [('company_id', '=', company.id)])
generic_journal_seq_id = model_data_obj.get_object_reference(
cr, SUPERUSER_ID, 'l10n_es_account_invoice_sequence',
'sequence_spanish_journal')[1]
journal_seq_id = sequence_obj.copy(
cr, SUPERUSER_ID, generic_journal_seq_id,
{'name': _('Journal Entries Sequence'),
'company_id': company.id})
for journal in journal_obj.browse(cr, SUPERUSER_ID, journal_ids):
vals = {'sequence_id': journal_seq_id}
if journal.type in ALLOWED_JOURNAL_TYPES:
vals['invoice_sequence_id'] = journal.sequence_id.id
journal_obj.write(
cr, SUPERUSER_ID, journal.id, vals)