1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
7 # Author : Vincent Renaville
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
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.
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.
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.
30 ##############################################################################
32 from openerp.tools.translate import _
33 from openerp.osv import fields, osv
34 from openerp import pooler
36 class report_webkit_actions(osv.osv_memory):
37 _name = "report.webkit.actions"
38 _description = "Webkit Actions"
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) "),
44 'print_button': lambda *a: True,
45 'open_action': lambda *a: False,
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.
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')
61 if not record_id or (active_model and active_model != 'ir.actions.report.xml'):
64 report = self.pool.get('ir.actions.report.xml').browse(
67 context.get('active_id'),
70 ir_values_obj = self.pool.get('ir.values')
71 ids = ir_values_obj.search(
74 [('value','=',report.type+','+str(context.get('active_id')))]
78 res['arch'] = '''<form string="Add Print Buttons">
79 <label string="Report Action already exist for this report."/>
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.
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(
101 context.get('active_id'),
104 if current.print_button:
105 ir_values_obj = pooler.get_pool(cr.dbname).get('ir.values')
106 res = ir_values_obj.set(
110 'client_print_multi',
113 'ir.actions.report.xml,%d' % context.get('active_id', False),
117 ir_values_obj = pooler.get_pool(cr.dbname).get('ir.values')
118 res = ir_values_obj.set(
122 'client_print_multi',
125 'ir.actions.report.xml,%d' % context.get('active_id', False),
129 if not current.open_action:
130 return {'type': 'ir.actions.act_window_close'}
133 'name': _('Client Actions Connections'),
137 'res_model': 'ir.values',
139 'type': 'ir.actions.act_window',
142 report_webkit_actions()
144 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: