Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can I restrict a model's tree view by some domain?

By
Ben Olsen
on 7/24/14, 11:22 AM 3,302 views

I've set up a simple tree view, which was pretty easy, but now I want to restrict the items in that tree view based on something like a domain. More specifically, I've created a page so users can view past timesheets (from hr_timesheet_sheet), but I only want them to be able to see their own past timesheets in the tree view. The basic tree view is like this:

    <record id="past_timesheet_tree" model="ir.ui.view">

        <field name="name">hr_timesheet_sheet.sheet.tree</field>
        <field name="model">hr_timesheet_sheet.sheet</field>
        <field name="arch" type="xml">
            <tree string="Past Timesheets" create="false" edit="false" delete="false">
                <field ... />
                <field ... />
            </tree>
        </field>
    </record>

 

Unfortunately it looks like I can't add a domain attribute to the <tree> tag. Also, I don't want to just create a default filter, because then users would be able to remove that filter and see all the timesheets. I need this view to completely restrict users to only view items that belong to them. I can't think of any examples of where this happens in the system, so I'm hoping someone here will have an idea.

 

(On an unrelated meta note, I indented my code block with 4 or more spaces, but I'm not getting code formatting. Is there something else I can do to put it in a code block?)

2

Ray Carnes

--Ray Carnes--
15677
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 7/24/14, 3:55 PM

A better solution is to add an Access Right rule to the 'Employee' group for the model.

[('user_id', '=', user.id)]

This prevents users from seeing other users timesheets, unless they are "Officers" or "Managers".

  • Navigate to Settings -> Users -> Groups
  • Open the Employee Group
  • Navigate to the Rules tab and Click Add
  • Click Create
  • Fill out the rule like this (Timesheet here is hr_timesheet_sheet.sheet)
  • Add the Employee group to this rule:
  • Click Save and Close.
  • Click Save.

 

 

 

Brilliant, thanks Ray! You're right, that's much more like what I was looking for. I knew there had to be a fairly straightforward way to do it, I was just going the wrong direction. Your answers on here are always extremely helpful.

Ben Olsen
on 7/24/14, 5:51 PM
0
Juan José Scarafía
On 7/25/14, 8:43 AM

Hi

The domain must be limited in the "action window related to the menu". But perhups, the right way would be to add a domain restriccion in "acces rules".

Regards,

Juan José - Ing ADHOC

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/24/14, 11:22 AM
Seen: 3302 times
Last updated: 3/16/15, 8:10 AM