2016-05-19 10 views
2

xmlを使用してカスタムボタンAdd Broを作成できました。Odoo 9カスタムボタンでアクションを作成する方法

enter image description here

は、ここで私は私がボタンを押したときに呼び出されます。このボタンにアクションを作成する方法、

<templates> 
    <tr t-extend="ListView.buttons"> 
    <t t-jquery="button.o_list_button_add" t-operation="after"> 
     <button id="tahu" name="action" type="object" class="btn btn-sm btn-primary"> 
      Add Bro 
     </button> 
    </t> 
    </tr> 
</templates> 

私の質問がされるXMLです。私は名前のactionとメソッドを作成しようとしましたので、ボタンのname属性を整えますが、何も起こりませんでした。

<record id="invoice_form_my" model="ir.ui.view"> 

      <field name="name">account.invoice.form.my</field> 

      <field name="model">account.invoice</field> 

      <field name="inherit_id" ref="account.invoice_form"/> 

      <field name="arch" type="xml"> 



       <xpath expr="/form/header/button[2][@string='Print']" position="after"> 

        <button name="my_button" string="Print2" class="oe_highlight"/> 

       </xpath> 

      </field> 

     </record> 

答えて

2

は、その方法のようにのように見えますListViewウィジェットを拡張し、ボタンにトリガーを追加する:

openerp.you_module_name_here = function(instance){ 

    var _t = instance.web._t, 
     _lt = instance.web._lt; 
    var QWeb = instance.web.qweb; 

    instance.web.ListView.include({ 

     load_list: function(data) { 
      if (this.$buttons) { 
       this.$buttons.find('#tahu').click(this.proxy('action')) ; 
      } 
     }, 

     action: function() { 
      var model_obj = new instance.web.Model('ir.model.data'); 
      view_id = model_obj.call('get_object_reference', ["account", "invoice_form"]); 

      this.do_action(
       name: _t('Customer Invoice'), 
       type: 'ir.actions.act_window', 
       res_model: 'purchase.order', 
       view_type: 'form', 
       view_mode: 'form', 
       view_id: view_id, 
       target: 'new' 
       ); 
     } 
    }); 
} 

/static/src/js/下に上記のコードと次のコードを含むxmlファイル( `module_view.xml)を含むjsファイル(script.js)を作成:

<template id="assets_backend_custom" name="custom assets" inherit_id="web.assets_backend"> 
    <xpath expr="." position="inside"> 
     <script type="text/javascript" src="/your_module_name_here/static/src/js/script.js"></script> 
     </xpath> 
</template> 

を__openerp__.py

... 

'data': [ 
    ... 

    "module_view.xml", 

    ... 
], 

... 
3

あなたが必要とする:あなたが

<xpath expr="/form/header/button[@name='invoice-open']" position="after"> 

    <!-- put your button here --> 

</xpath> 

を例XPathを使用することができますので、このテンプレートは、直接任意のメソッドを呼び出していないので、あなたのXMLコードで

@api.multi 
def action(self): 
    view_ref = self.env['ir.model.data'].get_object_reference('account', 'invoice_form') 
    view_id = view_ref[1] if view_ref else False 

    res = { 
     'type': 'ir.actions.act_window', 
     'name': _('Customer Invoice'), 
     'res_model': 'purchase.order', 
     'view_type': 'form', 
     'view_mode': 'form', 
     'view_id': view_id, 
     'target': 'new', 
     # 'context': {'default_partner_id': client_id} 
    } 

    return res 
関連する問題