1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
6
# Copyright (c) 2012 Noviat nv/sa (www.noviat.be). All rights reserved.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from osv import fields, osv
25
from tools.translate import _
27
_logger = logging.getLogger(__name__)
29
class be_legal_financial_reportscheme(osv.osv):
30
_name = 'be.legal.financial.reportscheme'
31
_description = 'Belgian Legal Financial Report Scheme (Full)'
32
_rec_name = 'account_group'
34
'account_group': fields.char('Group', size=4, help='General Account Starting Digits'),
35
'report_id': fields.many2one('account.financial.report', 'Report Entry', ondelete='cascade'),
36
'account_ids': fields.related('report_id','account_ids', type='one2many', relation='account.account', string='Accounts', readonly=True),
39
('group_uniq', 'unique (account_group)', 'The General Account Group must be unique !')
41
be_legal_financial_reportscheme()
43
class account_financial_report(osv.osv):
44
_inherit = 'account.financial.report'
46
'code': fields.char('Code', size=16),
47
'invisible': fields.boolean('Invisible', help="Hide this entry from the printed report."),
50
def _get_children_by_order(self, cr, uid, ids, context=None):
52
if context.get('get_children_by_sequence'):
53
res = self.search(cr, uid, [('id', 'child_of', ids[0]), ('invisible', '=', 0)], order='sequence ASC', context=context)
57
ids2 = self.search(cr, uid, [('parent_id', '=', id), ('invisible', '=', 0)], order='sequence ASC', context=context)
58
res += self._get_children_by_order(cr, uid, ids2, context=context)
61
def read(self, cr, user, ids, fields=None, context=None, load='_classic_read'):
62
#_logger.warn('read, context = %s', context)
63
res = super(account_financial_report, self).read(cr, user, ids, fields, context, load)
64
context = context or {}
67
if entry.get('code') and context.get('code_print'):
68
entry['name'] = entry['name'] + ' - (' + entry['code'] + ')'
71
account_financial_report()
73
class account_account(osv.osv):
74
_inherit = 'account.account'
76
def create(self, cr, uid, vals, context=None):
77
acc_id = super(account_account, self).create(cr, uid, vals, context=context)
78
#_logger.warn('create, vals = %s, context = %s', vals, context)
79
scheme_obj = self.pool.get('be.legal.financial.reportscheme')
80
scheme_table = scheme_obj.read(cr, uid, scheme_obj.search(cr, uid, []), context=context)
81
be_report_ids = [x['report_id'][0] for x in scheme_table]
82
acc_code = vals['code']
83
account = self.browse(cr, uid, acc_id)
84
if account.type not in ['view', 'consolidation'] and account.company_id.country_id.code == 'BE':
85
be_report_entries = filter(lambda x: acc_code[0:len(x['account_group'])] == x['account_group'], scheme_table)
87
if len(be_report_entries) > 1:
88
raise osv.except_osv(_('Configuration Error !'), _('Configuration Error in the Belgian Legal Financial Report Scheme.'))
89
be_report_id = be_report_entries[0]['report_id'][0]
90
self.write(cr, uid, account.id, {'financial_report_ids': [(4, be_report_id)]})
93
def write(self, cr, uid, ids, vals, context=None):
94
res = super(account_account, self).write(cr, uid, ids, vals, context=context)
95
#_logger.warn('write, vals = %s, context = %s', vals, context)
96
if 'code' in vals.keys():
97
scheme_obj = self.pool.get('be.legal.financial.reportscheme')
98
scheme_table = scheme_obj.read(cr, uid, scheme_obj.search(cr, uid, []), context=context)
99
be_report_ids = [x['report_id'][0] for x in scheme_table]
100
acc_code = vals['code']
101
for account in self.browse(cr, uid, ids):
103
if account.type not in ['view', 'consolidation'] and account.company_id.country_id.code == 'BE':
104
be_report_entries = filter(lambda x: acc_code[0:len(x['account_group'])] == x['account_group'], scheme_table)
105
if len(be_report_entries) > 1:
106
raise osv.except_osv(_('Configuration Error !'), _('Configuration Error in the Belgian Legal Financial Report Scheme.'))
107
be_report_id = be_report_entries and be_report_entries[0]['report_id'][0]
108
for fin_report in account.financial_report_ids:
109
if fin_report.id in be_report_ids:
110
if fin_report.id == be_report_id:
113
self.write(cr, uid, account.id, {'financial_report_ids': [(3, fin_report.id)]})
114
if be_report_id and not updated:
115
self.write(cr, uid, account.id, {'financial_report_ids': [(4, be_report_id)]})