[MERGE] forward port of branch saas-3 up to revid 5112 chs@openerp.com-20140407144238...
[odoo/odoo.git] / openerp / addons / base / ir / ir_actions.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2014 OpenERP S.A. <http://www.openerp.com>
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from functools import partial
23 import logging
24 import operator
25 import os
26 import time
27 import datetime
28 import dateutil
29
30 import openerp
31 from openerp import SUPERUSER_ID
32 from openerp import tools
33 from openerp import workflow
34 from openerp.osv import fields, osv
35 from openerp.osv.orm import browse_record
36 import openerp.report.interface
37 from openerp.report.report_sxw import report_sxw, report_rml
38 from openerp.tools.safe_eval import safe_eval as eval
39 from openerp.tools.translate import _
40 import openerp.workflow
41
42 _logger = logging.getLogger(__name__)
43
44 class actions(osv.osv):
45     _name = 'ir.actions.actions'
46     _table = 'ir_actions'
47     _order = 'name'
48     _columns = {
49         'name': fields.char('Name', size=64, required=True),
50         'type': fields.char('Action Type', required=True, size=32),
51         'usage': fields.char('Action Usage', size=32),
52         'help': fields.text('Action description',
53             help='Optional help text for the users with a description of the target view, such as its usage and purpose.',
54             translate=True),
55     }
56     _defaults = {
57         'usage': lambda *a: False,
58     }
59
60
61 class ir_actions_report_xml(osv.osv):
62
63     def _report_content(self, cursor, user, ids, name, arg, context=None):
64         res = {}
65         for report in self.browse(cursor, user, ids, context=context):
66             data = report[name + '_data']
67             if not data and report[name[:-8]]:
68                 fp = None
69                 try:
70                     fp = tools.file_open(report[name[:-8]], mode='rb')
71                     data = fp.read()
72                 except:
73                     data = False
74                 finally:
75                     if fp:
76                         fp.close()
77             res[report.id] = data
78         return res
79
80     def _report_content_inv(self, cursor, user, id, name, value, arg, context=None):
81         self.write(cursor, user, id, {name+'_data': value}, context=context)
82
83     def _report_sxw(self, cursor, user, ids, name, arg, context=None):
84         res = {}
85         for report in self.browse(cursor, user, ids, context=context):
86             if report.report_rml:
87                 res[report.id] = report.report_rml.replace('.rml', '.sxw')
88             else:
89                 res[report.id] = False
90         return res
91
92     def _lookup_report(self, cr, name):
93         """
94         Look up a report definition.
95         """
96         opj = os.path.join
97
98         # First lookup in the deprecated place, because if the report definition
99         # has not been updated, it is more likely the correct definition is there.
100         # Only reports with custom parser sepcified in Python are still there.
101         if 'report.' + name in openerp.report.interface.report_int._reports:
102             new_report = openerp.report.interface.report_int._reports['report.' + name]
103         else:
104             cr.execute("SELECT * FROM ir_act_report_xml WHERE report_name=%s", (name,))
105             r = cr.dictfetchone()
106             if r:
107                 if r['report_rml'] or r['report_rml_content_data']:
108                     if r['parser']:
109                         kwargs = { 'parser': operator.attrgetter(r['parser'])(openerp.addons) }
110                     else:
111                         kwargs = {}
112                     new_report = report_sxw('report.'+r['report_name'], r['model'],
113                             opj('addons',r['report_rml'] or '/'), header=r['header'], register=False, **kwargs)
114                 elif r['report_xsl'] and r['report_xml']:
115                     new_report = report_rml('report.'+r['report_name'], r['model'],
116                             opj('addons',r['report_xml']),
117                             r['report_xsl'] and opj('addons',r['report_xsl']), register=False)
118                 else:
119                     raise Exception, "Unhandled report type: %s" % r
120             else:
121                 raise Exception, "Required report does not exist: %s" % r
122
123         return new_report
124
125     def render_report(self, cr, uid, res_ids, name, data, context=None):
126         """
127         Look up a report definition and render the report for the provided IDs.
128         """
129         new_report = self._lookup_report(cr, name)
130         return new_report.create(cr, uid, res_ids, data, context)
131
132     _name = 'ir.actions.report.xml'
133     _inherit = 'ir.actions.actions'
134     _table = 'ir_act_report_xml'
135     _sequence = 'ir_actions_id_seq'
136     _order = 'name'
137     _columns = {
138         'type': fields.char('Action Type', size=32, required=True),
139         'name': fields.char('Name', size=64, required=True, translate=True),
140
141         'model': fields.char('Model', required=True),
142         'report_type': fields.selection([('qweb-pdf', 'PDF'),
143                     ('qweb-html', 'HTML'),
144                     ('controller', 'Controller'),
145                     ('pdf', 'RML pdf (deprecated)'),
146                     ('sxw', 'RML sxw (deprecated)'),
147                     ('webkit', 'Webkit (deprecated)'),
148                     ], 'Report Type', required=True, help="HTML will open the report directly in your browser, PDF will use wkhtmltopdf to render the HTML into a PDF file and let you download it, Controller allows you to define the url of a custom controller outputting any kind of report."),
149         'report_name': fields.char('Template Name', required=True, help="For QWeb reports, name of the template used in the rendering. The method 'render_html' of the model 'report.template_name' will be called (if any) to give the html. For RML reports, this is the LocalService name."),
150         'groups_id': fields.many2many('res.groups', 'res_groups_report_rel', 'uid', 'gid', 'Groups'),
151
152         # options
153         '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."),
154         '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.'),
155         '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.'),
156
157         # Deprecated rml stuff
158         'usage': fields.char('Action Usage', size=32),
159         'header': fields.boolean('Add RML Header', help="Add or not the corporate RML header"),
160         'parser': fields.char('Parser Class'),
161         'auto': fields.boolean('Custom Python Parser'),
162
163         'report_xsl': fields.char('XSL Path'),
164         'report_xml': fields.char('XML Path'),
165
166         'report_rml': fields.char('Main Report File Path/controller', help="The path to the main report file/controller (depending on Report Type) or NULL if the content is in another data field"),
167         'report_file': fields.related('report_rml', type="char", 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),
168
169         'report_sxw': fields.function(_report_sxw, type='char', string='SXW Path'),
170         'report_sxw_content_data': fields.binary('SXW Content'),
171         'report_rml_content_data': fields.binary('RML Content'),
172         'report_sxw_content': fields.function(_report_content, fnct_inv=_report_content_inv, type='binary', string='SXW Content',),
173         'report_rml_content': fields.function(_report_content, fnct_inv=_report_content_inv, type='binary', string='RML Content'),
174     }
175     _defaults = {
176         'type': 'ir.actions.report.xml',
177         'multi': False,
178         'auto': True,
179         'header': True,
180         'report_sxw_content': False,
181         'report_type': 'pdf',
182         'attachment': False,
183     }
184
185
186 class ir_actions_act_window(osv.osv):
187     _name = 'ir.actions.act_window'
188     _table = 'ir_act_window'
189     _inherit = 'ir.actions.actions'
190     _sequence = 'ir_actions_id_seq'
191     _order = 'name'
192
193     def _check_model(self, cr, uid, ids, context=None):
194         for action in self.browse(cr, uid, ids, context):
195             if action.res_model not in self.pool:
196                 return False
197             if action.src_model and action.src_model not in self.pool:
198                 return False
199         return True
200
201     def _invalid_model_msg(self, cr, uid, ids, context=None):
202         return _('Invalid model name in the action definition.')
203
204     _constraints = [
205         (_check_model, _invalid_model_msg, ['res_model','src_model'])
206     ]
207
208     def _views_get_fnc(self, cr, uid, ids, name, arg, context=None):
209         """Returns an ordered list of the specific view modes that should be
210            enabled when displaying the result of this action, along with the
211            ID of the specific view to use for each mode, if any were required.
212
213            This function hides the logic of determining the precedence between
214            the view_modes string, the view_ids o2m, and the view_id m2o that can
215            be set on the action.
216
217            :rtype: dict in the form { action_id: list of pairs (tuples) }
218            :return: { action_id: [(view_id, view_mode), ...], ... }, where view_mode
219                     is one of the possible values for ir.ui.view.type and view_id
220                     is the ID of a specific view to use for this mode, or False for
221                     the default one.
222         """
223         res = {}
224         for act in self.browse(cr, uid, ids):
225             res[act.id] = [(view.view_id.id, view.view_mode) for view in act.view_ids]
226             view_ids_modes = [view.view_mode for view in act.view_ids]
227             modes = act.view_mode.split(',')
228             missing_modes = [mode for mode in modes if mode not in view_ids_modes]
229             if missing_modes:
230                 if act.view_id and act.view_id.type in missing_modes:
231                     # reorder missing modes to put view_id first if present
232                     missing_modes.remove(act.view_id.type)
233                     res[act.id].append((act.view_id.id, act.view_id.type))
234                 res[act.id].extend([(False, mode) for mode in missing_modes])
235         return res
236
237     def _search_view(self, cr, uid, ids, name, arg, context=None):
238         res = {}
239         for act in self.browse(cr, uid, ids, context=context):
240             field_get = self.pool[act.res_model].fields_view_get(cr, uid,
241                 act.search_view_id and act.search_view_id.id or False,
242                 'search', context=context)
243             res[act.id] = str(field_get)
244         return res
245
246     _columns = {
247         'name': fields.char('Action Name', size=64, translate=True),
248         'type': fields.char('Action Type', size=32, required=True),
249         'view_id': fields.many2one('ir.ui.view', 'View Ref.', ondelete='cascade'),
250         'domain': fields.char('Domain Value',
251             help="Optional domain filtering of the destination data, as a Python expression"),
252         'context': fields.char('Context Value', required=True,
253             help="Context dictionary as Python expression, empty by default (Default: {})"),
254         'res_id': fields.integer('Record ID', help="Database ID of record to open in form view, when ``view_mode`` is set to 'form' only"),
255         'res_model': fields.char('Destination Model', size=64, required=True,
256             help="Model name of the object to open in the view window"),
257         'src_model': fields.char('Source Model', size=64,
258             help="Optional model name of the objects on which this action should be visible"),
259         'target': fields.selection([('current','Current Window'),('new','New Window'),('inline','Inline Edit'),('inlineview','Inline View')], 'Target Window'),
260         'view_mode': fields.char('View Mode', size=250, required=True,
261             help="Comma-separated list of allowed view modes, such as 'form', 'tree', 'calendar', etc. (Default: tree,form)"),
262         'view_type': fields.selection((('tree','Tree'),('form','Form')), string='View Type', required=True,
263             help="View type: Tree type to use for the tree view, set to 'tree' for a hierarchical tree view, or 'form' for a regular list view"),
264         'usage': fields.char('Action Usage', size=32,
265             help="Used to filter menu and home actions from the user form."),
266         'view_ids': fields.one2many('ir.actions.act_window.view', 'act_window_id', 'Views'),
267         'views': fields.function(_views_get_fnc, type='binary', string='Views',
268                help="This function field computes the ordered list of views that should be enabled " \
269                     "when displaying the result of an action, federating view mode, views and " \
270                     "reference view. The result is returned as an ordered list of pairs (view_id,view_mode)."),
271         'limit': fields.integer('Limit', help='Default limit for the list view'),
272         'auto_refresh': fields.integer('Auto-Refresh',
273             help='Add an auto-refresh on the view'),
274         'groups_id': fields.many2many('res.groups', 'ir_act_window_group_rel',
275             'act_id', 'gid', 'Groups'),
276         'search_view_id': fields.many2one('ir.ui.view', 'Search View Ref.'),
277         'filter': fields.boolean('Filter'),
278         'auto_search':fields.boolean('Auto Search'),
279         'search_view' : fields.function(_search_view, type='text', string='Search View'),
280         'multi': fields.boolean('Restrict to lists', help="If checked and the action is bound to a model, it will only appear in the More menu on list views"),
281     }
282
283     _defaults = {
284         'type': 'ir.actions.act_window',
285         'view_type': 'form',
286         'view_mode': 'tree,form',
287         'context': '{}',
288         'limit': 80,
289         'target': 'current',
290         'auto_refresh': 0,
291         'auto_search':True,
292         'multi': False,
293     }
294
295     def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
296         """ call the method get_empty_list_help of the model and set the window action help message
297         """
298         ids_int = isinstance(ids, (int, long))
299         if ids_int:
300             ids = [ids]
301         results = super(ir_actions_act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load)
302
303         if not fields or 'help' in fields:
304             context = dict(context or {})
305             eval_dict = {
306                 'active_model': context.get('active_model'),
307                 'active_id': context.get('active_id'),
308                 'active_ids': context.get('active_ids'),
309                 'uid': uid,
310             }
311             for res in results:
312                 model = res.get('res_model')
313                 if model and self.pool.get(model):
314                     try:
315                         with tools.mute_logger("openerp.tools.safe_eval"):
316                             eval_context = eval(res['context'] or "{}", eval_dict) or {}
317                     except Exception:
318                         continue
319                     custom_context = dict(context, **eval_context)
320                     res['help'] = self.pool.get(model).get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context)
321         if ids_int:
322             return results[0]
323         return results
324
325     def for_xml_id(self, cr, uid, module, xml_id, context=None):
326         """ Returns the act_window object created for the provided xml_id
327
328         :param module: the module the act_window originates in
329         :param xml_id: the namespace-less id of the action (the @id
330                        attribute from the XML file)
331         :return: A read() view of the ir.actions.act_window
332         """
333         dataobj = self.pool.get('ir.model.data')
334         data_id = dataobj._get_id (cr, SUPERUSER_ID, module, xml_id)
335         res_id = dataobj.browse(cr, uid, data_id, context).res_id
336         return self.read(cr, uid, res_id, [], context)
337
338 VIEW_TYPES = [
339     ('tree', 'Tree'),
340     ('form', 'Form'),
341     ('graph', 'Graph'),
342     ('calendar', 'Calendar'),
343     ('gantt', 'Gantt'),
344     ('kanban', 'Kanban')]
345 class ir_actions_act_window_view(osv.osv):
346     _name = 'ir.actions.act_window.view'
347     _table = 'ir_act_window_view'
348     _rec_name = 'view_id'
349     _order = 'sequence'
350     _columns = {
351         'sequence': fields.integer('Sequence'),
352         'view_id': fields.many2one('ir.ui.view', 'View'),
353         'view_mode': fields.selection(VIEW_TYPES, string='View Type', required=True),
354         'act_window_id': fields.many2one('ir.actions.act_window', 'Action', ondelete='cascade'),
355         'multi': fields.boolean('On Multiple Doc.',
356             help="If set to true, the action will not be displayed on the right toolbar of a form view."),
357     }
358     _defaults = {
359         'multi': False,
360     }
361     def _auto_init(self, cr, context=None):
362         super(ir_actions_act_window_view, self)._auto_init(cr, context)
363         cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = \'act_window_view_unique_mode_per_action\'')
364         if not cr.fetchone():
365             cr.execute('CREATE UNIQUE INDEX act_window_view_unique_mode_per_action ON ir_act_window_view (act_window_id, view_mode)')
366
367
368 class ir_actions_act_window_close(osv.osv):
369     _name = 'ir.actions.act_window_close'
370     _inherit = 'ir.actions.actions'
371     _table = 'ir_actions'
372     _defaults = {
373         'type': 'ir.actions.act_window_close',
374     }
375
376
377 class ir_actions_act_url(osv.osv):
378     _name = 'ir.actions.act_url'
379     _table = 'ir_act_url'
380     _inherit = 'ir.actions.actions'
381     _sequence = 'ir_actions_id_seq'
382     _order = 'name'
383     _columns = {
384         'name': fields.char('Action Name', size=64, translate=True),
385         'type': fields.char('Action Type', size=32, required=True),
386         'url': fields.text('Action URL',required=True),
387         'target': fields.selection((
388             ('new', 'New Window'),
389             ('self', 'This Window')),
390             'Action Target', required=True
391         )
392     }
393     _defaults = {
394         'type': 'ir.actions.act_url',
395         'target': 'new'
396     }
397
398
399 class ir_actions_server(osv.osv):
400     """ Server actions model. Server action work on a base model and offer various
401     type of actions that can be executed automatically, for example using base
402     action rules, of manually, by adding the action in the 'More' contextual
403     menu.
404
405     Since OpenERP 8.0 a button 'Create Menu Action' button is available on the
406     action form view. It creates an entry in the More menu of the base model.
407     This allows to create server actions and run them in mass mode easily through
408     the interface.
409
410     The available actions are :
411
412     - 'Execute Python Code': a block of python code that will be executed
413     - 'Trigger a Workflow Signal': send a signal to a workflow
414     - 'Run a Client Action': choose a client action to launch
415     - 'Create or Copy a new Record': create a new record with new values, or
416       copy an existing record in your database
417     - 'Write on a Record': update the values of a record
418     - 'Execute several actions': define an action that triggers several other
419       server actions
420     """
421     _name = 'ir.actions.server'
422     _table = 'ir_act_server'
423     _inherit = 'ir.actions.actions'
424     _sequence = 'ir_actions_id_seq'
425     _order = 'sequence,name'
426
427     def _select_objects(self, cr, uid, context=None):
428         model_pool = self.pool.get('ir.model')
429         ids = model_pool.search(cr, uid, [], limit=None)
430         res = model_pool.read(cr, uid, ids, ['model', 'name'])
431         return [(r['model'], r['name']) for r in res] + [('', '')]
432
433     def _get_states(self, cr, uid, context=None):
434         """ Override me in order to add new states in the server action. Please
435         note that the added key length should not be higher than already-existing
436         ones. """
437         return [('code', 'Execute Python Code'),
438                 ('trigger', 'Trigger a Workflow Signal'),
439                 ('client_action', 'Run a Client Action'),
440                 ('object_create', 'Create or Copy a new Record'),
441                 ('object_write', 'Write on a Record'),
442                 ('multi', 'Execute several actions')]
443
444     def _get_states_wrapper(self, cr, uid, context=None):
445         return self._get_states(cr, uid, context)
446
447     _columns = {
448         'name': fields.char('Action Name', required=True, size=64, translate=True),
449         'condition': fields.char('Condition',
450                                  help="Condition verified before executing the server action. If it "
451                                  "is not verified, the action will not be executed. The condition is "
452                                  "a Python expression, like 'object.list_price > 5000'. A void "
453                                  "condition is considered as always True. Help about python expression "
454                                  "is given in the help tab."),
455         'state': fields.selection(_get_states_wrapper, 'Action To Do', required=True,
456                                   help="Type of server action. The following values are available:\n"
457                                   "- 'Execute Python Code': a block of python code that will be executed\n"
458                                   "- 'Trigger a Workflow Signal': send a signal to a workflow\n"
459                                   "- 'Run a Client Action': choose a client action to launch\n"
460                                   "- 'Create or Copy a new Record': create a new record with new values, or copy an existing record in your database\n"
461                                   "- 'Write on a Record': update the values of a record\n"
462                                   "- 'Execute several actions': define an action that triggers several other server actions\n"
463                                   "- 'Send Email': automatically send an email (available in email_template)"),
464         'usage': fields.char('Action Usage', size=32),
465         'type': fields.char('Action Type', size=32, required=True),
466         # Generic
467         'sequence': fields.integer('Sequence',
468                                    help="When dealing with multiple actions, the execution order is "
469                                    "based on the sequence. Low number means high priority."),
470         'model_id': fields.many2one('ir.model', 'Base Model', required=True, ondelete='cascade',
471                                     help="Base model on which the server action runs."),
472         'menu_ir_values_id': fields.many2one('ir.values', 'More Menu entry', readonly=True,
473                                              help='More menu entry.'),
474         # Client Action
475         'action_id': fields.many2one('ir.actions.actions', 'Client Action',
476                                      help="Select the client action that has to be executed."),
477         # Python code
478         'code': fields.text('Python Code',
479                             help="Write Python code that the action will execute. Some variables are "
480                             "available for use; help about pyhon expression is given in the help tab."),
481         # Workflow signal
482         'use_relational_model': fields.selection([('base', 'Use the base model of the action'),
483                                                   ('relational', 'Use a relation field on the base model')],
484                                                  string='Target Model', required=True),
485         'wkf_transition_id': fields.many2one('workflow.transition', string='Signal to Trigger',
486                                              help="Select the workflow signal to trigger."),
487         'wkf_model_id': fields.many2one('ir.model', 'Target Model',
488                                         help="The model that will receive the workflow signal. Note that it should have a workflow associated with it."),
489         'wkf_model_name': fields.related('wkf_model_id', 'model', type='char', string='Target Model Name', store=True, readonly=True),
490         'wkf_field_id': fields.many2one('ir.model.fields', string='Relation Field',
491                                         oldname='trigger_obj_id',
492                                         help="The field on the current object that links to the target object record (must be a many2one, or an integer field with the record ID)"),
493         # Multi
494         'child_ids': fields.many2many('ir.actions.server', 'rel_server_actions',
495                                       'server_id', 'action_id',
496                                       string='Child Actions',
497                                       help='Child server actions that will be executed. Note that the last return returned action value will be used as global return value.'),
498         # Create/Copy/Write
499         'use_create': fields.selection([('new', 'Create a new record in the Base Model'),
500                                         ('new_other', 'Create a new record in another model'),
501                                         ('copy_current', 'Copy the current record'),
502                                         ('copy_other', 'Choose and copy a record in the database')],
503                                        string="Creation Policy", required=True,
504                                        help=""),
505         'crud_model_id': fields.many2one('ir.model', 'Target Model',
506                                          oldname='srcmodel_id',
507                                          help="Model for record creation / update. Set this field only to specify a different model than the base model."),
508         'crud_model_name': fields.related('crud_model_id', 'model', type='char',
509                                           string='Create/Write Target Model Name',
510                                           store=True, readonly=True),
511         'ref_object': fields.reference('Reference record', selection=_select_objects, size=128,
512                                        oldname='copy_object'),
513         'link_new_record': fields.boolean('Attach the new record',
514                                           help="Check this if you want to link the newly-created record "
515                                           "to the current record on which the server action runs."),
516         'link_field_id': fields.many2one('ir.model.fields', 'Link using field',
517                                          oldname='record_id',
518                                          help="Provide the field where the record id is stored after the operations."),
519         'use_write': fields.selection([('current', 'Update the current record'),
520                                        ('expression', 'Update a record linked to the current record using python'),
521                                        ('other', 'Choose and Update a record in the database')],
522                                       string='Update Policy', required=True,
523                                       help=""),
524         'write_expression': fields.char('Expression',
525                                         oldname='write_id',
526                                         help="Provide an expression that, applied on the current record, gives the field to update."),
527         'fields_lines': fields.one2many('ir.server.object.lines', 'server_id',
528                                         string='Value Mapping',
529                                         help=""),
530
531         # Fake fields used to implement the placeholder assistant
532         'model_object_field': fields.many2one('ir.model.fields', string="Field",
533                                               help="Select target field from the related document model.\n"
534                                                    "If it is a relationship field you will be able to select "
535                                                    "a target field at the destination of the relationship."),
536         'sub_object': fields.many2one('ir.model', 'Sub-model', readonly=True,
537                                       help="When a relationship field is selected as first field, "
538                                            "this field shows the document model the relationship goes to."),
539         'sub_model_object_field': fields.many2one('ir.model.fields', 'Sub-field',
540                                                   help="When a relationship field is selected as first field, "
541                                                        "this field lets you select the target field within the "
542                                                        "destination document model (sub-model)."),
543         'copyvalue': fields.char('Placeholder Expression', help="Final placeholder expression, to be copy-pasted in the desired template field."),
544         # Fake fields used to implement the ID finding assistant
545         'id_object': fields.reference('Record', selection=_select_objects, size=128),
546         'id_value': fields.char('Record ID'),
547     }
548
549     _defaults = {
550         'state': 'code',
551         'condition': 'True',
552         'type': 'ir.actions.server',
553         'sequence': 5,
554         'code': """# You can use the following variables:
555 #  - self: ORM model of the record on which the action is triggered
556 #  - object: browse_record of the record on which the action is triggered if there is one, otherwise None
557 #  - pool: ORM model pool (i.e. self.pool)
558 #  - cr: database cursor
559 #  - uid: current user id
560 #  - context: current context
561 #  - time: Python time module
562 #  - workflow: Workflow engine
563 # If you plan to return an action, assign: action = {...}""",
564         'use_relational_model': 'base',
565         'use_create': 'new',
566         'use_write': 'current',
567     }
568
569     def _check_expression(self, cr, uid, expression, model_id, context):
570         """ Check python expression (condition, write_expression). Each step of
571         the path must be a valid many2one field, or an integer field for the last
572         step.
573
574         :param str expression: a python expression, beginning by 'obj' or 'object'
575         :param int model_id: the base model of the server action
576         :returns tuple: (is_valid, target_model_name, error_msg)
577         """
578         if not model_id:
579             return (False, None, 'Your expression cannot be validated because the Base Model is not set.')
580         # fetch current model
581         current_model_name = self.pool.get('ir.model').browse(cr, uid, model_id, context).model
582         # transform expression into a path that should look like 'object.many2onefield.many2onefield'
583         path = expression.split('.')
584         initial = path.pop(0)
585         if initial not in ['obj', 'object']:
586             return (False, None, 'Your expression should begin with obj or object.\nAn expression builder is available in the help tab.')
587         # analyze path
588         while path:
589             step = path.pop(0)
590             column_info = self.pool[current_model_name]._all_columns.get(step)
591             if not column_info:
592                 return (False, None, 'Part of the expression (%s) is not recognized as a column in the model %s.' % (step, current_model_name))
593             column_type = column_info.column._type
594             if column_type not in ['many2one', 'int']:
595                 return (False, None, 'Part of the expression (%s) is not a valid column type (is %s, should be a many2one or an int)' % (step, column_type))
596             if column_type == 'int' and path:
597                 return (False, None, 'Part of the expression (%s) is an integer field that is only allowed at the end of an expression' % (step))
598             if column_type == 'many2one':
599                 current_model_name = column_info.column._obj
600         return (True, current_model_name, None)
601
602     def _check_write_expression(self, cr, uid, ids, context=None):
603         for record in self.browse(cr, uid, ids, context=context):
604             if record.write_expression and record.model_id:
605                 correct, model_name, message = self._check_expression(cr, uid, record.write_expression, record.model_id.id, context=context)
606                 if not correct:
607                     _logger.warning('Invalid expression: %s' % message)
608                     return False
609         return True
610
611     _constraints = [
612         (_check_write_expression,
613             'Incorrect Write Record Expression',
614             ['write_expression']),
615         (partial(osv.Model._check_m2m_recursion, field_name='child_ids'),
616             'Recursion found in child server actions',
617             ['child_ids']),
618     ]
619
620     def on_change_model_id(self, cr, uid, ids, model_id, wkf_model_id, crud_model_id, context=None):
621         """ When changing the action base model, reset workflow and crud config
622         to ease value coherence. """
623         values = {
624             'use_create': 'new',
625             'use_write': 'current',
626             'use_relational_model': 'base',
627             'wkf_model_id': model_id,
628             'wkf_field_id': False,
629             'crud_model_id': model_id,
630         }
631         return {'value': values}
632
633     def on_change_wkf_wonfig(self, cr, uid, ids, use_relational_model, wkf_field_id, wkf_model_id, model_id, context=None):
634         """ Update workflow type configuration
635
636          - update the workflow model (for base (model_id) /relational (field.relation))
637          - update wkf_transition_id to False if workflow model changes, to force
638            the user to choose a new one
639         """
640         values = {}
641         if use_relational_model == 'relational' and wkf_field_id:
642             field = self.pool['ir.model.fields'].browse(cr, uid, wkf_field_id, context=context)
643             new_wkf_model_id = self.pool.get('ir.model').search(cr, uid, [('model', '=', field.relation)], context=context)[0]
644             values['wkf_model_id'] = new_wkf_model_id
645         else:
646             values['wkf_model_id'] = model_id
647         return {'value': values}
648
649     def on_change_wkf_model_id(self, cr, uid, ids, wkf_model_id, context=None):
650         """ When changing the workflow model, update its stored name also """
651         wkf_model_name = False
652         if wkf_model_id:
653             wkf_model_name = self.pool.get('ir.model').browse(cr, uid, wkf_model_id, context).model
654         values = {'wkf_transition_id': False, 'wkf_model_name': wkf_model_name}
655         return {'value': values}
656
657     def on_change_crud_config(self, cr, uid, ids, state, use_create, use_write, ref_object, crud_model_id, model_id, context=None):
658         """ Wrapper on CRUD-type (create or write) on_change """
659         if state == 'object_create':
660             return self.on_change_create_config(cr, uid, ids, use_create, ref_object, crud_model_id, model_id, context=context)
661         elif state == 'object_write':
662             return self.on_change_write_config(cr, uid, ids, use_write, ref_object, crud_model_id, model_id, context=context)
663         else:
664             return {}
665
666     def on_change_create_config(self, cr, uid, ids, use_create, ref_object, crud_model_id, model_id, context=None):
667         """ When changing the object_create type configuration:
668
669          - `new` and `copy_current`: crud_model_id is the same as base model
670          - `new_other`: user choose crud_model_id
671          - `copy_other`: disassemble the reference object to have its model
672          - if the target model has changed, then reset the link field that is
673            probably not correct anymore
674         """
675         values = {}
676         if use_create == 'new':
677             values['crud_model_id'] = model_id
678         elif use_create == 'new_other':
679             pass
680         elif use_create == 'copy_current':
681             values['crud_model_id'] = model_id
682         elif use_create == 'copy_other' and ref_object:
683             ref_model, ref_id = ref_object.split(',')
684             ref_model_id = self.pool['ir.model'].search(cr, uid, [('model', '=', ref_model)], context=context)[0]
685             values['crud_model_id'] = ref_model_id
686
687         if values.get('crud_model_id') != crud_model_id:
688             values['link_field_id'] = False
689         return {'value': values}
690
691     def on_change_write_config(self, cr, uid, ids, use_write, ref_object, crud_model_id, model_id, context=None):
692         """ When changing the object_write type configuration:
693
694          - `current`: crud_model_id is the same as base model
695          - `other`: disassemble the reference object to have its model
696          - `expression`: has its own on_change, nothing special here
697         """
698         values = {}
699         if use_write == 'current':
700             values['crud_model_id'] = model_id
701         elif use_write == 'other' and ref_object:
702             ref_model, ref_id = ref_object.split(',')
703             ref_model_id = self.pool['ir.model'].search(cr, uid, [('model', '=', ref_model)], context=context)[0]
704             values['crud_model_id'] = ref_model_id
705         elif use_write == 'expression':
706             pass
707
708         if values.get('crud_model_id') != crud_model_id:
709             values['link_field_id'] = False
710         return {'value': values}
711
712     def on_change_write_expression(self, cr, uid, ids, write_expression, model_id, context=None):
713         """ Check the write_expression and update crud_model_id accordingly """
714         values = {}
715         valid, model_name, message = self._check_expression(cr, uid, write_expression, model_id, context=context)
716         if valid:
717             ref_model_id = self.pool['ir.model'].search(cr, uid, [('model', '=', model_name)], context=context)[0]
718             values['crud_model_id'] = ref_model_id
719             return {'value': values}
720         if not message:
721             message = 'Invalid expression'
722         return {
723             'warning': {
724                 'title': 'Incorrect expression',
725                 'message': message,
726             }
727         }
728
729     def on_change_crud_model_id(self, cr, uid, ids, crud_model_id, context=None):
730         """ When changing the CRUD model, update its stored name also """
731         crud_model_name = False
732         if crud_model_id:
733             crud_model_name = self.pool.get('ir.model').browse(cr, uid, crud_model_id, context).model
734         values = {'link_field_id': False, 'crud_model_name': crud_model_name}
735         return {'value': values}
736
737     def _build_expression(self, field_name, sub_field_name):
738         """ Returns a placeholder expression for use in a template field,
739         based on the values provided in the placeholder assistant.
740
741         :param field_name: main field name
742         :param sub_field_name: sub field name (M2O)
743         :return: final placeholder expression
744         """
745         expression = ''
746         if field_name:
747             expression = "object." + field_name
748             if sub_field_name:
749                 expression += "." + sub_field_name
750         return expression
751
752     def onchange_sub_model_object_value_field(self, cr, uid, ids, model_object_field, sub_model_object_field=False, context=None):
753         result = {
754             'sub_object': False,
755             'copyvalue': False,
756             'sub_model_object_field': False,
757         }
758         if model_object_field:
759             fields_obj = self.pool.get('ir.model.fields')
760             field_value = fields_obj.browse(cr, uid, model_object_field, context)
761             if field_value.ttype in ['many2one', 'one2many', 'many2many']:
762                 res_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', field_value.relation)], context=context)
763                 sub_field_value = False
764                 if sub_model_object_field:
765                     sub_field_value = fields_obj.browse(cr, uid, sub_model_object_field, context)
766                 if res_ids:
767                     result.update({
768                         'sub_object': res_ids[0],
769                         'copyvalue': self._build_expression(field_value.name, sub_field_value and sub_field_value.name or False),
770                         'sub_model_object_field': sub_model_object_field or False,
771                     })
772             else:
773                 result.update({
774                     'copyvalue': self._build_expression(field_value.name, False),
775                 })
776         return {'value': result}
777
778     def onchange_id_object(self, cr, uid, ids, id_object, context=None):
779         if id_object:
780             ref_model, ref_id = id_object.split(',')
781             return {'value': {'id_value': ref_id}}
782         return {'value': {'id_value': False}}
783
784     def create_action(self, cr, uid, ids, context=None):
785         """ Create a contextual action for each of the server actions. """
786         for action in self.browse(cr, uid, ids, context=context):
787             ir_values_id = self.pool.get('ir.values').create(cr, SUPERUSER_ID, {
788                 'name': _('Run %s') % action.name,
789                 'model': action.model_id.model,
790                 'key2': 'client_action_multi',
791                 'value': "ir.actions.server,%s" % action.id,
792             }, context)
793             action.write({
794                 'menu_ir_values_id': ir_values_id,
795             })
796
797         return True
798
799     def unlink_action(self, cr, uid, ids, context=None):
800         """ Remove the contextual actions created for the server actions. """
801         for action in self.browse(cr, uid, ids, context=context):
802             if action.menu_ir_values_id:
803                 try:
804                     self.pool.get('ir.values').unlink(cr, SUPERUSER_ID, action.menu_ir_values_id.id, context)
805                 except Exception:
806                     raise osv.except_osv(_('Warning'), _('Deletion of the action record failed.'))
807         return True
808
809     def run_action_client_action(self, cr, uid, action, eval_context=None, context=None):
810         if not action.action_id:
811             raise osv.except_osv(_('Error'), _("Please specify an action to launch!"))
812         return self.pool[action.action_id.type].read(cr, uid, action.action_id.id, context=context)
813
814     def run_action_code_multi(self, cr, uid, action, eval_context=None, context=None):
815         eval(action.code.strip(), eval_context, mode="exec", nocopy=True)  # nocopy allows to return 'action'
816         if 'action' in eval_context:
817             return eval_context['action']
818
819     def run_action_trigger(self, cr, uid, action, eval_context=None, context=None):
820         """ Trigger a workflow signal, depending on the use_relational_model:
821
822          - `base`: base_model_pool.signal_<TRIGGER_NAME>(cr, uid, context.get('active_id'))
823          - `relational`: find the related model and object, using the relational
824            field, then target_model_pool.signal_<TRIGGER_NAME>(cr, uid, target_id)
825         """
826         obj_pool = self.pool[action.model_id.model]
827         if action.use_relational_model == 'base':
828             target_id = context.get('active_id')
829             target_pool = obj_pool
830         else:
831             value = getattr(obj_pool.browse(cr, uid, context.get('active_id'), context=context), action.wkf_field_id.name)
832             if action.wkf_field_id.ttype == 'many2one':
833                 target_id = value.id
834             else:
835                 target_id = value
836             target_pool = self.pool[action.wkf_model_id.model]
837
838         trigger_name = action.wkf_transition_id.signal
839
840         workflow.trg_validate(uid, target_pool._name, target_id, trigger_name, cr)
841
842     def run_action_multi(self, cr, uid, action, eval_context=None, context=None):
843         res = []
844         for act in action.child_ids:
845             result = self.run(cr, uid, [act.id], context)
846             if result:
847                 res.append(result)
848         return res and res[0] or False
849
850     def run_action_object_write(self, cr, uid, action, eval_context=None, context=None):
851         """ Write server action.
852
853          - 1. evaluate the value mapping
854          - 2. depending on the write configuration:
855
856           - `current`: id = active_id
857           - `other`: id = from reference object
858           - `expression`: id = from expression evaluation
859         """
860         res = {}
861         for exp in action.fields_lines:
862             if exp.type == 'equation':
863                 expr = eval(exp.value, eval_context)
864             else:
865                 expr = exp.value
866             res[exp.col1.name] = expr
867
868         if action.use_write == 'current':
869             model = action.model_id.model
870             ref_id = context.get('active_id')
871         elif action.use_write == 'other':
872             model = action.crud_model_id.model
873             ref_id = action.ref_object.id
874         elif action.use_write == 'expression':
875             model = action.crud_model_id.model
876             ref = eval(action.write_expression, eval_context)
877             if isinstance(ref, browse_record):
878                 ref_id = getattr(ref, 'id')
879             else:
880                 ref_id = int(ref)
881
882         obj_pool = self.pool[model]
883         obj_pool.write(cr, uid, [ref_id], res, context=context)
884
885     def run_action_object_create(self, cr, uid, action, eval_context=None, context=None):
886         """ Create and Copy server action.
887
888          - 1. evaluate the value mapping
889          - 2. depending on the write configuration:
890
891           - `new`: new record in the base model
892           - `copy_current`: copy the current record (id = active_id) + gives custom values
893           - `new_other`: new record in target model
894           - `copy_other`: copy the current record (id from reference object)
895             + gives custom values
896         """
897         res = {}
898         for exp in action.fields_lines:
899             if exp.type == 'equation':
900                 expr = eval(exp.value, eval_context)
901             else:
902                 expr = exp.value
903             res[exp.col1.name] = expr
904
905         if action.use_create in ['new', 'copy_current']:
906             model = action.model_id.model
907         elif action.use_create in ['new_other', 'copy_other']:
908             model = action.crud_model_id.model
909
910         obj_pool = self.pool[model]
911         if action.use_create == 'copy_current':
912             ref_id = context.get('active_id')
913             res_id = obj_pool.copy(cr, uid, ref_id, res, context=context)
914         elif action.use_create == 'copy_other':
915             ref_id = action.ref_object.id
916             res_id = obj_pool.copy(cr, uid, ref_id, res, context=context)
917         else:
918             res_id = obj_pool.create(cr, uid, res, context=context)
919
920         if action.link_new_record and action.link_field_id:
921             self.pool[action.model_id.model].write(cr, uid, [context.get('active_id')], {action.link_field_id.name: res_id})
922
923     def _get_eval_context(self, cr, uid, action, context=None):
924         """ Prepare the context used when evaluating python code, like the
925         condition or code server actions.
926
927         :param action: the current server action
928         :type action: browse record
929         :returns: dict -- evaluation context given to (safe_)eval """
930         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
931         obj_pool = self.pool[action.model_id.model]
932         obj = None
933         if context.get('active_model') == action.model_id.model and context.get('active_id'):
934             obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
935         return {
936             'self': obj_pool,
937             'object': obj,
938             'obj': obj,
939             'pool': self.pool,
940             'time': time,
941             'datetime': datetime,
942             'dateutil': dateutil,
943             'cr': cr,
944             'uid': uid,
945             'user': user,
946             'context': context,
947             'workflow': workflow
948             'Warning': openerp.exceptions.Warning,
949         }
950
951     def run(self, cr, uid, ids, context=None):
952         """ Runs the server action. For each server action, the condition is
953         checked. Note that a void (``False``) condition is considered as always
954         valid. If it is verified, the run_action_<STATE> method is called. This
955         allows easy overriding of the server actions.
956
957         :param dict context: context should contain following keys
958
959                              - active_id: id of the current object (single mode)
960                              - active_model: current model that should equal the action's model
961
962                              The following keys are optional:
963
964                              - active_ids: ids of the current records (mass mode). If active_ids
965                                and active_id are present, active_ids is given precedence.
966
967         :return: an action_id to be executed, or False is finished correctly without
968                  return action
969         """
970         if context is None:
971             context = {}
972         res = False
973         for action in self.browse(cr, uid, ids, context):
974             eval_context = self._get_eval_context(cr, uid, action, context=context)
975             condition = action.condition
976             if condition is False:
977                 # Void (aka False) conditions are considered as True
978                 condition = True
979             if hasattr(self, 'run_action_%s_multi' % action.state):
980                 run_context = eval_context['context']
981                 expr = eval(str(condition), eval_context)
982                 if not expr:
983                     continue
984                 # call the multi method
985                 func = getattr(self, 'run_action_%s_multi' % action.state)
986                 res = func(cr, uid, action, eval_context=eval_context, context=run_context)
987
988             elif hasattr(self, 'run_action_%s' % action.state):
989                 func = getattr(self, 'run_action_%s' % action.state)
990                 active_id = context.get('active_id')
991                 active_ids = context.get('active_ids', [active_id] if active_id else [])
992                 for active_id in active_ids:
993                     # run context dedicated to a particular active_id
994                     run_context = dict(context, active_ids=[active_id], active_id=active_id)
995                     eval_context["context"] = run_context
996                     expr = eval(str(condition), eval_context)
997                     if not expr:
998                         continue
999                     # call the single method related to the action: run_action_<STATE>
1000                     res = func(cr, uid, action, eval_context=eval_context, context=run_context)
1001         return res
1002
1003
1004 class ir_server_object_lines(osv.osv):
1005     _name = 'ir.server.object.lines'
1006     _sequence = 'ir_actions_id_seq'
1007     _columns = {
1008         'server_id': fields.many2one('ir.actions.server', 'Related Server Action'),
1009         'col1': fields.many2one('ir.model.fields', 'Field', required=True),
1010         'value': fields.text('Value', required=True, help="Expression containing a value specification. \n"
1011                                                           "When Formula type is selected, this field may be a Python expression "
1012                                                           " that can use the same values as for the condition field on the server action.\n"
1013                                                           "If Value type is selected, the value will be used directly without evaluation."),
1014         'type': fields.selection([
1015             ('value', 'Value'),
1016             ('equation', 'Python expression')
1017         ], 'Evaluation Type', required=True, change_default=True),
1018     }
1019     _defaults = {
1020         'type': 'value',
1021     }
1022
1023
1024 TODO_STATES = [('open', 'To Do'),
1025                ('done', 'Done')]
1026 TODO_TYPES = [('manual', 'Launch Manually'),('once', 'Launch Manually Once'),
1027               ('automatic', 'Launch Automatically')]
1028 class ir_actions_todo(osv.osv):
1029     """
1030     Configuration Wizards
1031     """
1032     _name = 'ir.actions.todo'
1033     _description = "Configuration Wizards"
1034     _columns={
1035         'action_id': fields.many2one(
1036             'ir.actions.actions', 'Action', select=True, required=True),
1037         'sequence': fields.integer('Sequence'),
1038         'state': fields.selection(TODO_STATES, string='Status', required=True),
1039         'name': fields.char('Name', size=64),
1040         'type': fields.selection(TODO_TYPES, 'Type', required=True,
1041             help="""Manual: Launched manually.
1042 Automatic: Runs whenever the system is reconfigured.
1043 Launch Manually Once: after having been launched manually, it sets automatically to Done."""),
1044         'groups_id': fields.many2many('res.groups', 'res_groups_action_rel', 'uid', 'gid', 'Groups'),
1045         'note': fields.text('Text', translate=True),
1046     }
1047     _defaults={
1048         'state': 'open',
1049         'sequence': 10,
1050         'type': 'manual',
1051     }
1052     _order="sequence,id"
1053
1054     def action_launch(self, cr, uid, ids, context=None):
1055         """ Launch Action of Wizard"""
1056         wizard_id = ids and ids[0] or False
1057         wizard = self.browse(cr, uid, wizard_id, context=context)
1058         if wizard.type in ('automatic', 'once'):
1059             wizard.write({'state': 'done'})
1060
1061         # Load action
1062         act_type = self.pool.get('ir.actions.actions').read(cr, uid, wizard.action_id.id, ['type'], context=context)
1063
1064         res = self.pool[act_type['type']].read(cr, uid, wizard.action_id.id, [], context=context)
1065         if act_type['type'] != 'ir.actions.act_window':
1066             return res
1067         res.setdefault('context','{}')
1068         res['nodestroy'] = True
1069
1070         # Open a specific record when res_id is provided in the context
1071         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
1072         ctx = eval(res['context'], {'user': user})
1073         if ctx.get('res_id'):
1074             res.update({'res_id': ctx.pop('res_id')})
1075
1076         # disable log for automatic wizards
1077         if wizard.type == 'automatic':
1078             ctx.update({'disable_log': True})
1079         res.update({'context': ctx})
1080
1081         return res
1082
1083     def action_open(self, cr, uid, ids, context=None):
1084         """ Sets configuration wizard in TODO state"""
1085         return self.write(cr, uid, ids, {'state': 'open'}, context=context)
1086
1087     def progress(self, cr, uid, context=None):
1088         """ Returns a dict with 3 keys {todo, done, total}.
1089
1090         These keys all map to integers and provide the number of todos
1091         marked as open, the total number of todos and the number of
1092         todos not open (which is basically a shortcut to total-todo)
1093
1094         :rtype: dict
1095         """
1096         user_groups = set(map(
1097             lambda x: x.id,
1098             self.pool['res.users'].browse(cr, uid, [uid], context=context)[0].groups_id))
1099         def groups_match(todo):
1100             """ Checks if the todo's groups match those of the current user
1101             """
1102             return not todo.groups_id \
1103                    or bool(user_groups.intersection((
1104                         group.id for group in todo.groups_id)))
1105
1106         done = filter(
1107             groups_match,
1108             self.browse(cr, uid,
1109                 self.search(cr, uid, [('state', '!=', 'open')], context=context),
1110                         context=context))
1111
1112         total = filter(
1113             groups_match,
1114             self.browse(cr, uid,
1115                 self.search(cr, uid, [], context=context),
1116                         context=context))
1117
1118         return {
1119             'done': len(done),
1120             'total': len(total),
1121             'todo': len(total) - len(done)
1122         }
1123
1124
1125 class ir_actions_act_client(osv.osv):
1126     _name = 'ir.actions.client'
1127     _inherit = 'ir.actions.actions'
1128     _table = 'ir_act_client'
1129     _sequence = 'ir_actions_id_seq'
1130     _order = 'name'
1131
1132     def _get_params(self, cr, uid, ids, field_name, arg, context):
1133         result = {}
1134         for record in self.browse(cr, uid, ids, context=context):
1135             result[record.id] = record.params_store and eval(record.params_store, {'uid': uid}) or False
1136         return result
1137
1138     def _set_params(self, cr, uid, id, field_name, field_value, arg, context):
1139         if isinstance(field_value, dict):
1140             self.write(cr, uid, id, {'params_store': repr(field_value)}, context=context)
1141         else:
1142             self.write(cr, uid, id, {'params_store': field_value}, context=context)
1143
1144     _columns = {
1145         'name': fields.char('Action Name', required=True, size=64, translate=True),
1146         'tag': fields.char('Client action tag', size=64, required=True,
1147                            help="An arbitrary string, interpreted by the client"
1148                                 " according to its own needs and wishes. There "
1149                                 "is no central tag repository across clients."),
1150         'res_model': fields.char('Destination Model', size=64, 
1151             help="Optional model, mostly used for needactions."),
1152         'context': fields.char('Context Value', size=250, required=True,
1153             help="Context dictionary as Python expression, empty by default (Default: {})"),
1154         'params': fields.function(_get_params, fnct_inv=_set_params,
1155                                   type='binary', 
1156                                   string="Supplementary arguments",
1157                                   help="Arguments sent to the client along with"
1158                                        "the view tag"),
1159         'params_store': fields.binary("Params storage", readonly=True)
1160     }
1161     _defaults = {
1162         'type': 'ir.actions.client',
1163         'context': '{}',
1164
1165     }
1166
1167
1168
1169 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1170