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

« back to all changes in this revision

Viewing changes to personal_base/wizard/open_line_entry.py

  • Committer: pso (tiny)
  • Date: 2009-02-10 13:58:54 UTC
  • mto: This revision was merged to the branch mainline in revision 3554.
  • Revision ID: pso@tinyerp.com-20090210135854-egbyysq88p1v41w8
personal_base:made compatible to 5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2007-2008 Sandas. (http://www.sandas.eu) All Rights Reserved.
 
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.
 
26
#
 
27
############################################################
 
28
 
 
29
import wizard
 
30
import pooler
 
31
 
 
32
class wiz_open_line_entry(wizard.interface):
 
33
    def _open_line_entry(self, cr, uid, data, context):
 
34
        pool = pooler.get_pool(cr.dbname)
 
35
        lines = pool.get('personal.base.account.entry.line').browse(cr, uid, data['ids'])
 
36
        ids = []
 
37
        model = None
 
38
        for l in lines:
 
39
            if not model:
 
40
                model = l.parent_id.created_in_model_id
 
41
            if model.id == l.parent_id.created_in_model_id.id:
 
42
                ids.append(l.parent_id.id)
 
43
        if ids != []:
 
44
            if model.model == 'personal.base.account.entry':
 
45
                id_field_name = 'id'
 
46
            else:
 
47
                id_field_name = 'entry_id'
 
48
                
 
49
            domain = "[('" + id_field_name + "','in', [" + ','.join(map(str,ids)) + "])"
 
50
            if model.model == 'personal.base.account.entry':
 
51
                domain = domain + ",('created_in_model_id', '=', %d)" % model.id
 
52
            domain = domain + ']'
 
53
            return {
 
54
                    'domain': domain,
 
55
                    #'name': 'Entries',
 
56
                    'view_type': 'form',
 
57
                    'view_mode': 'tree,form',
 
58
                    'res_model': model.model,
 
59
                    'view_id': False,
 
60
                    'type': 'ir.actions.act_window'
 
61
            }
 
62
            
 
63
        return {}
 
64
    states = {
 
65
        'init': {
 
66
            'actions': [],
 
67
            'result': {'type':'action', 'action':_open_line_entry, 'state':'end'}
 
68
        }
 
69
    }
 
70
wiz_open_line_entry('personal.base.account.open_line_entry')