1
# -*- encoding: utf-8 -*-
1
2
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.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 General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (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 General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
21
##############################################################################
29
23
from osv import fields, osv
31
25
class account_journal_simulation(osv.osv):
32
_name = "account.journal.simulation"
33
_description = "Simulation level"
35
'name': fields.char('Simulation name', size=32, required=True),
36
'code': fields.char('Simulation code', size=8, required=True),
39
('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
26
_name = "account.journal.simulation"
27
_description = "Simulation level"
29
'name': fields.char('Simulation name', size=32, required=True),
30
'code': fields.char('Simulation code', size=8, required=True),
33
('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
42
36
account_journal_simulation()
44
38
def _state_simul_get(self, cr, uid, context={}):
45
obj = self.pool.get('account.journal.simulation')
46
ids = obj.search(cr, uid, [])
47
res = obj.read(cr, uid, ids, ['code', 'name'], context)
48
return [('valid','Base')]+ [(r['code'], r['name']) for r in res]
39
obj = self.pool.get('account.journal.simulation')
40
ids = obj.search(cr, uid, [])
41
res = obj.read(cr, uid, ids, ['code', 'name'], context)
42
return [('valid','Base')]+ [(r['code'], r['name']) for r in res]
50
44
class account_journal(osv.osv):
51
_inherit = "account.journal"
53
'state': fields.selection(_state_simul_get, 'Status', required=True),
54
'parent_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_src_id', 'journal_dest_id', 'Childs journal'),
55
'child_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_dest_id', 'journal_src_id', 'Parent journal'),
58
'state': lambda self,cr,uid,context: 'valid'
45
_inherit = "account.journal"
47
'state': fields.selection(_state_simul_get, 'Status', required=True),
48
'parent_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_src_id', 'journal_dest_id', 'Childs journal'),
49
'child_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_dest_id', 'journal_src_id', 'Parent journal'),
52
'state': lambda self,cr,uid,context: 'valid'
62
56
class account_move_line(osv.osv):
63
_inherit = "account.move.line"
64
def search_not_run(self, cr, uid, crit, offset=0, limit=None, order=None, context={}):
65
if not 'fiscalyear' in context:
66
context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid)
69
if c[0]=='journal_id':
72
if 'journal_id' in context:
76
for state in context.get('journal_state', []):
78
cr.execute("select id from account_journal where state in ('valid'"+plus+")")
79
crit.append(('journal_id', 'in', map(lambda x: x[0], cr.fetchall())))
80
res = super(account_move_line, self).search(cr, uid, crit, offset, limit, order, context)
57
_inherit = "account.move.line"
58
def search_not_run(self, cr, uid, crit, offset=0, limit=None, order=None, context={}):
59
if not 'fiscalyear' in context:
60
context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid)
63
if c[0]=='journal_id':
66
if 'journal_id' in context:
70
for state in context.get('journal_state', []):
72
cr.execute("select id from account_journal where state in ('valid'"+plus+")")
73
crit.append(('journal_id', 'in', map(lambda x: x[0], cr.fetchall())))
74
res = super(account_move_line, self).search(cr, uid, crit, offset, limit, order, context)
83
def _query_get(self, cr, uid, obj='l', context={}):
84
res = super(account_move_line, self)._query_get(cr, uid, obj, context)
85
if context.get('journal_state', []):
86
plus = " and (l.journal_id in (select id from account_journal where state in ('valid', "+','.join(map(lambda x: "'"+x+"'", context['journal_state']))+")))"
88
plus = " and (l.journal_id in (select id from account_journal where state='valid'))"
77
def _query_get(self, cr, uid, obj='l', context={}):
78
res = super(account_move_line, self)._query_get(cr, uid, obj, context)
79
if context.get('journal_state', []):
80
plus = " and ("+obj+".journal_id in (select id from account_journal where state in ('valid', "+','.join(map(lambda x: "'"+x+"'", context['journal_state']))+")))"
82
plus = " and ("+obj+".journal_id in (select id from account_journal where state='valid'))"
90
84
account_move_line()
85
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: