Odoo8action中_callback_method_name的用法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_23931991/article/details/83017182

odoo8中action定义时可以在context中添加‘_callback_method_name’属性,用于在点击菜单之后调用action时触发

以采购订单行模型为例,定义action如下:

<record model="ir.actions.act_window" id="purchase_order_line_action">
   <field name="name">Purchase Order Line</field>
    <field name="res_model">purchase.order.line</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree</field>
    <field name="view_id" ref="purchase_order_line_view_tree"/>
    <field name="context"
           eval="{ '_callback_method_name': 'purchase_reset_qty_invoice'}"/>
    <field name="search_view_id" ref="purchase_order_line_view_search"/>
    <field name="help" type="html">
      <p>
        Here you can track all the lines of purchase orders where the
        invoicing is "Based on Purchase Order Lines", and for which you
        have not received a supplier invoice yet. You can generate a
        draft supplier invoice based on the lines from this list.
      </p>
    </field>
</record>

在action的context中属性上添加,_callback_method_name后边的值是对应purchase.line模型中定义的方法

方法purchase_reset_qty_invoice如下:

@api.model
  def purchase_reset_qty_invoice(self):
      # do somting....
      pass

这样定义之后,就可以实现在触发action时调用自定义方法。

猜你喜欢

转载自blog.csdn.net/sinat_23931991/article/details/83017182