~chris-ormaza/aeroo/openerp6

« back to all changes in this revision

Viewing changes to report_aeroo/wizard/report_actions.py

  • Committer: root
  • Date: 2011-11-15 11:01:45 UTC
  • Revision ID: root@erp.kndati.lv-20111115110145-ybiy32im1hnvoby7
RC6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
##############################################################################
2
2
#
3
 
# Copyright (c) 2008-2011 Alistek, SIA. (http://www.alistek.com) All Rights Reserved.
 
3
# Copyright (c) 2008-2011 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
4
4
#                    General contacts <info@alistek.com>
5
5
#
6
6
# WARNING: This program as such is intended to be used by professional
12
12
#
13
13
# This program is Free Software; you can redistribute it and/or
14
14
# modify it under the terms of the GNU General Public License
15
 
# as published by the Free Software Foundation; either version 2
 
15
# as published by the Free Software Foundation; either version 3
16
16
# of the License, or (at your option) any later version.
17
17
#
 
18
# This module is GPLv3 or newer and incompatible
 
19
# with OpenERP SA "AGPL + Private Use License"!
 
20
#
18
21
# This program is distributed in the hope that it will be useful,
19
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
31
 
29
32
import wizard
30
33
import pooler
31
 
import ir
32
34
from tools.translate import _
33
35
 
 
36
def ir_set(cr, uid, key, key2, name, models, value, replace=True, isobject=False, meta=None):
 
37
    obj = pooler.get_pool(cr.dbname).get('ir.values')
 
38
    return obj.set(cr, uid, key, key2, name, models, value, replace, isobject, meta)
 
39
 
34
40
special_reports = [
35
41
    'printscreen.list'
36
42
]
61
67
    </form>'''
62
68
 
63
69
    fields = {
64
 
        #'print_button': {'string': 'Add print button', 'type': 'boolean', 'default': True, 'help':'Add action to menu context in print button.'},
65
70
        'open_action': {'string': 'Open added action', 'type': 'boolean', 'default': False},
66
71
    }
67
72
 
68
73
    def _do_action(self, cr, uid, data, context):
69
74
        pool = pooler.get_pool(cr.dbname)
70
75
        report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
71
 
        #if data['form']['print_button']:
72
76
        res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
73
 
        #else:
74
 
            #    res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model,0], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
 
77
        if report.report_wizard:
 
78
            report._set_report_wizard()
75
79
        return {'value_id':res[0]}
76
80
 
77
81
    def _check(self, cr, uid, data, context):
78
82
        pool = pooler.get_pool(cr.dbname)
 
83
        ir_values_obj = pool.get('ir.values')
79
84
        report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
80
85
        if report.report_name in special_reports:
81
86
            return 'exception'
82
 
        ids = pool.get('ir.values').search(cr, uid, [('value','=',report.type+','+str(data['id']))])
83
 
        if not ids:
84
 
                return 'add'
 
87
        if report.report_wizard:
 
88
            act_win_obj = pool.get('ir.actions.act_window')
 
89
            act_win_ids = act_win_obj.search(cr, uid, [('res_model','=','aeroo.print_actions')], context=context)
 
90
            for act_win in act_win_obj.browse(cr, uid, act_win_ids, context=context):
 
91
                act_win_context = eval(act_win.context, {})
 
92
                if act_win_context.get('report_action_id')==report.id:
 
93
                    return 'exist'
 
94
            return 'add'
85
95
        else:
86
 
                return 'exist'
 
96
            ids = ir_values_obj.search(cr, uid, [('value','=',report.type+','+str(data['id']))])
 
97
            if not ids:
 
98
                    return 'add'
 
99
            else:
 
100
                    return 'exist'
87
101
 
88
102
    def _action_open_window(self, cr, uid, data, context):
89
103
        form=data['form']
90
104
        if not form['open_action']:
91
105
            return {}
92
 
        return {
93
 
            'domain':"[('id','=',%d)]" % (form['value_id']),
94
 
            'name': _('Client Actions Connections'),
95
 
            'view_type': 'form',
96
 
            'view_mode': 'tree,form',
97
 
            'res_model': 'ir.values',
98
 
            'view_id': False,
99
 
            'type': 'ir.actions.act_window',
100
 
        }
 
106
 
 
107
        mod_obj = pooler.get_pool(cr.dbname).get('ir.model.data')
 
108
        act_obj = pooler.get_pool(cr.dbname).get('ir.actions.act_window')
 
109
 
 
110
        mod_id = mod_obj.search(cr, uid, [('name', '=', 'act_values_form_action')])[0]
 
111
        res_id = mod_obj.read(cr, uid, mod_id, ['res_id'])['res_id']
 
112
        act_win = act_obj.read(cr, uid, res_id, [])
 
113
        act_win['domain'] = [('id','=',form['value_id'])]
 
114
        act_win['name'] = _('Client Events')
 
115
        return act_win
101
116
    
102
117
    states = {
103
118
        'init': {