2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2014 TeMPO Consulting, MSF. All Rights Reserved
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
23
from osv import fields
24
from tools.translate import _
27
class account_account(osv.osv):
28
_name = "account.account"
29
_inherit = "account.account"
31
def _get_is_analytic_addicted(self, cr, uid, ids, field_name, arg, context=None):
33
An account is dependant on analytic distribution in these cases:
34
- the account is expense (user_type_code == 'expense')
36
Some exclusive cases can be add in the system if you configure your company:
37
- either you also take all income account (user_type_code == 'income')
38
- or you take accounts that are income + 7xx (account code begins with 7)
44
company_account_active = False
45
company = self.pool.get('res.users').browse(cr, uid, uid).company_id
46
if company and company.additional_allocation:
47
company_account_active = company.additional_allocation
48
company_account = 7 # User for accounts that begins by "7"
50
for account in self.read(cr, uid, ids, ['user_type_code', 'code'], context=context):
51
account_id = account.get('id', False)
52
user_type = account.get('user_type_code', False)
53
code = account.get('code')
54
res[account_id] = self.is_analytic_addicted(cr, uid, user_type, code, company_account, company_account_active)
57
def is_analytic_addicted(self, cr, uid, user_type, code, company_account, company_account_active):
61
if user_type == 'expense':
63
elif user_type == 'income':
64
if not company_account_active:
66
elif company_account_active and code.startswith(str(company_account)):
70
def _search_is_analytic_addicted(self, cr, uid, ids, field_name, args, context=None):
72
Search analytic addicted accounts regarding same criteria as those from _get_is_analytic_addicted method.
78
company_account_active = False
79
company = self.pool.get('res.users').browse(cr, uid, uid).company_id
80
if company and company.additional_allocation:
81
company_account_active = company.additional_allocation
84
if x[0] == 'is_analytic_addicted' and ((x[1] in ['=', 'is'] and x[2] is True) or (x[1] in ['!=', 'is not', 'not'] and x[2] is False)):
86
arg.append(('user_type.code', '=', 'expense'))
87
if company_account_active:
89
arg.append(('user_type.code', '=', 'income'))
90
if company_account_active:
91
arg.append(('code', '=like', '%s%%' % company_account))
92
elif x[0] == 'is_analytic_addicted' and ((x[1] in ['=', 'is'] and x[2] is False) or (x[1] in ['!=', 'is not', 'not'] and x[2] is True)):
93
arg.append(('user_type.code', '!=', 'expense'))
94
if company_account_active:
96
arg.append(('user_type.code', '!=', 'income'))
97
arg.append(('code', 'not like', '%s%%' % company_account))
99
arg.append(('user_type.code', '!=', 'income'))
100
elif x[0] != 'is_analytic_addicted':
103
raise osv.except_osv(_('Error'), _('Operation not implemented!'))
106
def _get_accounts_from_company(self, cr, uid, ids, context=None):
107
return self.pool.get('account.account').search(cr, uid, [('user_type.code', '=', 'income')], context=context)
110
'is_analytic_addicted': fields.function(
111
_get_is_analytic_addicted, fnct_search=_search_is_analytic_addicted,
112
method=True, type='boolean', string='Analytic-a-holic?', readonly=True,
113
help="Is this account addicted on analytic distribution?",
114
store={'res.company': (_get_accounts_from_company, ['additional_allocation'], 10),
115
'account.account': (lambda self, cr, uid, ids, c={}: ids, ['user_type_code', 'code'], 10)}),
119
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: