zoukankan      html  css  js  c++  java
  • Odoo ir actions 分析

    源代码位置:openerp/addons/base/ir/ir_actions.py

    根类型:ir.actions.actions

     1 class actions(osv.osv):
     2     _name = 'ir.actions.actions'
     3     _table = 'ir_actions'
     4     _order = 'name'
     5     _columns = {
     6         'name': fields.char('Name', required=True),
     7         'type': fields.char('Action Type', required=True),
     8         'usage': fields.char('Action Usage'),
     9         'help': fields.text('Action description',
    10             help='Optional help text for the users with a description of the target view, such as its usage and purpose.',
    11             translate=True),
    12     }

    继承自ir.actions.actions 的类型有:ir.actions.report.xml,ir.actions.act_window,ir.actions.act_window_close,ir.actions.act_url,ir.actions.server,ir.actions.client 6种

    1 .ir.actions.report.xml :用于打印报表的动作 在定义中可知,8.0中支持的报表类型有以下几种:

    1 'report_type': fields.selection([('qweb-pdf', 'PDF'),
    2                     ('qweb-html', 'HTML'),
    3                     ('controller', 'Controller'),
    4                     ('pdf', 'RML pdf (deprecated)'),
    5                     ('sxw', 'RML sxw (deprecated)'),
    6                     ('webkit', 'Webkit (deprecated)'),
    7                     ],

    2.ir.actions.act_window:用于展现页面的动作 

     1 'name': fields.char('Action Name', required=True, translate=True),
     2         'type': fields.char('Action Type', required=True),
     3         'view_id': fields.many2one('ir.ui.view', 'View Ref.', ondelete='set null'),
     4         'domain': fields.char('Domain Value',
     5             help="Optional domain filtering of the destination data, as a Python expression"),
     6         'context': fields.char('Context Value', required=True,
     7             help="Context dictionary as Python expression, empty by default (Default: {})"),
     8         'res_id': fields.integer('Record ID', help="Database ID of record to open in form view, when ``view_mode`` is set to 'form' only"),
     9         'res_model': fields.char('Destination Model', required=True,
    10             help="Model name of the object to open in the view window"),
    11         'src_model': fields.char('Source Model',
    12             help="Optional model name of the objects on which this action should be visible"),
    13         'target': fields.selection([('current','Current Window'),('new','New Window'),('inline','Inline Edit'),('inlineview','Inline View')], 'Target Window'),
    14         'view_mode': fields.char('View Mode', required=True,
    15             help="Comma-separated list of allowed view modes, such as 'form', 'tree', 'calendar', etc. (Default: tree,form)"),
    16         'view_type': fields.selection((('tree','Tree'),('form','Form')), string='View Type', required=True,
    17             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"),
    18         'usage': fields.char('Action Usage',
    19             help="Used to filter menu and home actions from the user form."),
    20         'view_ids': fields.one2many('ir.actions.act_window.view', 'act_window_id', 'Views'),
    21         'views': fields.function(_views_get_fnc, type='binary', string='Views',
    22                help="This function field computes the ordered list of views that should be enabled " 
    23                     "when displaying the result of an action, federating view mode, views and " 
    24                     "reference view. The result is returned as an ordered list of pairs (view_id,view_mode)."),
    25         'limit': fields.integer('Limit', help='Default limit for the list view'),
    26         'auto_refresh': fields.integer('Auto-Refresh',
    27             help='Add an auto-refresh on the view'),
    28         'groups_id': fields.many2many('res.groups', 'ir_act_window_group_rel',
    29             'act_id', 'gid', 'Groups'),
    30         'search_view_id': fields.many2one('ir.ui.view', 'Search View Ref.'),
    31         'filter': fields.boolean('Filter'),
    32         'auto_search':fields.boolean('Auto Search'),
    33         'search_view' : fields.function(_search_view, type='text', string='Search View'),
    34         '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"),
    35     }

    比较重要的列:

    target:current(在当前页面显示),new(在新页面中显示,即弹窗方式),inline(内嵌),inlineview(内嵌视图).

    view_mode:视图模式 可选值:tree,form,graph,calendar,gantt,kanban

    view_type:视图类型 可选值:tree,form tree是指分层的树形视图,form是传统的列表类型

    view_ids:指定绑定的视图id

    limit:指定默认列表视图的显示行数

    multi:True 如果绑定了model,将只在列表视图的more按钮列表中显示.

    3.ir.actions.act_window_close

    关闭窗口的动作

    4.ir.actions.act_url

     1 _name = 'ir.actions.act_url'
     2     _table = 'ir_act_url'
     3     _inherit = 'ir.actions.actions'
     4     _sequence = 'ir_actions_id_seq'
     5     _order = 'name'
     6     _columns = {
     7         'name': fields.char('Action Name', required=True, translate=True),
     8         'type': fields.char('Action Type', required=True),
     9         'url': fields.text('Action URL',required=True),
    10         'target': fields.selection((
    11             ('new', 'New Window'),
    12             ('self', 'This Window')),
    13             'Action Target', required=True
    14         )
    15     }
    16     _defaults = {
    17         'type': 'ir.actions.act_url',
    18         'target': 'new'
    19     }

    暂不清楚,还没遇见过,应该是指定URL跳转之类的动作

    5.ir.actions.server

    执行服务器动作:可用的动作包括

    执行python代码块,触发工作流,执行客户端动作,创建并复制一条新记录,修改记录,执行多个服务器动作等.

    可以利用ir.actions.server在视图的more加入自定义按钮.

      1  'name': fields.char('Action Name', required=True, translate=True),
      2         'condition': fields.char('Condition',
      3                                  help="Condition verified before executing the server action. If it "
      4                                  "is not verified, the action will not be executed. The condition is "
      5                                  "a Python expression, like 'object.list_price > 5000'. A void "
      6                                  "condition is considered as always True. Help about python expression "
      7                                  "is given in the help tab."),
      8         'state': fields.selection(_get_states_wrapper, 'Action To Do', required=True,
      9                                   help="Type of server action. The following values are available:
    "
     10                                   "- 'Execute Python Code': a block of python code that will be executed
    "
     11                                   "- 'Trigger a Workflow Signal': send a signal to a workflow
    "
     12                                   "- 'Run a Client Action': choose a client action to launch
    "
     13                                   "- 'Create or Copy a new Record': create a new record with new values, or copy an existing record in your database
    "
     14                                   "- 'Write on a Record': update the values of a record
    "
     15                                   "- 'Execute several actions': define an action that triggers several other server actions
    "
     16                                   "- 'Send Email': automatically send an email (available in email_template)"),
     17         'usage': fields.char('Action Usage'),
     18         'type': fields.char('Action Type', required=True),
     19         # Generic
     20         'sequence': fields.integer('Sequence',
     21                                    help="When dealing with multiple actions, the execution order is "
     22                                    "based on the sequence. Low number means high priority."),
     23         'model_id': fields.many2one('ir.model', 'Base Model', required=True, ondelete='cascade',
     24                                     help="Base model on which the server action runs."),
     25         'model_name': fields.related('model_id', 'model', type='char',
     26                                      string='Model Name', readonly=True),
     27         'menu_ir_values_id': fields.many2one('ir.values', 'More Menu entry', readonly=True,
     28                                              help='More menu entry.', copy=False),
     29         # Client Action
     30         'action_id': fields.many2one('ir.actions.actions', 'Client Action',
     31                                      help="Select the client action that has to be executed."),
     32         # Python code
     33         'code': fields.text('Python Code',
     34                             help="Write Python code that the action will execute. Some variables are "
     35                             "available for use; help about pyhon expression is given in the help tab."),
     36         # Workflow signal
     37         'use_relational_model': fields.selection([('base', 'Use the base model of the action'),
     38                                                   ('relational', 'Use a relation field on the base model')],
     39                                                  string='Target Model', required=True),
     40         'wkf_transition_id': fields.many2one('workflow.transition', string='Signal to Trigger',
     41                                              help="Select the workflow signal to trigger."),
     42         'wkf_model_id': fields.many2one('ir.model', 'Target Model',
     43                                         help="The model that will receive the workflow signal. Note that it should have a workflow associated with it."),
     44         'wkf_model_name': fields.related('wkf_model_id', 'model', type='char', string='Target Model Name', store=True, readonly=True),
     45         'wkf_field_id': fields.many2one('ir.model.fields', string='Relation Field',
     46                                         oldname='trigger_obj_id',
     47                                         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)"),
     48         # Multi
     49         'child_ids': fields.many2many('ir.actions.server', 'rel_server_actions',
     50                                       'server_id', 'action_id',
     51                                       string='Child Actions',
     52                                       help='Child server actions that will be executed. Note that the last return returned action value will be used as global return value.'),
     53         # Create/Copy/Write
     54         'use_create': fields.selection([('new', 'Create a new record in the Base Model'),
     55                                         ('new_other', 'Create a new record in another model'),
     56                                         ('copy_current', 'Copy the current record'),
     57                                         ('copy_other', 'Choose and copy a record in the database')],
     58                                        string="Creation Policy", required=True,
     59                                        help=""),
     60         'crud_model_id': fields.many2one('ir.model', 'Target Model',
     61                                          oldname='srcmodel_id',
     62                                          help="Model for record creation / update. Set this field only to specify a different model than the base model."),
     63         'crud_model_name': fields.related('crud_model_id', 'model', type='char',
     64                                           string='Create/Write Target Model Name',
     65                                           store=True, readonly=True),
     66         'ref_object': fields.reference('Reference record', selection=_select_objects, size=128,
     67                                        oldname='copy_object'),
     68         'link_new_record': fields.boolean('Attach the new record',
     69                                           help="Check this if you want to link the newly-created record "
     70                                           "to the current record on which the server action runs."),
     71         'link_field_id': fields.many2one('ir.model.fields', 'Link using field',
     72                                          oldname='record_id',
     73                                          help="Provide the field where the record id is stored after the operations."),
     74         'use_write': fields.selection([('current', 'Update the current record'),
     75                                        ('expression', 'Update a record linked to the current record using python'),
     76                                        ('other', 'Choose and Update a record in the database')],
     77                                       string='Update Policy', required=True,
     78                                       help=""),
     79         'write_expression': fields.char('Expression',
     80                                         oldname='write_id',
     81                                         help="Provide an expression that, applied on the current record, gives the field to update."),
     82         'fields_lines': fields.one2many('ir.server.object.lines', 'server_id',
     83                                         string='Value Mapping',
     84                                         copy=True),
     85 
     86         # Fake fields used to implement the placeholder assistant
     87         'model_object_field': fields.many2one('ir.model.fields', string="Field",
     88                                               help="Select target field from the related document model.
    "
     89                                                    "If it is a relationship field you will be able to select "
     90                                                    "a target field at the destination of the relationship."),
     91         'sub_object': fields.many2one('ir.model', 'Sub-model', readonly=True,
     92                                       help="When a relationship field is selected as first field, "
     93                                            "this field shows the document model the relationship goes to."),
     94         'sub_model_object_field': fields.many2one('ir.model.fields', 'Sub-field',
     95                                                   help="When a relationship field is selected as first field, "
     96                                                        "this field lets you select the target field within the "
     97                                                        "destination document model (sub-model)."),
     98         'copyvalue': fields.char('Placeholder Expression', help="Final placeholder expression, to be copy-pasted in the desired template field."),
     99         # Fake fields used to implement the ID finding assistant
    100         'id_object': fields.reference('Record', selection=_select_objects, size=128),
    101         'id_value': fields.char('Record ID'),
    102     }

    6.ir.actions.client

     1 _columns = {
     2         'name': fields.char('Action Name', required=True, translate=True),
     3         'tag': fields.char('Client action tag', required=True,
     4                            help="An arbitrary string, interpreted by the client"
     5                                 " according to its own needs and wishes. There "
     6                                 "is no central tag repository across clients."),
     7         'res_model': fields.char('Destination Model', 
     8             help="Optional model, mostly used for needactions."),
     9         'context': fields.char('Context Value', required=True,
    10             help="Context dictionary as Python expression, empty by default (Default: {})"),
    11         'params': fields.function(_get_params, fnct_inv=_set_params,
    12                                   type='binary', 
    13                                   string="Supplementary arguments",
    14                                   help="Arguments sent to the client along with"
    15                                        "the view tag"),
    16         'params_store': fields.binary("Params storage", readonly=True)
    17     }
    18     _defaults = {
    19         'type': 'ir.actions.client',
    20         'context': '{}',
    21 
    22     }

    客户端动作

  • 相关阅读:
    P1579哥德巴赫猜想
    JAVA快速入门方法
    PHP快速入门方法
    Java 8 lambda表达式
    JVM内存配置参数
    Synchronized 关键字
    数据库事务的理解
    hello world 执行原理
    面试知识点总结之JVM调优
    面试知识点总结之RabbitMQ/Kafka使用场景
  • 原文地址:https://www.cnblogs.com/kfx2007/p/4337659.html
Copyright © 2011-2022 走看看