Skip to Content
Menu
This question has been flagged
6 Replies
8532 Views

Hi comunity,

I am trying to create a module containing the following features:

- It is composed just with one Model. This model contains 3 status A, B and C.

- There are 3 groups X, Z and Y. 

-Depending on the group, there will be a view. Group X only can view the model in status A view, group Y just the can view the model in status B.


 For that, I am thinking on creating a view for each group.  Is that possible?


Kind Regards

Avatar
Discard

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

Author

The second one

You can use Odoo's record rules.

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

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


Avatar
Discard
Best Answer

Simple View:

https://i.imgur.com/qhAiKJa.png


Detailed View:

https://i.imgur.com/mdSWcwx.png

Avatar
Discard