1
votes

I'm using API 9.Well first of all, I had make a Button to show a tree view of some detailed products that have been chosen by the customers (like a pop-up window), the button called View Chosen Product(s) in this image (see this link).

And then when the button clicked, it shows tree view of the chosen products like in this link.

So, what I wanted to do is, I'd like to make a redirect link if we click the product in the list / tree view pop-up window. So it will redirects to the form view of the product that we clicked on the list. The product on the list is the product that customer choose to buy. My buttons only showing the product that customer had chosen when they are shopping.

What should I add in my code or what should I change ? I am really a newbie in Python and in Odoo.

Here's my Python code for the button :

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()

And here's my XML code to view the button :

<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>
2

2 Answers

0
votes

Try this code:-

  #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
votes

This is solved. I just need to add a 'form' on the 'view mode' : 'tree,form' in Python file.

So it will automatically showed you the detailed of the products that was chosen by customers in the same form view. So the Python file will look like this :

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()