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

« back to all changes in this revision

Viewing changes to account_simulation/account_simulation.py

merging new development from indian accounting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
1
2
##############################################################################
2
3
#
3
4
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
29
30
from osv import fields, osv
30
31
 
31
32
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"
 
33
    _name = "account.journal.simulation"
 
34
    _description = "Simulation level"
 
35
    _columns = {
 
36
        'name': fields.char('Simulation name', size=32, required=True),
 
37
        'code': fields.char('Simulation code', size=8, required=True),
 
38
    }
 
39
    _sql_constraints = [
 
40
        ('code_uniq', 'unique (code)', 'The code of the simulation must be unique !')
 
41
    ]
 
42
    _order = "name"
42
43
account_journal_simulation()
43
44
 
44
45
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]
 
46
    obj = self.pool.get('account.journal.simulation')
 
47
    ids = obj.search(cr, uid, [])
 
48
    res = obj.read(cr, uid, ids, ['code', 'name'], context)
 
49
    return [('valid','Base')]+ [(r['code'], r['name']) for r in res]
49
50
 
50
51
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
 
        }
 
52
    _inherit = "account.journal"
 
53
    _columns = {
 
54
        'state': fields.selection(_state_simul_get, 'Status', required=True),
 
55
        'parent_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_src_id', 'journal_dest_id', 'Childs journal'),
 
56
        'child_ids': fields.many2many('account.journal', 'account_journal_simulation_rel', 'journal_dest_id', 'journal_src_id', 'Parent journal'),
 
57
    }
 
58
    _defaults = {
 
59
        'state': lambda self,cr,uid,context: 'valid'
 
60
    }
60
61
account_journal()
61
62
 
62
63
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
 
64
    _inherit = "account.move.line"
 
65
    def search_not_run(self, cr, uid, crit, offset=0, limit=None, order=None, context={}):
 
66
        if not 'fiscalyear' in context:
 
67
            context['fiscalyear'] = self.pool.get('account.fiscalyear').find(cr, uid)
 
68
        ok = True
 
69
        for c in crit:
 
70
            if c[0]=='journal_id':
 
71
                ok = False
 
72
                break
 
73
        if 'journal_id' in context:
 
74
            ok=False
 
75
        if ok:
 
76
            plus = ''
 
77
            for state in context.get('journal_state', []):
 
78
                plus+=",'"+state+"'"
 
79
            cr.execute("select id from account_journal where state in ('valid'"+plus+")")
 
80
            crit.append(('journal_id', 'in', map(lambda x: x[0], cr.fetchall())))
 
81
        res = super(account_move_line, self).search(cr, uid, crit, offset, limit, order, context)
 
82
        return res
82
83
 
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
 
84
    def _query_get(self, cr, uid, obj='l', context={}):
 
85
        res = super(account_move_line, self)._query_get(cr, uid, obj, context)
 
86
        if context.get('journal_state', []):
 
87
            plus = " and ("+obj+".journal_id in (select id from account_journal where state in ('valid', "+','.join(map(lambda x: "'"+x+"'", context['journal_state']))+")))"
 
88
        else:
 
89
            plus = " and ("+obj+".journal_id in (select id from account_journal where state='valid'))"
 
90
        return res+plus
90
91
account_move_line()
 
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
93