[IMP]account_analytic_analysis: set ids intes of id for write bcoz in project there...
[odoo/odoo.git] / addons / report_webkit / wizard / report_webkit_actions.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) 
5 # All Right Reserved
6 #
7 # Author : Vincent Renaville
8 #
9 # WARNING: This program as such is intended to be used by professional
10 # programmers who take the whole responsability of assessing all potential
11 # consequences resulting from its eventual inadequacies and bugs
12 # End users who are looking for a ready-to-use solution with commercial
13 # garantees and support are strongly adviced to contract a Free Software
14 # Service Company
15 #
16 # This program is Free Software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
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 from openerp.tools.translate import _
33 from openerp.osv import fields, osv
34 from openerp import pooler
35
36 class report_webkit_actions(osv.osv_memory):
37     _name = "report.webkit.actions"
38     _description = "Webkit Actions"
39     _columns = {
40        'print_button':fields.boolean('Add print button', help="Check this to add a Print action for this Report in the sidebar of the corresponding document types"),
41        'open_action':fields.boolean('Open added action', help="Check this to view the newly added internal print action after creating it (technical view) "),
42     }
43     _defaults = {
44              'print_button': lambda *a: True,
45              'open_action': lambda *a: False,
46     }    
47
48     def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
49         """ Changes the view dynamically
50          @param self: The object pointer.
51          @param cr: A database cursor
52          @param uid: ID of the user currently logged in
53          @param context: A standard dictionary 
54          @return: New arch of view.
55         """
56         if not context: context = {}
57         res = super(report_webkit_actions, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
58         record_id = context and context.get('active_id', False) or False
59         active_model = context.get('active_model')
60
61         if not record_id or (active_model and active_model != 'ir.actions.report.xml'):
62             return res
63         
64         report = self.pool.get('ir.actions.report.xml').browse(
65                                                     cr, 
66                                                     uid, 
67                                                     context.get('active_id'), 
68                                                     context=context
69                                                 )
70         ir_values_obj = self.pool.get('ir.values')
71         ids = ir_values_obj.search(
72                             cr, 
73                             uid, 
74                             [('value','=',report.type+','+str(context.get('active_id')))]
75                         )        
76
77         if ids:
78             res['arch'] = '''<form string="Add Print Buttons">
79                                  <label string="Report Action already exist for this report."/>
80                              </form> 
81                             '''
82         
83         return res
84
85     def do_action(self, cr, uid, ids, context=None):
86         """ This Function Open added Action.
87          @param self: The object pointer.
88          @param cr: A database cursor
89          @param uid: ID of the user currently logged in
90          @param ids: List of report.webkit.actions's ID
91          @param context: A standard dictionary 
92          @return: Dictionary of ir.values form.
93         """
94         if context is None:
95             context = {}        
96         report_obj = self.pool.get('ir.actions.report.xml')
97         for current in self.browse(cr, uid, ids, context=context):
98             report = report_obj.browse(
99                                                         cr, 
100                                                         uid, 
101                                                         context.get('active_id'), 
102                                                         context=context
103                                                     )
104             if current.print_button:
105                 ir_values_obj = pooler.get_pool(cr.dbname).get('ir.values')
106                 res = ir_values_obj.set(
107                                 cr, 
108                                 uid, 
109                                 'action', 
110                                 'client_print_multi',
111                                  report.report_name, 
112                                  [report.model], 
113                                  'ir.actions.report.xml,%d' % context.get('active_id', False), 
114                                  isobject=True
115                                 )
116             else:
117                 ir_values_obj = pooler.get_pool(cr.dbname).get('ir.values')
118                 res = ir_values_obj.set(
119                                     cr, 
120                                     uid, 
121                                     'action', 
122                                     'client_print_multi', 
123                                     report.report_name, 
124                                     [report.model,0], 
125                                     'ir.actions.report.xml,%d' % context.get('active_id', False), 
126                                     isobject=True
127                                 )
128             if res[0]:
129                 if not current.open_action:
130                     return {'type': 'ir.actions.act_window_close'}
131                 
132                 return {
133                     'name': _('Client Actions Connections'),
134                     'view_type': 'form',
135                     'view_mode': 'form',
136                     'res_id' : res[0],
137                     'res_model': 'ir.values',
138                     'view_id': False,
139                     'type': 'ir.actions.act_window',
140                 }                   
141
142 report_webkit_actions()
143
144 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: