1
# -*- coding: utf-8 -*-
4
# -*- encoding: utf-8 -*-
5
##############################################
7
# ChriCar Beteiligungs- und Beratungs- GmbH
8
# Copyright (C) ChriCar Beteiligungs- und Beratungs- GmbH
10
# created 2009-08-18 23:44:30+02
12
# WARNING: This program as such is intended to be used by professional
13
# programmers who take the whole responsability of assessing all potential
14
# consequences resulting from its eventual inadequacies and bugs.
15
# End users who are looking for a ready-to-use solution with commercial
16
# garantees and support are strongly adviced to contract a Free Software
19
# This program is Free Software; you can redistribute it and/or
20
# modify it under the terms of the GNU General Public License
21
# as published by the Free Software Foundation; either version 3
22
# of the License, or (at your option) any later version.
24
# This program is distributed in the hope that it will be useful,
25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
# GNU General Public License for more details.
29
# You should have received a copy of the GNU General Public License
30
# along with this program; if not, see <http://www.gnu.org/licenses/> or
31
# write to the Free Software Foundation, Inc.,
32
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34
###############################################
36
from osv import fields,osv
41
class account_account(osv.osv):
42
_inherit = "account.account"
47
'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', select=True,
48
help="provide Analytic Account only for default and fixed"),
49
'account_analytic_usage': fields.selection([
51
('default','Default'),
52
('mandatory','Mandatory'),
53
('optional','Optional'),
54
('none','Not allowed'),
55
], 'Analytic Account Usage', help="""This type is used to differenciate types with
56
special effects in Open ERP:
58
* fixed: will be used and user can not change it
59
* default: will be proposed and user can change it
60
* mandatory: user must supply analytic account
62
* mandatory: user must supply analytic account
63
* optional: user may supply analytic account
64
* none: no analytic account allowed""",
69
def _analytic_account_type(self, cr, uid, context={}):
70
account = self.pool.get('account.account').browse(cr, uid, uid, context=context)
71
if account.account_analytic_usage:
73
if account.user_type.close_method == 'none':
80
'account_analytic_usage' : _analytic_account_type,
84
def _check_analytic_account_usage(self, cr, uid, ids):
85
account = self.browse(cr, uid, ids[0])
86
if account.user_type.close_method == 'none' and account.account_analytic_usage not in ('mandatory','default','fixed'):
88
# FIXME - do we need the following check? -
89
#if account.user_type.close_method != 'none' and account.account_analytic_usage not in ('mandatory','optional','none'):
93
def _check_analytic_account_id(self, cr, uid, ids):
94
account = self.browse(cr, uid, ids[0])
95
if not account.account_analytic_id and account.account_analytic_usage in ('default','fixed'):
97
# FIXME - do we need the following check? -
98
if account.account_analytic_id and account.account_analytic_usage not in ('default','fixed'):
104
(_check_analytic_account_usage,
105
'You must assign a correct analytic account usage', ['account_analytic_usage']),
106
(_check_analytic_account_id,
107
'You must define an analytic account for fixed and default, else nothing', ['account_analytic_id']),
114
# We set some resonable values
115
# P & L accounts - mandatory
116
# other no analytic account
118
update account_account
119
set account_analytic_usage = (
121
case when close_method = 'none' and code != 'view' then 'mandatory' when code = 'view' then null else 'none' end
122
from account_account_type aat
123
where aat.id = user_type)
124
where account_analytic_usage is null;
131
class account_move_line(osv.osv):
132
_inherit = "account.move.line"
134
def _check_analytic_account(self, cr, uid, ids):
135
for move in self.browse(cr, uid, ids):
136
# FIXME - does not write the found value
137
#if not move.analytic_account_id and move.account_id.account_analytic_usage in ['default','fixed']:
138
# move.account_id.analytic_account_id = move.account_id.account_analytic_id
140
if not move.analytic_account_id and move.account_id.account_analytic_usage in ['mandatory','default','fixed']:
142
if move.analytic_account_id and move.account_id.account_analytic_usage in ['none']:
147
(_check_analytic_account,
148
'You must assign an analytic account using this account', ['analytic_account_id'] ),
154
class account_bank_statement_line(osv.osv):
155
_inherit = "account.bank.statement.line"
157
def _check_analytic_account(self, cr, uid, ids):
158
for move in self.browse(cr, uid, ids):
159
if not move.account_analytic_id and move.account_id.account_analytic_usage in ['default','fixed']:
160
move.account_analytic_id = move.account_id.account_analytic_id
162
if not move.account_analytic_id and move.account_id.account_analytic_usage in ['mandatory','default','fixed']:
164
if move.account_analytic_id and move.account_id.account_analytic_usage in ['none']:
169
(_check_analytic_account,
170
'You must assign an analytic account using this account', ['account_analytic_id'] ),
173
account_bank_statement_line()
175
class account_invoice_line(osv.osv):
176
_inherit = "account.invoice.line"
179
def _check_analytic_account(self, cr, uid, ids):
180
for move in self.browse(cr, uid, ids):
181
# FIXME - does not write the found value
182
#if not move.account_analytic_id and move.account_id.account_analytic_usage in ['default','fixed']:
183
# move.account_analytic_id = move.account_id.account_analytic_id
184
# res = {'value': {'account_analytic_id' : move.account_id.account_analytic_id.id }}
186
if not move.account_analytic_id and move.account_id.account_analytic_usage in ['mandatory','default','fixed']:
188
if move.account_analytic_id and move.account_id.account_analytic_usage in ['none']:
193
(_check_analytic_account,
194
'You must assign an analytic account using this account', ['account_analytic_id'] ),
197
account_invoice_line()