如何使用 Python 从树视图中的单击列表重定向到 Odoo 中的特定表单视图?
How to redirect from a clicked list in tree view to certain form view in Odoo using Python?
我正在使用 API 9.Well 首先,我制作了一个按钮来显示客户选择的一些详细产品的树视图(如弹出窗口) window),此图片中名为查看所选产品的按钮 (see this link)。
然后当单击按钮时,它会显示所选产品的树视图,如 in this link。
所以,我想做的是,如果我们单击列表/树视图弹出窗口中的产品 window,我想进行重定向 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>
试试这个代码:-
#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
}
已解决。我只需要在 'view mode' 上添加一个 'form' : 'tree,form' in Python 文件。
所以它会在同一个表单视图中自动向您显示客户选择的产品的详细信息。所以 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()
我正在使用 API 9.Well 首先,我制作了一个按钮来显示客户选择的一些详细产品的树视图(如弹出窗口) window),此图片中名为查看所选产品的按钮 (see this link)。
然后当单击按钮时,它会显示所选产品的树视图,如 in this link。
所以,我想做的是,如果我们单击列表/树视图弹出窗口中的产品 window,我想进行重定向 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>
试试这个代码:-
#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
}
已解决。我只需要在 'view mode' 上添加一个 'form' : 'tree,form' in Python 文件。
所以它会在同一个表单视图中自动向您显示客户选择的产品的详细信息。所以 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()