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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- encoding: utf-8 -*-
##############################################################################
#    
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
#
##############################################################################
from osv import fields, osv

class account_journal_simulation(osv.osv):
    _name = "account.journal.simulation"
    _description = "Simulation level"
    _columns = {
        'name': fields.char('Simulation name', size=32, required=True),
        'code': fields.char('Simulation code', size=8, required=True),
    }
    _sql_constraints = [
        ('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
    ]
    _order = "name"
account_journal_simulation()

def _state_simul_get(self, cr, uid, context={}):
    obj = self.pool.get('account.journal.simulation')
    ids = obj.search(cr, uid, [])
    res = obj.read(cr, uid, ids, ['code', 'name'], context)
    return [('valid','Base')]+ [(r['code'], r['name']) for r in res]

class account_journal(osv.osv):
    _inherit = "account.journal"
    _columns = {
        'state': fields.selection(_state_simul_get, 'Status', required=True),
        'parent_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_src_id', 'journal_dest_id', 'Child journals'),
        'child_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_dest_id', 'journal_src_id', 'Parent journal'),
    }
    _defaults = {
        'state': lambda self,cr,uid,context: 'valid'
    }
account_journal()

class account_move_line(osv.osv):
    _inherit = "account.move.line"
    def search_not_run(self, cr, uid, crit, offset=0, limit=None, order=None, context={}):
        if not 'fiscalyear' in context:
            context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid)
        ok = True
        for c in crit:
            if c[0]=='journal_id':
                ok = False
                break
        if 'journal_id' in context:
            ok=False
        if ok:
            plus = ''
            for state in context.get('journal_state', []):
                plus+=",'"+state+"'"
            cr.execute("select id from account_journal where state in ('valid'"+plus+")")
            crit.append(('journal_id', 'in', map(lambda x: x[0], cr.fetchall())))
        res = super(account_move_line, self).search(cr, uid, crit, offset, limit, order, context)
        return res

    def _query_get(self, cr, uid, obj='l', context={}):
        res = super(account_move_line, self)._query_get(cr, uid, obj, context)
        if context.get('journal_state', []):
            plus = " and ("+obj+".journal_id in (select id from account_journal where state in ('valid', "+','.join(map(lambda x: "'"+x+"'", context['journal_state']))+")))"
        else:
            plus = " and ("+obj+".journal_id in (select id from account_journal where state='valid'))"
        return res+plus
account_move_line()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: