Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

Is it possible to create multiple views for a single model?

Avatar
odoo
4 Comments
Avatar
Discard
Avatar
odoo
-

Hello, are you trying to implement different kind of view when the model is in different status(ie, form, tree views are different when status is different)

OR

DO you just want user with group X see records containing status A only, group Y see records with status B etc

Avatar
odoo
-

The second one

Avatar
odoo
-

You can use Odoo's record rules.

Avatar
odoo
-

Please refer this docs https://www.odoo.com/documentation/8.0/reference/security.html.

If you have any problem implementing it please post a new question for it

2 Answers
0
Avatar
odoo
Best Answer

Hi,

It is possible in Odoo. Suppose if this is the case means, for group X users have to view the view A, for group Y have to view the view B and for group Z have to view the view C.


What you can do is that you can call the python function from the menu item and check the current user's group and return the view accordingly from the python function.


Calling python function from menu,

<record id="action_test" model="ir.actions.server">
<field name="sequence" eval="5"/>
<field name="state">code</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_product_template"/>
<field name="code">action = model.test_function()</field>
<field name="condition">True</field>
<field name="name">Test</field>
</record>

<menuitem id='menu_test' name='Test' sequence="20" parent="purchase.menu_procurement_management"
action="action_test"/>


Python function,

class ProductTemplate(models.Model):
_inherit = 'product.template'

@api.model
def test_function(self):
action = self.env.ref('test_action').read()[0]
kanb_view_id = self.env.ref('product.product_template_kanban_view').id
form_view_id = self.env.ref('product.product_template_only_form_view').id
tree_view_id = self.env.ref('product.product_template_tree_view').id
action_context = safe_eval(action['context'])
action['views'] = [
[kanb_view_id, 'kanban'],
[tree_view_id, 'tree'],
[form_view_id, 'form']
]
action['context'] = action_context
return action


Thanks


1 Comment
Avatar
Discard
Avatar
odoo
-

Works on odoo18 as well.
Thanks for the code

0
Avatar
odoo
Best Answer

Simple View:

Detailed View:

Avatar
Discard