2010-10-13 12:07:37 +00:00
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
# All Right Reserved
#
# Author : Vincent Renaville
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
2013-05-14 14:28:37 +00:00
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2010-10-13 12:07:37 +00:00
#
##############################################################################
2012-12-06 14:56:32 +00:00
from openerp . tools . translate import _
from openerp . osv import fields , osv
from openerp import pooler
2010-10-13 12:07:37 +00:00
class report_webkit_actions ( osv . osv_memory ) :
_name = " report.webkit.actions "
_description = " Webkit Actions "
_columns = {
2010-10-14 13:38:14 +00:00
' 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 " ) ,
' open_action ' : fields . boolean ( ' Open added action ' , help = " Check this to view the newly added internal print action after creating it (technical view) " ) ,
2010-10-13 12:07:37 +00:00
}
_defaults = {
' print_button ' : lambda * a : True ,
2010-10-14 13:38:14 +00:00
' open_action ' : lambda * a : False ,
2010-10-13 12:07:37 +00:00
}
def fields_view_get ( self , cr , uid , view_id = None , view_type = ' form ' , context = None , toolbar = False , submenu = False ) :
""" Changes the view dynamically
@param self : The object pointer .
@param cr : A database cursor
@param uid : ID of the user currently logged in
@param context : A standard dictionary
@return : New arch of view .
"""
2012-06-05 11:38:39 +00:00
if not context : context = { }
2010-10-13 12:07:37 +00:00
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 )
record_id = context and context . get ( ' active_id ' , False ) or False
active_model = context . get ( ' active_model ' )
if not record_id or ( active_model and active_model != ' ir.actions.report.xml ' ) :
return res
report = self . pool . get ( ' ir.actions.report.xml ' ) . browse (
cr ,
uid ,
context . get ( ' active_id ' ) ,
context = context
)
2011-05-16 15:33:31 +00:00
ir_values_obj = self . pool . get ( ' ir.values ' )
ids = ir_values_obj . search (
2010-10-13 12:07:37 +00:00
cr ,
uid ,
[ ( ' value ' , ' = ' , report . type + ' , ' + str ( context . get ( ' active_id ' ) ) ) ]
)
if ids :
res [ ' arch ' ] = ''' <form string= " Add Print Buttons " >
< label string = " Report Action already exist for this report. " / >
< / form >
'''
return res
2010-12-13 06:43:09 +00:00
def do_action ( self , cr , uid , ids , context = None ) :
2010-10-13 12:07:37 +00:00
""" This Function Open added Action.
@param self : The object pointer .
@param cr : A database cursor
@param uid : ID of the user currently logged in
@param ids : List of report . webkit . actions ' s ID
@param context : A standard dictionary
@return : Dictionary of ir . values form .
2010-12-13 06:43:09 +00:00
"""
if context is None :
context = { }
2010-10-13 12:07:37 +00:00
report_obj = self . pool . get ( ' ir.actions.report.xml ' )
2010-12-13 06:43:09 +00:00
for current in self . browse ( cr , uid , ids , context = context ) :
2010-10-13 12:07:37 +00:00
report = report_obj . browse (
cr ,
uid ,
context . get ( ' active_id ' ) ,
context = context
)
if current . print_button :
2011-05-19 12:13:36 +00:00
ir_values_obj = pooler . get_pool ( cr . dbname ) . get ( ' ir.values ' )
res = ir_values_obj . set (
2010-10-13 12:07:37 +00:00
cr ,
uid ,
' action ' ,
' client_print_multi ' ,
report . report_name ,
[ report . model ] ,
' ir.actions.report.xml, %d ' % context . get ( ' active_id ' , False ) ,
isobject = True
)
else :
2011-05-19 12:13:36 +00:00
ir_values_obj = pooler . get_pool ( cr . dbname ) . get ( ' ir.values ' )
res = ir_values_obj . set (
2010-10-13 12:07:37 +00:00
cr ,
uid ,
' action ' ,
' client_print_multi ' ,
report . report_name ,
[ report . model , 0 ] ,
' ir.actions.report.xml, %d ' % context . get ( ' active_id ' , False ) ,
isobject = True
)
if res [ 0 ] :
if not current . open_action :
2010-12-28 10:41:38 +00:00
return { ' type ' : ' ir.actions.act_window_close ' }
2010-10-13 12:07:37 +00:00
return {
' name ' : _ ( ' Client Actions Connections ' ) ,
' view_type ' : ' form ' ,
2010-10-14 13:38:14 +00:00
' view_mode ' : ' form ' ,
' res_id ' : res [ 0 ] ,
2010-10-13 12:07:37 +00:00
' res_model ' : ' ir.values ' ,
' view_id ' : False ,
' type ' : ' ir.actions.act_window ' ,
}
report_webkit_actions ( )
2011-11-22 08:51:38 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: