2017-02-17 14 views
0

私はAPIを使用しています。まず、私は、顧客が選択した詳細な製品(ポップアップウィンドウのような)、View Selected Productこの画像(see this link)の中にあるものです。Pythonを使用して、クリックしたリストからツリービューで特定のフォームビューにリダイレクトする方法

ボタンをクリックすると、in this linkのような選択した製品のツリービューが表示されます。

私がしたかったのは、リスト/ツリービューのポップアップウィンドウで製品をクリックすると、リダイレクトリンクを作ってみたいと思います。したがって、リストでクリックした製品ののフォームビューにリダイレクトされます。リストの製品は、顧客が購入を選択した製品です。私のボタンは、顧客が買い物をするときに選択した商品のみを表示します。

私のコードに追加する必要はありますか?何を変更する必要がありますか?私はPythonとOdooの初心者です。ここで

は、ボタンのための私のPythonコードです:

from openerp import models, api, fields, _ 

class task_04 (models.Model): 

    #Inherit dari model purchase.order 
    _inherit = "purchase.order" 

    @api.multi 
    def action_view_related_products(self): 
     ids = [line.product_id.id 
       for line in self.order_line] 
     return{ 
      'name'   : ('View Chosen Products'), # Nama dari tabel pop up 
      'type'   : 'ir.actions.act_window', 
      'view_type'  : 'form', #Tampilan pada tabel pop-up 
      'view_mode'  : 'tree', # Menampilkan bagian yang di pop up, tree = menampilkan tabel tree nya utk product 
      'res_model'  : 'product.product', #Menampilkan tabel yang akan di show di pop-up screen 
      'target'  : 'new', # Untuk menjadikan tampilan prduct yang dipilih menjadi pop-up table tampilan baru, jika dikosongin maka tidak muncul pop-up namun muncul halaman baru. 
      'view_id'  : False, 
      'domain'  : [('id','in',ids)] #Filter id barang yang ditampilkan 
      } 

task_04() 

そして、ここでは私のXMLコードは、ボタンを表示します:

<openerp> 
<data> 
    <record id="task_4_purchase_order_form" model="ir.ui.view"> 
     <field name="name">purchase.order.form</field> 
     <field name="model">purchase.order</field> 
     <field name="inherit_id" ref="purchase.purchase_order_form"></field> 
     <field name="arch" type="xml"> 
      <!-- Lokasi untuk menempatkan button yang akan dibuat diletakkan di sebelah button cancel --> 
      <xpath expr="/form/header/button[@name='button_cancel']" position="inside"> 
       <!-- Membuat button --> 
       <button string="View Chosen Product(s)" type="object" name="action_view_related_products"/> 
      </xpath> 
     </field> 
    </record> 
</data> 
</openerp> 

答えて

0

これは、解決される。私は 'view mode'に 'form'を追加するだけです:Pythonファイルで 'tree、form'。

これにより、顧客が同じフォームビューで選択した製品の詳細が自動的に表示されます。したがって、Pythonファイルは次のようになります:

from openerp import models, api, fields, _ 

class task_04 (models.Model): 

    #Inherit dari model purchase.order 
    _inherit = "purchase.order" 

    @api.multi 
    def action_view_related_products(self): 
     ids = [line.product_id.id 
       for line in self.order_line] 
     return{ 
      'name'   : ('View Chosen Products'), # Nama dari tabel pop up 
      'type'   : 'ir.actions.act_window', 
      'view_type'  : 'form', #Tampilan pada tabel pop-up 
      'view_mode'  : 'tree', # Menampilkan bagian yang di pop up, tree = menampilkan tabel tree nya utk product 
      'res_model'  : 'product.product', #Menampilkan tabel yang akan di show di pop-up screen 
      'target'  : 'new', # Untuk menjadikan tampilan prduct yang dipilih menjadi pop-up table tampilan baru, jika dikosongin maka tidak muncul pop-up namun muncul halaman baru. 
      'view_id'  : False, 
      'domain'  : [('id','in',ids)] #Filter id barang yang ditampilkan 
      } 

task_04() 
+0

自己回答を投稿してくれてありがとう。タイトルに[解決済み]を追加しないでください。代わりにこれらの回答の隣にある目盛りをクリックすると緑色に変わります。 – halfer

0

は、このコードを試してください: -

#Inherit dari model purchase.order 
_inherit = "purchase.order" 


@api.multi 
def action_view_related_products(self): 
    ids = [line.product_id.id 
      for line in self.order_line] 
    tree_res = self.env['ir.model.data'].get_object_reference('code_residing_module_name', 'Your_tree_view_id') 
    tree_id = tree_res and tree_res[1] or False 
    form_res = self.env['ir.model.data'].get_object_reference('code_residing_module_name', 'Your_form_view_id') 
    tree_id = form_res and form_res[1] or False 

    return{ 
     'name'   : ('View Chosen Products'), # Nama dari tabel pop up 
     'type'   : 'ir.actions.act_window', 
     'view_type'  : 'form', #Tampilan pada tabel pop-up 
     'view_mode'  : 'tree,form', # Menampilkan bagian yang di pop up, tree = menampilkan tabel tree nya utk product 
     'res_model'  : 'product.product', #Menampilkan tabel yang akan di show di pop-up screen 
     'target'  : 'new', # Untuk menjadikan tampilan prduct yang dipilih menjadi pop-up table tampilan baru, jika dikosongin maka tidak muncul pop-up namun muncul halaman baru. 
     'views'   : [(tree_id, 'tree'),(form_id, 'form')] 
     'domain'  : [('id','in',ids)] #Filter id barang yang ditampilkan 
     } 
+0

そして、そのビューをどこに追加しますか? –

+0

あなたのコードMr burmeseを試してみると、どのmodulがget_object_reference()とどのidであるべきかを理解できません。 –

+0

あなたの現在のモジュール名とあなたのツリーview_id、編集された答えを確認してください –

関連する問題