~factorlibre/aeroo/aeroo-fix-tz

« back to all changes in this revision

Viewing changes to report_aeroo/wizard/report_actions.py

  • Committer: root
  • Date: 2013-02-01 16:11:17 UTC
  • Revision ID: root@erp.kndati.lv-20130201161117-1n3261woqk45mw5c
1.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2008-2012 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
 
4
#                    General contacts <info@alistek.com>
 
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 3
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This module is GPLv3 or newer and incompatible
 
19
# with OpenERP SA "AGPL + Private Use License"!
 
20
#
 
21
# This program is distributed in the hope that it will be useful,
 
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
# GNU General Public License for more details.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program; if not, write to the Free Software
 
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
29
#
 
30
##############################################################################
 
31
 
 
32
import wizard
 
33
import pooler
 
34
from tools.translate import _
 
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
 
 
40
special_reports = [
 
41
    'printscreen.list'
 
42
]
 
43
 
 
44
class report_actions_wizard(wizard.interface):
 
45
    '''
 
46
    Add Print Button
 
47
    '''
 
48
    form = '''<?xml version="1.0"?>
 
49
    <form string="Add Print Button">
 
50
        <!--<field name="print_button"/>-->
 
51
        <field name="open_action"/>
 
52
    </form>'''
 
53
 
 
54
    exist_form = '''<?xml version="1.0"?>
 
55
    <form string="Add Print Button">
 
56
        <label string="Report Action already exist for this report."/>
 
57
    </form>'''
 
58
 
 
59
    exception_form = '''<?xml version="1.0"?>
 
60
    <form string="Add Print Button">
 
61
        <label string="Can not be create print button for the Special report."/>
 
62
    </form>'''
 
63
 
 
64
    done_form = '''<?xml version="1.0"?>
 
65
    <form string="Remove print button">
 
66
        <label string="The print button is successfully added"/>
 
67
    </form>'''
 
68
 
 
69
    fields = {
 
70
        'open_action': {'string': 'Open added action', 'type': 'boolean', 'default': False},
 
71
    }
 
72
 
 
73
    def _do_action(self, cr, uid, data, context):
 
74
        pool = pooler.get_pool(cr.dbname)
 
75
        report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
 
76
        res = ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
 
77
        if report.report_wizard:
 
78
            report._set_report_wizard()
 
79
        return {'value_id':res[0]}
 
80
 
 
81
    def _check(self, cr, uid, data, context):
 
82
        pool = pooler.get_pool(cr.dbname)
 
83
        ir_values_obj = pool.get('ir.values')
 
84
        report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
 
85
        if report.report_name in special_reports:
 
86
            return 'exception'
 
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'
 
95
        else:
 
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'
 
101
 
 
102
    def _action_open_window(self, cr, uid, data, context):
 
103
        form=data['form']
 
104
        if not form['open_action']:
 
105
            return {}
 
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
 
116
    
 
117
    states = {
 
118
        'init': {
 
119
                        'actions': [],
 
120
                        'result': {'type':'choice','next_state':_check}
 
121
        },
 
122
        'add': {
 
123
            'actions': [],
 
124
            'result': {'type': 'form', 'arch': form, 'fields': fields, 'state': (('end', _('_Cancel')), ('process', _('_Ok')))},
 
125
        },
 
126
        'exist': {
 
127
            'actions': [],
 
128
            'result': {'type': 'form', 'arch': exist_form, 'fields': {}, 'state': (('end', _('_Close')),)},
 
129
        },
 
130
        'exception': {
 
131
            'actions': [],
 
132
            'result': {'type': 'form', 'arch': exception_form, 'fields': {}, 'state': (('end', _('_Close')),)},
 
133
        },
 
134
        'process': {
 
135
            'actions': [_do_action],
 
136
            'result': {'type': 'state', 'state': 'done'},
 
137
        },
 
138
        'done': {
 
139
            'actions': [],
 
140
            'result': {'type': 'form', 'arch': done_form, 'fields': {}, 'state': (('exit', _('_Close')),)},
 
141
        },
 
142
        'exit': {
 
143
            'actions': [],
 
144
            'result': {'type': 'action', 'action': _action_open_window, 'state': 'end'},
 
145
        },
 
146
    }
 
147
report_actions_wizard('aeroo.report_actions')
 
148