~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to account_simulation/account_simulation.py

  • Committer: Fabien Pinckaers
  • Date: 2008-11-12 06:43:12 UTC
  • Revision ID: fp@tinyerp.com-20081112064312-fp85io97i1e95tuz
moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
1
2
##############################################################################
2
3
#
3
 
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
 
#                    Fabien Pinckaers <fp@tiny.Be>
5
 
#
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
11
 
# Service Company
12
 
#
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.
17
 
#
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.
22
 
#
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
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
26
20
#
27
21
##############################################################################
28
22
 
29
23
from osv import fields, osv
30
24
 
31
25
class account_journal_simulation(osv.osv):
32
 
        _name = "account.journal.simulation"
33
 
        _description = "Simulation level"
34
 
        _columns = {
35
 
                'name': fields.char('Simulation name', size=32, required=True),
36
 
                'code': fields.char('Simulation code', size=8, required=True),
37
 
        }
38
 
        _sql_constraints = [
39
 
                ('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
40
 
        ]
41
 
        _order = "name"
 
26
    _name = "account.journal.simulation"
 
27
    _description = "Simulation level"
 
28
    _columns = {
 
29
        'name': fields.char('Simulation name', size=32, required=True),
 
30
        'code': fields.char('Simulation code', size=8, required=True),
 
31
    }
 
32
    _sql_constraints = [
 
33
        ('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
 
34
    ]
 
35
    _order = "name"
42
36
account_journal_simulation()
43
37
 
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]
49
43
 
50
44
class account_journal(osv.osv):
51
 
        _inherit = "account.journal"
52
 
        _columns = {
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'),
56
 
        }
57
 
        _defaults = {
58
 
                'state': lambda self,cr,uid,context: 'valid'
59
 
        }
 
45
    _inherit = "account.journal"
 
46
    _columns = {
 
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'),
 
50
    }
 
51
    _defaults = {
 
52
        'state': lambda self,cr,uid,context: 'valid'
 
53
    }
60
54
account_journal()
61
55
 
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)
67
 
                ok = True
68
 
                for c in crit:
69
 
                        if c[0]=='journal_id':
70
 
                                ok = False
71
 
                                break
72
 
                if 'journal_id' in context:
73
 
                        ok=False
74
 
                if ok:
75
 
                        plus = ''
76
 
                        for state in context.get('journal_state', []):
77
 
                                plus+=",'"+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)
81
 
                return res
 
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)
 
61
        ok = True
 
62
        for c in crit:
 
63
            if c[0]=='journal_id':
 
64
                ok = False
 
65
                break
 
66
        if 'journal_id' in context:
 
67
            ok=False
 
68
        if ok:
 
69
            plus = ''
 
70
            for state in context.get('journal_state', []):
 
71
                plus+=",'"+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)
 
75
        return res
82
76
 
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']))+")))"
87
 
                else:
88
 
                        plus = " and (l.journal_id in (select id from account_journal where state='valid'))"
89
 
                return res+plus
 
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']))+")))"
 
81
        else:
 
82
            plus = " and ("+obj+".journal_id in (select id from account_journal where state='valid'))"
 
83
        return res+plus
90
84
account_move_line()
 
85
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
86