2009-10-20 10:52:23 +00:00
# -*- coding: utf-8 -*-
2006-12-07 13:41:40 +00:00
##############################################################################
2009-10-30 12:33:59 +00:00
#
2009-10-14 12:32:15 +00:00
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
2008-06-16 11:00:21 +00:00
#
2008-11-03 18:27:16 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 12:32:15 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2006-12-07 13:41:40 +00:00
#
2008-11-03 18:27:16 +00:00
# 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
2009-10-14 12:32:15 +00:00
# GNU Affero General Public License for more details.
2006-12-07 13:41:40 +00:00
#
2009-10-14 12:32:15 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-10-30 12:33:59 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2006-12-07 13:41:40 +00:00
#
##############################################################################
from osv import fields , osv
2010-05-03 23:49:53 +00:00
from tools . safe_eval import safe_eval as eval
2007-09-07 14:02:45 +00:00
import tools
2008-06-15 00:25:47 +00:00
import time
2008-07-23 07:33:17 +00:00
from tools . config import config
2009-03-06 18:06:50 +00:00
from tools . translate import _
2008-07-23 08:16:45 +00:00
import netsvc
2008-08-21 10:36:17 +00:00
import re
2009-09-17 07:27:12 +00:00
import copy
2010-10-01 11:25:52 +00:00
import os
2009-12-02 11:21:22 +00:00
from xml import dom
2010-10-01 11:25:52 +00:00
from report . report_sxw import report_sxw , report_rml
2006-12-07 13:41:40 +00:00
class actions ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.actions '
_table = ' ir_actions '
_columns = {
' name ' : fields . char ( ' Action Name ' , required = True , size = 64 ) ,
2010-09-29 07:58:17 +00:00
' type ' : fields . char ( ' Action Type ' , required = True , size = 32 , readonly = True ) ,
2008-07-22 14:24:36 +00:00
' usage ' : fields . char ( ' Action Usage ' , size = 32 ) ,
}
_defaults = {
' usage ' : lambda * a : False ,
}
2006-12-07 13:41:40 +00:00
actions ( )
class report_xml ( osv . osv ) :
2007-09-07 14:02:45 +00:00
2008-07-22 14:24:36 +00:00
def _report_content ( self , cursor , user , ids , name , arg , context = None ) :
res = { }
for report in self . browse ( cursor , user , ids , context = context ) :
data = report [ name + ' _data ' ]
if not data and report [ name [ : - 8 ] ] :
try :
fp = tools . file_open ( report [ name [ : - 8 ] ] , mode = ' rb ' )
data = fp . read ( )
except :
data = False
res [ report . id ] = data
return res
2007-09-07 14:02:45 +00:00
2008-07-22 14:24:36 +00:00
def _report_content_inv ( self , cursor , user , id , name , value , arg , context = None ) :
self . write ( cursor , user , id , { name + ' _data ' : value } , context = context )
2007-09-07 14:02:45 +00:00
2008-07-22 14:24:36 +00:00
def _report_sxw ( self , cursor , user , ids , name , arg , context = None ) :
res = { }
for report in self . browse ( cursor , user , ids , context = context ) :
if report . report_rml :
res [ report . id ] = report . report_rml . replace ( ' .rml ' , ' .sxw ' )
else :
res [ report . id ] = False
return res
2007-09-07 14:02:45 +00:00
2010-10-01 11:25:52 +00:00
def register_all ( self , cr ) :
""" Report registration handler that may be overridden by subclasses to
add their own kinds of report services .
Loads all reports with no manual loaders ( auto == True ) and
registers the appropriate services to implement them .
"""
opj = os . path . join
cr . execute ( " SELECT * FROM ir_act_report_xml WHERE auto= %s ORDER BY id " , ( True , ) )
result = cr . dictfetchall ( )
svcs = netsvc . Service . _services
for r in result :
if svcs . has_key ( ' report. ' + r [ ' report_name ' ] ) :
continue
if r [ ' report_rml ' ] or r [ ' report_rml_content_data ' ] :
report_sxw ( ' report. ' + r [ ' report_name ' ] , r [ ' model ' ] ,
opj ( ' addons ' , r [ ' report_rml ' ] or ' / ' ) , header = r [ ' header ' ] )
if r [ ' report_xsl ' ] :
report_rml ( ' report. ' + r [ ' report_name ' ] , r [ ' model ' ] ,
opj ( ' addons ' , r [ ' report_xml ' ] ) ,
r [ ' report_xsl ' ] and opj ( ' addons ' , r [ ' report_xsl ' ] ) )
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.report.xml '
_table = ' ir_act_report_xml '
_sequence = ' ir_actions_id_seq '
_columns = {
' name ' : fields . char ( ' Name ' , size = 64 , required = True , translate = True ) ,
2008-08-21 13:49:55 +00:00
' model ' : fields . char ( ' Object ' , size = 64 , required = True ) ,
2010-07-21 07:13:32 +00:00
' type ' : fields . char ( ' Action Type ' , size = 32 , required = True ) ,
' report_name ' : fields . char ( ' Service Name ' , size = 64 , required = True ) ,
2008-07-22 14:24:36 +00:00
' usage ' : fields . char ( ' Action Usage ' , size = 32 ) ,
2010-10-01 11:25:52 +00:00
' report_type ' : fields . char ( ' Report Type ' , size = 32 , required = True , help = " Report Type, e.g. pdf, html, raw, sxw, odt, html2html, mako2html, ... " ) ,
2008-09-04 00:22:48 +00:00
' groups_id ' : fields . many2many ( ' res.groups ' , ' res_groups_report_rel ' , ' uid ' , ' gid ' , ' Groups ' ) ,
2010-07-21 07:13:32 +00:00
' multi ' : fields . boolean ( ' On multiple doc. ' , help = " If set to true, the action will not be displayed on the right toolbar of a form view. " ) ,
2009-01-26 17:40:29 +00:00
' attachment ' : fields . char ( ' Save As Attachment Prefix ' , size = 128 , help = ' This is the filename of the attachment used to store the printing result. Keep empty to not save the printed reports. You can use a python expression with the object and time variables. ' ) ,
2010-07-21 07:22:52 +00:00
' attachment_use ' : fields . boolean ( ' Reload from Attachment ' , help = ' If you check this, then the second time the user prints with same attachment name, it returns the previous report. ' ) ,
2010-07-21 07:13:32 +00:00
' auto ' : fields . boolean ( ' Custom python parser ' , required = True ) ,
' header ' : fields . boolean ( ' Add RML header ' , help = " Add or not the coporate RML header " ) ,
' report_xsl ' : fields . char ( ' XSL path ' , size = 256 ) ,
' report_xml ' : fields . char ( ' XML path ' , size = 256 , help = ' ' ) ,
2010-10-08 14:23:01 +00:00
# Pending deprecation... to be replaced by report_file as this object will become the default report object (not so specific to RML anymore)
' report_rml ' : fields . char ( ' Main report file path ' , size = 256 , help = " The path to the main report file (depending on Report Type) or NULL if the content is in another data field " ) ,
# temporary related field as report_rml is pending deprecation - this field will replace report_rml after v6.0
' report_file ' : fields . related ( ' report_rml ' , type = " char " , size = 256 , required = False , readonly = False , string = ' Report file ' , help = " The path to the main report file (depending on Report Type) or NULL if the content is in another field " , store = True ) ,
' report_sxw ' : fields . function ( _report_sxw , method = True , type = ' char ' , string = ' SXW path ' ) ,
2010-07-21 07:13:32 +00:00
' report_sxw_content_data ' : fields . binary ( ' SXW content ' ) ,
' report_rml_content_data ' : fields . binary ( ' RML content ' ) ,
' report_sxw_content ' : fields . function ( _report_content , fnct_inv = _report_content_inv , method = True , type = ' binary ' , string = ' SXW content ' , ) ,
' report_rml_content ' : fields . function ( _report_content , fnct_inv = _report_content_inv , method = True , type = ' binary ' , string = ' RML content ' ) ,
2008-07-22 14:24:36 +00:00
}
_defaults = {
' type ' : lambda * a : ' ir.actions.report.xml ' ,
' multi ' : lambda * a : False ,
' auto ' : lambda * a : True ,
' header ' : lambda * a : True ,
' report_sxw_content ' : lambda * a : False ,
' report_type ' : lambda * a : ' pdf ' ,
2008-09-04 00:22:48 +00:00
' attachment ' : lambda * a : False ,
2008-07-22 14:24:36 +00:00
}
2007-07-31 14:08:58 +00:00
2006-12-07 13:41:40 +00:00
report_xml ( )
class act_window ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.act_window '
_table = ' ir_act_window '
_sequence = ' ir_actions_id_seq '
2009-10-30 12:33:59 +00:00
2009-03-16 17:49:01 +00:00
def _check_model ( self , cr , uid , ids , context = { } ) :
for action in self . browse ( cr , uid , ids , context ) :
if not self . pool . get ( action . res_model ) :
return False
if action . src_model and not self . pool . get ( action . src_model ) :
return False
return True
_constraints = [
( _check_model , ' Invalid model name in the action definition. ' , [ ' res_model ' , ' src_model ' ] )
]
2008-09-18 14:02:05 +00:00
2008-07-22 14:24:36 +00:00
def _views_get_fnc ( self , cr , uid , ids , name , arg , context = { } ) :
res = { }
for act in self . browse ( cr , uid , ids ) :
res [ act . id ] = [ ( view . view_id . id , view . view_mode ) for view in act . view_ids ]
2008-11-17 16:56:01 +00:00
modes = act . view_mode . split ( ' , ' )
if len ( modes ) > len ( act . view_ids ) :
2008-07-22 14:24:36 +00:00
find = False
2008-09-09 13:22:10 +00:00
if act . view_id :
2008-07-22 14:24:36 +00:00
res [ act . id ] . append ( ( act . view_id . id , act . view_id . type ) )
2008-11-17 16:56:01 +00:00
for t in modes [ len ( act . view_ids ) : ] :
2008-07-22 14:24:36 +00:00
if act . view_id and ( t == act . view_id . type ) and not find :
find = True
continue
res [ act . id ] . append ( ( False , t ) )
return res
2007-05-15 13:27:39 +00:00
2009-09-17 07:27:12 +00:00
def _search_view ( self , cr , uid , ids , name , arg , context = { } ) :
res = { }
def encode ( s ) :
if isinstance ( s , unicode ) :
return s . encode ( ' utf8 ' )
return s
for act in self . browse ( cr , uid , ids ) :
2010-04-22 09:59:00 +00:00
fields_from_fields_get = self . pool . get ( act . res_model ) . fields_get ( cr , uid , context = context )
2010-03-05 07:59:38 +00:00
search_view_id = False
2009-09-17 07:27:12 +00:00
if act . search_view_id :
2010-03-05 07:59:38 +00:00
search_view_id = act . search_view_id . id
else :
res_view = self . pool . get ( ' ir.ui.view ' ) . search ( cr , uid , [ ( ' model ' , ' = ' , act . res_model ) , ( ' type ' , ' = ' , ' search ' ) , ( ' inherit_id ' , ' = ' , False ) ] )
if res_view :
search_view_id = res_view [ 0 ]
if search_view_id :
field_get = self . pool . get ( act . res_model ) . fields_view_get ( cr , uid , search_view_id , ' search ' , context )
2009-09-17 07:27:12 +00:00
fields_from_fields_get . update ( field_get [ ' fields ' ] )
field_get [ ' fields ' ] = fields_from_fields_get
res [ act . id ] = str ( field_get )
else :
def process_child ( node , new_node , doc ) :
for child in node . childNodes :
if child . localName == ' field ' and child . hasAttribute ( ' select ' ) and child . getAttribute ( ' select ' ) == ' 1 ' :
if child . childNodes :
fld = doc . createElement ( ' field ' )
for attr in child . attributes . keys ( ) :
fld . setAttribute ( attr , child . getAttribute ( attr ) )
new_node . appendChild ( fld )
else :
new_node . appendChild ( child )
elif child . localName in ( ' page ' , ' group ' , ' notebook ' ) :
process_child ( child , new_node , doc )
form_arch = self . pool . get ( act . res_model ) . fields_view_get ( cr , uid , False , ' form ' , context )
dom_arc = dom . minidom . parseString ( encode ( form_arch [ ' arch ' ] ) )
new_node = copy . deepcopy ( dom_arc )
for child_node in new_node . childNodes [ 0 ] . childNodes :
if child_node . nodeType == child_node . ELEMENT_NODE :
new_node . childNodes [ 0 ] . removeChild ( child_node )
process_child ( dom_arc . childNodes [ 0 ] , new_node . childNodes [ 0 ] , dom_arc )
form_arch [ ' arch ' ] = new_node . toxml ( )
form_arch [ ' fields ' ] . update ( fields_from_fields_get )
res [ act . id ] = str ( form_arch )
return res
2010-10-06 14:11:09 +00:00
def _get_help_status ( self , cr , uid , ids , name , arg , context = { } ) :
activate_tips = self . pool . get ( ' res.users ' ) . browse ( cr , uid , uid ) . menu_tips
return dict ( [ ( id , activate_tips ) for id in ids ] )
2008-07-22 14:24:36 +00:00
_columns = {
' name ' : fields . char ( ' Action Name ' , size = 64 , translate = True ) ,
' type ' : fields . char ( ' Action Type ' , size = 32 , required = True ) ,
' view_id ' : fields . many2one ( ' ir.ui.view ' , ' View Ref. ' , ondelete = ' cascade ' ) ,
2010-07-06 07:06:58 +00:00
' domain ' : fields . char ( ' Domain Value ' , size = 250 ,
2010-07-05 17:57:59 +00:00
help = " Optional domain filtering of the destination data, as a Python expression " ) ,
2010-07-06 07:06:58 +00:00
' context ' : fields . char ( ' Context Value ' , size = 250 , required = True ,
2010-07-05 17:57:59 +00:00
help = " Context dictionary as Python expression, empty by default (Default: {} ) " ) ,
2010-07-06 07:06:58 +00:00
' res_model ' : fields . char ( ' Object ' , size = 64 , required = True ,
2010-07-05 17:57:59 +00:00
help = " Model name of the object to open in the view window " ) ,
2010-07-06 07:06:58 +00:00
' src_model ' : fields . char ( ' Source Object ' , size = 64 ,
2010-07-05 17:57:59 +00:00
help = " Optional model name of the objects on which this action should be visible " ) ,
2008-07-22 14:24:36 +00:00
' target ' : fields . selection ( [ ( ' current ' , ' Current Window ' ) , ( ' new ' , ' New Window ' ) ] , ' Target Window ' ) ,
2010-07-05 17:57:59 +00:00
' view_type ' : fields . selection ( ( ( ' tree ' , ' Tree ' ) , ( ' form ' , ' Form ' ) ) , string = ' View Type ' , required = True ,
help = " View type: set to ' tree ' for a hierarchical tree view, or ' form ' for other views " ) ,
' view_mode ' : fields . char ( ' View Mode ' , size = 250 , required = True ,
help = " Comma-separated list of allowed view modes, such as ' form ' , ' tree ' , ' calendar ' , etc. (Default: tree,form) " ) ,
2008-07-22 14:24:36 +00:00
' usage ' : fields . char ( ' Action Usage ' , size = 32 ) ,
' view_ids ' : fields . one2many ( ' ir.actions.act_window.view ' , ' act_window_id ' , ' Views ' ) ,
' views ' : fields . function ( _views_get_fnc , method = True , type = ' binary ' , string = ' Views ' ) ,
' limit ' : fields . integer ( ' Limit ' , help = ' Default limit for the list view ' ) ,
' auto_refresh ' : fields . integer ( ' Auto-Refresh ' ,
help = ' Add an auto-refresh on the view ' ) ,
2008-09-18 14:02:05 +00:00
' groups_id ' : fields . many2many ( ' res.groups ' , ' ir_act_window_group_rel ' ,
' act_id ' , ' gid ' , ' Groups ' ) ,
2009-09-17 07:27:12 +00:00
' search_view_id ' : fields . many2one ( ' ir.ui.view ' , ' Search View Ref. ' ) ,
' filter ' : fields . boolean ( ' Filter ' ) ,
2010-02-19 13:46:56 +00:00
' auto_search ' : fields . boolean ( ' Auto Search ' ) ,
2009-09-17 07:27:12 +00:00
' search_view ' : fields . function ( _search_view , type = ' text ' , method = True , string = ' Search View ' ) ,
2010-06-23 09:19:52 +00:00
' menus ' : fields . char ( ' Menus ' , size = 4096 ) ,
2010-07-06 07:06:58 +00:00
' help ' : fields . text ( ' Action description ' ,
help = ' Optional help text for the users with a description of the target view, such as its usage and purpose. ' ) ,
2010-10-06 14:11:09 +00:00
' display_menu_tip ' : fields . function ( _get_help_status , type = ' boolean ' , method = True , string = ' Display Menu Tips ' ,
help = ' It gives the status if the tip has to be displayed or not when a user executes an action ' )
2008-07-22 14:24:36 +00:00
}
_defaults = {
' type ' : lambda * a : ' ir.actions.act_window ' ,
' view_type ' : lambda * a : ' form ' ,
' view_mode ' : lambda * a : ' tree,form ' ,
' context ' : lambda * a : ' {} ' ,
' limit ' : lambda * a : 80 ,
' target ' : lambda * a : ' current ' ,
' auto_refresh ' : lambda * a : 0 ,
2010-02-19 13:46:56 +00:00
' auto_search ' : lambda * a : True
2008-07-22 14:24:36 +00:00
}
2010-09-27 05:46:42 +00:00
2006-12-07 13:41:40 +00:00
act_window ( )
2007-05-15 13:27:39 +00:00
class act_window_view ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.act_window.view '
_table = ' ir_act_window_view '
_rec_name = ' view_id '
_columns = {
' sequence ' : fields . integer ( ' Sequence ' ) ,
' view_id ' : fields . many2one ( ' ir.ui.view ' , ' View ' ) ,
' view_mode ' : fields . selection ( (
( ' tree ' , ' Tree ' ) ,
( ' form ' , ' Form ' ) ,
( ' graph ' , ' Graph ' ) ,
2008-10-10 12:30:23 +00:00
( ' calendar ' , ' Calendar ' ) ,
2010-04-26 13:38:47 +00:00
( ' gantt ' , ' Gantt ' ) ,
( ' gallery ' , ' Gallery ' ) ) , string = ' View Type ' , required = True ) ,
2008-07-22 14:24:36 +00:00
' act_window_id ' : fields . many2one ( ' ir.actions.act_window ' , ' Action ' , ondelete = ' cascade ' ) ,
2009-01-26 17:40:29 +00:00
' multi ' : fields . boolean ( ' On Multiple Doc. ' ,
help = " If set to true, the action will not be displayed on the right toolbar of a form view. " ) ,
2008-07-22 14:24:36 +00:00
}
_defaults = {
' multi ' : lambda * a : False ,
}
_order = ' sequence '
2007-05-15 13:27:39 +00:00
act_window_view ( )
2006-12-07 13:41:40 +00:00
class act_wizard ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.wizard '
2009-01-26 15:47:04 +00:00
_inherit = ' ir.actions.actions '
2008-07-22 14:24:36 +00:00
_table = ' ir_act_wizard '
_sequence = ' ir_actions_id_seq '
_columns = {
2009-01-26 17:40:29 +00:00
' name ' : fields . char ( ' Wizard Info ' , size = 64 , required = True , translate = True ) ,
' type ' : fields . char ( ' Action Type ' , size = 32 , required = True ) ,
' wiz_name ' : fields . char ( ' Wizard Name ' , size = 64 , required = True ) ,
' multi ' : fields . boolean ( ' Action on Multiple Doc. ' , help = " If set to true, the wizard will not be displayed on the right toolbar of a form view. " ) ,
2008-10-08 14:12:08 +00:00
' groups_id ' : fields . many2many ( ' res.groups ' , ' res_groups_wizard_rel ' , ' uid ' , ' gid ' , ' Groups ' ) ,
' model ' : fields . char ( ' Object ' , size = 64 ) ,
2008-07-22 14:24:36 +00:00
}
_defaults = {
' type ' : lambda * a : ' ir.actions.wizard ' ,
' multi ' : lambda * a : False ,
}
2006-12-07 13:41:40 +00:00
act_wizard ( )
2007-10-25 18:20:12 +00:00
class act_url ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.url '
_table = ' ir_act_url '
_sequence = ' ir_actions_id_seq '
_columns = {
' name ' : fields . char ( ' Action Name ' , size = 64 , translate = True ) ,
' type ' : fields . char ( ' Action Type ' , size = 32 , required = True ) ,
2009-01-26 17:40:29 +00:00
' url ' : fields . text ( ' Action URL ' , required = True ) ,
2008-07-22 14:24:36 +00:00
' target ' : fields . selection ( (
( ' new ' , ' New Window ' ) ,
( ' self ' , ' This Window ' ) ) ,
' Action Target ' , required = True
)
}
_defaults = {
' type ' : lambda * a : ' ir.actions.act_url ' ,
' target ' : lambda * a : ' new '
}
2007-10-25 18:20:12 +00:00
act_url ( )
2008-08-14 06:00:47 +00:00
def model_get ( self , cr , uid , context = { } ) :
wkf_pool = self . pool . get ( ' workflow ' )
ids = wkf_pool . search ( cr , uid , [ ] )
osvs = wkf_pool . read ( cr , uid , ids , [ ' osv ' ] )
2008-09-18 14:02:05 +00:00
2008-08-14 06:00:47 +00:00
res = [ ]
mpool = self . pool . get ( ' ir.model ' )
for osv in osvs :
model = osv . get ( ' osv ' )
id = mpool . search ( cr , uid , [ ( ' model ' , ' = ' , model ) ] )
name = mpool . read ( cr , uid , id ) [ 0 ] [ ' name ' ]
res . append ( ( model , name ) )
2008-09-18 14:02:05 +00:00
2008-08-14 06:00:47 +00:00
return res
2008-08-19 11:23:03 +00:00
2008-08-20 10:21:43 +00:00
class ir_model_fields ( osv . osv ) :
_inherit = ' ir.model.fields '
2008-10-28 23:15:42 +00:00
_rec_name = ' field_description '
2008-08-20 10:21:43 +00:00
_columns = {
2008-12-01 15:13:51 +00:00
' complete_name ' : fields . char ( ' Complete Name ' , size = 64 , select = 1 ) ,
2008-08-20 10:21:43 +00:00
}
ir_model_fields ( )
2008-08-20 11:15:20 +00:00
2008-08-25 10:55:15 +00:00
class server_object_lines ( osv . osv ) :
_name = ' ir.server.object.lines '
_sequence = ' ir_actions_id_seq '
_columns = {
' server_id ' : fields . many2one ( ' ir.actions.server ' , ' Object Mapping ' ) ,
' col1 ' : fields . many2one ( ' ir.model.fields ' , ' Destination ' , required = True ) ,
' value ' : fields . text ( ' Value ' , required = True ) ,
' type ' : fields . selection ( [
( ' value ' , ' Value ' ) ,
( ' equation ' , ' Formula ' )
] , ' Type ' , required = True , size = 32 , change_default = True ) ,
}
_defaults = {
' type ' : lambda * a : ' equation ' ,
}
server_object_lines ( )
2008-08-19 12:30:13 +00:00
##
2008-06-15 00:25:47 +00:00
# Actions that are run on the server side
#
class actions_server ( osv . osv ) :
2008-12-19 05:37:16 +00:00
2008-12-12 06:48:19 +00:00
def _select_signals ( self , cr , uid , context = { } ) :
2010-03-12 07:30:53 +00:00
cr . execute ( " SELECT distinct w.osv, t.signal FROM wkf w, wkf_activity a, wkf_transition t \
WHERE w . id = a . wkf_id AND t . act_from = a . id OR t . act_to = a . id AND t . signal != ' ' \
2010-06-18 14:05:37 +00:00
AND t . signal NOT IN ( null , NULL ) " )
2008-12-15 13:49:12 +00:00
result = cr . fetchall ( ) or [ ]
res = [ ]
for rs in result :
2009-12-02 18:20:21 +00:00
if rs [ 0 ] is not None and rs [ 1 ] is not None :
2010-03-11 14:12:46 +00:00
line = rs [ 0 ] , " %s - ( %s ) " % ( rs [ 1 ] , rs [ 0 ] )
res . append ( line )
2008-12-15 13:49:12 +00:00
return res
2010-04-21 08:53:38 +00:00
2010-03-11 14:12:46 +00:00
def _select_objects ( self , cr , uid , context = { } ) :
model_pool = self . pool . get ( ' ir.model ' )
ids = model_pool . search ( cr , uid , [ ( ' name ' , ' not ilike ' , ' . ' ) ] )
res = model_pool . read ( cr , uid , ids , [ ' model ' , ' name ' ] )
return [ ( r [ ' model ' ] , r [ ' name ' ] ) for r in res ] + [ ( ' ' , ' ' ) ]
2010-04-21 08:53:38 +00:00
2010-03-11 14:12:46 +00:00
def change_object ( self , cr , uid , ids , copy_object , state , context = { } ) :
if state == ' object_copy ' :
model_pool = self . pool . get ( ' ir.model ' )
model = copy_object . split ( ' , ' ) [ 0 ]
mid = model_pool . search ( cr , uid , [ ( ' model ' , ' = ' , model ) ] )
return {
' value ' : { ' srcmodel_id ' : mid [ 0 ] } ,
' context ' : context
}
else :
return { }
2008-12-19 05:37:16 +00:00
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.server '
_table = ' ir_act_server '
_sequence = ' ir_actions_id_seq '
2008-12-18 06:31:14 +00:00
_order = ' sequence '
2008-07-22 14:24:36 +00:00
_columns = {
2009-07-01 07:31:09 +00:00
' name ' : fields . char ( ' Action Name ' , required = True , size = 64 , help = " Easy to Refer action by name e.g. One Sales Order -> Many Invoices " , translate = True ) ,
2009-01-26 17:40:29 +00:00
' condition ' : fields . char ( ' Condition ' , size = 256 , required = True , help = " Condition that is to be tested before action is executed, e.g. object.list_price > object.cost_price " ) ,
2008-07-22 14:24:36 +00:00
' state ' : fields . selection ( [
2008-12-04 23:58:43 +00:00
( ' client_action ' , ' Client Action ' ) ,
2008-07-22 14:24:36 +00:00
( ' dummy ' , ' Dummy ' ) ,
2008-12-17 11:40:21 +00:00
( ' loop ' , ' Iteration ' ) ,
2008-12-16 10:18:09 +00:00
( ' code ' , ' Python Code ' ) ,
2008-07-22 14:24:36 +00:00
( ' trigger ' , ' Trigger ' ) ,
( ' email ' , ' Email ' ) ,
( ' sms ' , ' SMS ' ) ,
( ' object_create ' , ' Create Object ' ) ,
2010-03-11 14:12:46 +00:00
( ' object_copy ' , ' Copy Object ' ) ,
2008-07-22 14:24:36 +00:00
( ' object_write ' , ' Write Object ' ) ,
2008-12-13 06:30:50 +00:00
( ' other ' , ' Multi Actions ' ) ,
2009-01-26 17:40:29 +00:00
] , ' Action Type ' , required = True , size = 32 , help = " Type of the Action that is to be executed " ) ,
' code ' : fields . text ( ' Python Code ' , help = " Python code to be executed " ) ,
' sequence ' : fields . integer ( ' Sequence ' , help = " Important when you deal with multiple actions, the execution order will be decided based on this, low number is higher priority. " ) ,
2009-01-28 20:33:13 +00:00
' model_id ' : fields . many2one ( ' ir.model ' , ' Object ' , required = True , help = " Select the object on which the action will work (read, write, create). " ) ,
2009-01-26 17:40:29 +00:00
' action_id ' : fields . many2one ( ' ir.actions.actions ' , ' Client Action ' , help = " Select the Action Window, Report, Wizard to be executed. " ) ,
' trigger_name ' : fields . selection ( _select_signals , string = ' Trigger Name ' , size = 128 , help = " Select the Signal name that is to be used as the trigger. " ) ,
' wkf_model_id ' : fields . many2one ( ' ir.model ' , ' Workflow On ' , help = " Workflow to be executed on this model. " ) ,
' trigger_obj_id ' : fields . many2one ( ' ir.model.fields ' , ' Trigger On ' , help = " Select the object from the model on which the workflow will executed. " ) ,
' email ' : fields . char ( ' Email Address ' , size = 512 , help = " Provides the fields that will be used to fetch the email address, e.g. when you select the invoice, then `object.invoice_address_id.email` is the field which gives the correct address " ) ,
' subject ' : fields . char ( ' Subject ' , size = 1024 , translate = True , help = " Specify the subject. You can use fields from the object, e.g. `Hello [[ object.partner_id.name ]]` " ) ,
' message ' : fields . text ( ' Message ' , translate = True , help = " Specify the message. You can use the fields from the object. e.g. `Dear [[ object.partner_id.name ]]` " ) ,
' mobile ' : fields . char ( ' Mobile No ' , size = 512 , help = " Provides fields that be used to fetch the mobile number, e.g. you select the invoice, then `object.invoice_address_id.mobile` is the field which gives the correct mobile number " ) ,
2008-09-10 12:55:55 +00:00
' sms ' : fields . char ( ' SMS ' , size = 160 , translate = True ) ,
2009-01-26 17:40:29 +00:00
' child_ids ' : fields . many2many ( ' ir.actions.server ' , ' rel_server_actions ' , ' server_id ' , ' action_id ' , ' Other Actions ' ) ,
2008-07-22 14:24:36 +00:00
' usage ' : fields . char ( ' Action Usage ' , size = 32 ) ,
2008-12-13 06:30:50 +00:00
' type ' : fields . char ( ' Action Type ' , size = 32 , required = True ) ,
2009-01-26 17:40:29 +00:00
' srcmodel_id ' : fields . many2one ( ' ir.model ' , ' Model ' , help = " Object in which you want to create / write the object. If it is empty then refer to the Object field. " ) ,
' fields_lines ' : fields . one2many ( ' ir.server.object.lines ' , ' server_id ' , ' Field Mappings. ' ) ,
' record_id ' : fields . many2one ( ' ir.model.fields ' , ' Create Id ' , help = " Provide the field name where the record id is stored after the create operations. If it is empty, you can not track the new record. " ) ,
' write_id ' : fields . char ( ' Write Id ' , size = 256 , help = " Provide the field name that the record id refers to for the write operation. If it is empty it will refer to the active id of the object. " ) ,
' loop_action ' : fields . many2one ( ' ir.actions.server ' , ' Loop Action ' , help = " Select the action that will be executed. Loop action will not be avaliable inside loop. " ) ,
' expression ' : fields . char ( ' Loop Expression ' , size = 512 , help = " Enter the field/expression that will return the list. E.g. select the sale order in Object, and you can have loop on the sales order line. Expression = `object.order_line`. " ) ,
2010-03-11 14:12:46 +00:00
' copy_object ' : fields . reference ( ' Copy Of ' , selection = _select_objects , size = 256 ) ,
2008-07-22 14:24:36 +00:00
}
_defaults = {
' state ' : lambda * a : ' dummy ' ,
2008-12-16 19:26:08 +00:00
' condition ' : lambda * a : ' True ' ,
2008-07-22 14:24:36 +00:00
' type ' : lambda * a : ' ir.actions.server ' ,
2008-12-15 13:49:12 +00:00
' sequence ' : lambda * a : 5 ,
2008-12-16 10:18:09 +00:00
' code ' : lambda * a : """ # You can use the following variables
2010-05-12 11:41:25 +00:00
# - object or obj
2008-12-16 10:18:09 +00:00
# - time
# - cr
# - uid
# - ids
# If you plan to return an action, assign: action = {...}
""" ,
2008-07-22 14:24:36 +00:00
}
2008-09-18 14:02:05 +00:00
2008-12-11 11:32:08 +00:00
def get_email ( self , cr , uid , action , context ) :
2008-12-13 12:42:04 +00:00
logger = netsvc . Logger ( )
2008-08-21 09:04:40 +00:00
obj_pool = self . pool . get ( action . model_id . model )
id = context . get ( ' active_id ' )
obj = obj_pool . browse ( cr , uid , id )
2008-09-18 14:02:05 +00:00
2008-08-21 10:36:17 +00:00
fields = None
2008-09-18 14:02:05 +00:00
2008-12-11 11:32:08 +00:00
if ' / ' in action . email . complete_name :
fields = action . email . complete_name . split ( ' / ' )
elif ' . ' in action . email . complete_name :
fields = action . email . complete_name . split ( ' . ' )
for field in fields :
try :
obj = getattr ( obj , field )
except Exception , e :
2008-12-13 12:42:04 +00:00
logger . notifyChannel ( ' Workflow ' , netsvc . LOG_ERROR , ' Failed to parse : %s ' % ( field ) )
2008-12-11 11:32:08 +00:00
return obj
def get_mobile ( self , cr , uid , action , context ) :
2008-12-13 12:42:04 +00:00
logger = netsvc . Logger ( )
2008-12-11 11:32:08 +00:00
obj_pool = self . pool . get ( action . model_id . model )
id = context . get ( ' active_id ' )
obj = obj_pool . browse ( cr , uid , id )
fields = None
if ' / ' in action . mobile . complete_name :
fields = action . mobile . complete_name . split ( ' / ' )
elif ' . ' in action . mobile . complete_name :
fields = action . mobile . complete_name . split ( ' . ' )
2008-09-18 14:02:05 +00:00
2008-08-21 09:04:40 +00:00
for field in fields :
2008-08-21 10:36:17 +00:00
try :
obj = getattr ( obj , field )
except Exception , e :
2008-12-13 12:42:04 +00:00
logger . notifyChannel ( ' Workflow ' , netsvc . LOG_ERROR , ' Failed to parse : %s ' % ( field ) )
2008-09-18 14:02:05 +00:00
2008-08-21 09:04:40 +00:00
return obj
2008-08-14 06:00:47 +00:00
2010-09-21 13:14:37 +00:00
def merge_message ( self , cr , uid , keystr , action , context = None ) :
if context is None :
context = { }
2008-08-21 10:36:17 +00:00
logger = netsvc . Logger ( )
def merge ( match ) :
obj_pool = self . pool . get ( action . model_id . model )
id = context . get ( ' active_id ' )
obj = obj_pool . browse ( cr , uid , id )
2008-12-11 11:32:08 +00:00
exp = str ( match . group ( ) [ 2 : - 2 ] ) . strip ( )
2010-09-21 13:14:37 +00:00
result = eval ( exp ,
{
' object ' : obj ,
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
' time ' : time ,
} )
2008-12-13 12:42:04 +00:00
if result in ( None , False ) :
return str ( " -------- " )
2010-01-27 14:42:27 +00:00
return tools . ustr ( result )
2009-10-30 12:33:59 +00:00
2008-11-26 23:52:20 +00:00
com = re . compile ( ' ( \ [ \ [.+? \ ] \ ]) ' )
2008-08-25 13:11:10 +00:00
message = com . sub ( merge , keystr )
2009-10-30 12:33:59 +00:00
2008-08-21 10:36:17 +00:00
return message
2008-09-18 14:02:05 +00:00
2008-07-22 14:24:36 +00:00
# Context should contains:
# ids : original ids
# id : current id of the object
# OUT:
# False : Finnished correctly
# ACTION_ID : Action to launch
2009-10-30 12:33:59 +00:00
2010-09-21 13:14:37 +00:00
# FIXME: refactor all the eval() calls in run()!
def run ( self , cr , uid , ids , context = None ) :
2008-07-23 16:33:28 +00:00
logger = netsvc . Logger ( )
2010-09-21 13:14:37 +00:00
if context is None :
context = { }
2008-07-22 14:24:36 +00:00
for action in self . browse ( cr , uid , ids , context ) :
2008-12-16 19:26:08 +00:00
obj_pool = self . pool . get ( action . model_id . model )
obj = obj_pool . browse ( cr , uid , context [ ' active_id ' ] , context = context )
cxt = {
2010-09-21 13:14:37 +00:00
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
2009-10-30 12:33:59 +00:00
' object ' : obj ,
2008-12-16 19:26:08 +00:00
' time ' : time ,
' cr ' : cr ,
' pool ' : self . pool ,
' uid ' : uid
}
expr = eval ( str ( action . condition ) , cxt )
if not expr :
continue
2009-10-30 12:33:59 +00:00
2008-12-04 23:58:43 +00:00
if action . state == ' client_action ' :
if not action . action_id :
2009-10-30 12:33:59 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( " Please specify an action to launch ! " ) )
2009-12-02 18:20:21 +00:00
return self . pool . get ( action . action_id . type ) \
. read ( cr , uid , action . action_id . id , context = context )
2008-12-16 19:26:08 +00:00
2010-06-25 09:22:56 +00:00
if action . state == ' code ' :
2010-09-21 13:14:37 +00:00
localdict = {
' self ' : self . pool . get ( action . model_id . model ) ,
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
' time ' : time ,
' ids ' : ids ,
' cr ' : cr ,
' uid ' : uid ,
' object ' : obj ,
' obj ' : obj ,
}
eval ( action . code , localdict , mode = " exec " , nocopy = True ) # nocopy allows to return 'action'
if ' action ' in localdict :
return localdict [ ' action ' ]
2008-09-18 14:02:05 +00:00
2008-07-23 16:33:28 +00:00
if action . state == ' email ' :
2008-07-29 07:28:04 +00:00
user = config [ ' email_from ' ]
2008-12-17 11:40:21 +00:00
address = str ( action . email )
try :
address = eval ( str ( action . email ) , cxt )
except :
pass
2009-10-30 12:33:59 +00:00
2008-10-22 11:25:13 +00:00
if not address :
2009-09-17 07:27:12 +00:00
logger . notifyChannel ( ' email ' , netsvc . LOG_INFO , ' Partner Email address not Specified! ' )
continue
2008-12-11 11:32:08 +00:00
if not user :
2010-05-11 07:30:51 +00:00
raise osv . except_osv ( _ ( ' Error ' ) , _ ( " Please specify server option --email-from ! " ) )
2010-04-21 08:53:38 +00:00
2010-01-18 15:28:03 +00:00
subject = self . merge_message ( cr , uid , action . subject , action , context )
body = self . merge_message ( cr , uid , action . message , action , context )
2010-04-21 08:53:38 +00:00
2008-12-13 12:42:04 +00:00
if tools . email_send ( user , [ address ] , subject , body , debug = False , subtype = ' html ' ) == True :
2008-08-20 11:15:20 +00:00
logger . notifyChannel ( ' email ' , netsvc . LOG_INFO , ' Email successfully send to : %s ' % ( address ) )
2008-07-23 16:33:28 +00:00
else :
2008-08-20 11:15:20 +00:00
logger . notifyChannel ( ' email ' , netsvc . LOG_ERROR , ' Failed to send email to : %s ' % ( address ) )
2008-08-14 08:40:46 +00:00
2008-08-14 06:00:47 +00:00
if action . state == ' trigger ' :
2008-08-14 08:40:46 +00:00
wf_service = netsvc . LocalService ( " workflow " )
2008-12-12 11:48:54 +00:00
model = action . wkf_model_id . model
2008-12-12 06:48:19 +00:00
obj_pool = self . pool . get ( action . model_id . model )
res_id = self . pool . get ( action . model_id . model ) . read ( cr , uid , [ context . get ( ' active_id ' ) ] , [ action . trigger_obj_id . name ] )
id = res_id [ 0 ] [ action . trigger_obj_id . name ]
2008-08-14 08:40:46 +00:00
wf_service . trg_validate ( uid , model , int ( id ) , action . trigger_name , cr )
2008-09-18 14:02:05 +00:00
2008-08-06 09:01:54 +00:00
if action . state == ' sms ' :
2008-09-10 07:16:19 +00:00
#TODO: set the user and password from the system
# for the sms gateway user / password
2010-02-10 11:06:47 +00:00
# USE smsclient module from extra-addons
logger . notifyChannel ( ' sms ' , netsvc . LOG_ERROR , ' SMS Facility has not been implemented yet. Use smsclient module! ' )
2009-10-30 12:33:59 +00:00
2008-08-14 06:00:47 +00:00
if action . state == ' other ' :
2008-12-16 19:26:08 +00:00
res = [ ]
2008-08-14 08:40:46 +00:00
for act in action . child_ids :
2008-12-18 05:22:28 +00:00
context [ ' active_id ' ] = context [ ' active_ids ' ] [ 0 ]
2008-12-12 11:48:54 +00:00
result = self . run ( cr , uid , [ act . id ] , context )
if result :
2008-12-16 19:26:08 +00:00
res . append ( result )
2009-10-30 12:33:59 +00:00
2008-12-12 11:48:54 +00:00
return res
2009-10-30 12:33:59 +00:00
2008-12-17 11:40:21 +00:00
if action . state == ' loop ' :
obj_pool = self . pool . get ( action . model_id . model )
obj = obj_pool . browse ( cr , uid , context [ ' active_id ' ] , context = context )
cxt = {
2010-09-21 13:14:37 +00:00
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
2009-10-30 12:33:59 +00:00
' object ' : obj ,
2010-09-21 13:14:37 +00:00
' time ' : time ,
2008-12-17 11:40:21 +00:00
' cr ' : cr ,
' pool ' : self . pool ,
' uid ' : uid
}
expr = eval ( str ( action . expression ) , cxt )
context [ ' object ' ] = obj
for i in expr :
context [ ' active_id ' ] = i . id
result = self . run ( cr , uid , [ action . loop_action . id ] , context )
2009-10-30 12:33:59 +00:00
2008-08-25 13:11:10 +00:00
if action . state == ' object_write ' :
res = { }
for exp in action . fields_lines :
euq = exp . value
if exp . type == ' equation ' :
2008-11-26 23:52:20 +00:00
obj_pool = self . pool . get ( action . model_id . model )
obj = obj_pool . browse ( cr , uid , context [ ' active_id ' ] , context = context )
2010-09-21 13:14:37 +00:00
cxt = {
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
' object ' : obj ,
' time ' : time ,
}
2008-12-17 11:40:21 +00:00
expr = eval ( euq , cxt )
2008-08-25 13:11:10 +00:00
else :
expr = exp . value
res [ exp . col1 . name ] = expr
2008-09-18 14:02:05 +00:00
2008-12-17 11:40:21 +00:00
if not action . write_id :
2008-12-12 05:07:38 +00:00
if not action . srcmodel_id :
obj_pool = self . pool . get ( action . model_id . model )
obj_pool . write ( cr , uid , [ context . get ( ' active_id ' ) ] , res )
else :
2008-12-17 11:40:21 +00:00
write_id = context . get ( ' active_id ' )
2008-12-12 05:07:38 +00:00
obj_pool = self . pool . get ( action . srcmodel_id . model )
2008-12-17 11:40:21 +00:00
obj_pool . write ( cr , uid , [ write_id ] , res )
2009-10-30 12:33:59 +00:00
2008-12-17 11:40:21 +00:00
elif action . write_id :
2008-12-11 15:01:47 +00:00
obj_pool = self . pool . get ( action . srcmodel_id . model )
2008-12-17 11:40:21 +00:00
rec = self . pool . get ( action . model_id . model ) . browse ( cr , uid , context . get ( ' active_id ' ) )
id = eval ( action . write_id , { ' object ' : rec } )
2008-12-18 06:31:14 +00:00
try :
id = int ( id )
except :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( " Problem in configuration `Record Id` in Server Action! " ) )
2009-10-30 12:33:59 +00:00
2008-12-17 11:40:21 +00:00
if type ( id ) != type ( 1 ) :
raise osv . except_osv ( _ ( ' Error ' ) , _ ( " Problem in configuration `Record Id` in Server Action! " ) )
write_id = id
2008-12-16 19:26:08 +00:00
obj_pool . write ( cr , uid , [ write_id ] , res )
2008-12-17 11:40:21 +00:00
2008-08-25 13:11:10 +00:00
if action . state == ' object_create ' :
2008-08-26 08:51:10 +00:00
res = { }
for exp in action . fields_lines :
euq = exp . value
if exp . type == ' equation ' :
2008-11-26 23:52:20 +00:00
obj_pool = self . pool . get ( action . model_id . model )
obj = obj_pool . browse ( cr , uid , context [ ' active_id ' ] , context = context )
2010-09-21 13:14:37 +00:00
expr = eval ( euq ,
{
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
' object ' : obj ,
' time ' : time ,
} )
2008-08-26 08:51:10 +00:00
else :
expr = exp . value
res [ exp . col1 . name ] = expr
2008-09-18 14:02:05 +00:00
2008-09-01 11:48:01 +00:00
obj_pool = None
2008-12-11 15:01:47 +00:00
res_id = False
obj_pool = self . pool . get ( action . srcmodel_id . model )
res_id = obj_pool . create ( cr , uid , res )
2008-12-16 19:26:08 +00:00
if action . record_id :
self . pool . get ( action . model_id . model ) . write ( cr , uid , [ context . get ( ' active_id ' ) ] , { action . record_id . name : res_id } )
2010-04-21 08:53:38 +00:00
2010-03-11 14:12:46 +00:00
if action . state == ' object_copy ' :
res = { }
for exp in action . fields_lines :
euq = exp . value
if exp . type == ' equation ' :
obj_pool = self . pool . get ( action . model_id . model )
obj = obj_pool . browse ( cr , uid , context [ ' active_id ' ] , context = context )
2010-09-21 13:14:37 +00:00
expr = eval ( euq ,
{
' context ' : dict ( context ) , # copy context to prevent side-effects of eval
' object ' : obj ,
' time ' : time ,
} )
2010-03-11 14:12:46 +00:00
else :
expr = exp . value
res [ exp . col1 . name ] = expr
obj_pool = None
res_id = False
2010-04-21 08:53:38 +00:00
2010-03-11 14:12:46 +00:00
model = action . copy_object . split ( ' , ' ) [ 0 ]
cid = action . copy_object . split ( ' , ' ) [ 1 ]
obj_pool = self . pool . get ( model )
res_id = obj_pool . copy ( cr , uid , int ( cid ) , res )
2008-09-18 14:02:05 +00:00
2008-07-22 14:24:36 +00:00
return False
2008-12-17 11:40:21 +00:00
2008-06-15 00:25:47 +00:00
actions_server ( )
2008-06-15 14:59:23 +00:00
class act_window_close ( osv . osv ) :
2008-07-22 14:24:36 +00:00
_name = ' ir.actions.act_window_close '
2009-01-26 15:47:04 +00:00
_inherit = ' ir.actions.actions '
2008-07-22 14:24:36 +00:00
_table = ' ir_actions '
_defaults = {
' type ' : lambda * a : ' ir.actions.act_window_close ' ,
}
2008-06-15 14:59:23 +00:00
act_window_close ( )
2008-09-29 08:49:06 +00:00
# This model use to register action services.
2010-04-18 20:07:32 +00:00
TODO_STATES = [ ( ' open ' , ' To Do ' ) ,
2009-12-07 10:17:40 +00:00
( ' done ' , ' Done ' ) ,
( ' skip ' , ' Skipped ' ) ,
2010-09-23 10:54:10 +00:00
( ' cancel ' , ' Cancelled ' ) ]
2010-04-18 20:07:32 +00:00
2008-09-29 08:49:06 +00:00
class ir_actions_todo ( osv . osv ) :
2009-10-30 12:33:59 +00:00
_name = ' ir.actions.todo '
2008-09-29 08:49:06 +00:00
_columns = {
2009-12-07 10:17:40 +00:00
' action_id ' : fields . many2one (
' ir.actions.act_window ' , ' Action ' , select = True , required = True ,
ondelete = ' cascade ' ) ,
' sequence ' : fields . integer ( ' Sequence ' ) ,
2009-12-16 15:59:41 +00:00
' state ' : fields . selection ( TODO_STATES , string = ' State ' , required = True ) ,
' name ' : fields . char ( ' Name ' , size = 64 ) ,
2010-04-18 20:07:32 +00:00
' restart ' : fields . selection ( [ ( ' onskip ' , ' On Skip ' ) , ( ' always ' , ' Always ' ) , ( ' never ' , ' Never ' ) ] , ' Restart ' , required = True ) ,
2010-04-28 06:54:06 +00:00
' groups_id ' : fields . many2many ( ' res.groups ' , ' res_groups_action_rel ' , ' uid ' , ' gid ' , ' Groups ' ) ,
2009-12-16 15:59:41 +00:00
' note ' : fields . text ( ' Text ' , translate = True ) ,
2008-09-29 08:49:06 +00:00
}
_defaults = {
2010-09-23 10:53:45 +00:00
' state ' : ' open ' ,
' sequence ' : 10 ,
' restart ' : ' onskip ' ,
2008-09-29 08:49:06 +00:00
}
2010-04-18 20:07:32 +00:00
_order = " sequence,id "
2010-08-23 06:43:09 +00:00
2010-08-30 13:04:48 +00:00
def action_launch ( self , cr , uid , ids , context = None ) :
""" Launch Action of Wizard """
if context is None :
context = { }
wizard_id = ids and ids [ 0 ] or False
wizard = self . browse ( cr , uid , wizard_id , context = context )
res = self . pool . get ( ' ir.actions.act_window ' ) . read ( cr , uid , wizard . action_id . id , [ ' name ' , ' view_type ' , ' view_mode ' , ' res_model ' , ' context ' , ' views ' , ' type ' ] , context = context )
res . update ( { ' target ' : ' new ' , ' nodestroy ' : True } )
return res
2010-08-23 06:43:09 +00:00
def action_open ( self , cr , uid , ids , context = None ) :
""" Sets configuration wizard in TODO state """
return self . write ( cr , uid , ids , { ' state ' : ' open ' } , context = context )
2008-09-29 08:49:06 +00:00
ir_actions_todo ( )
2008-10-08 14:12:08 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: