Community mailing list archives

community@mail.odoo.com

Re: Many2one field filter using child_of user login

by
Togar
- 09/08/2015 13:35:44
Boom.. I didn't read your last message when I sent the mail. Sorry :D

On Wed, Sep 9, 2015 at 12:34 AM, Togar Hutabarat <to.garnet@gmail.com> wrote:
Hi,

If so, you can just put the domain on xml file (instead of python).

First, delete "domain" thing from your python code. Then, add domain to the XML line where you call the field (responsible_id).

<field name="responsible_id" domain="[('parent_id','=',uid)]"

Hope it works. 

On Tue, Sep 8, 2015 at 8:53 AM, vak0160 <vak0160.work@gmail.com> wrote:

Hello Togar,

I have a model with a field for responsible user (responsible_id). The creator can only choose any user below him. I have modified the res.users model to have parent_id field.

This is my code:

class ResUser(models.Model):
    _inherit = "res.users"

    parent_id = fields.Many2one("res.users")

class WorkOrder(models.Model):
    _name = "mymodule.work.order"

    name = fields.Char("Work Order Numbers", required=True)
    duration = fields.Float("Duration (Hours)", required=True)

    responsible_id = field.Many2one(
        "res.users", required=True,
        domain="[('id', 'child_of', user.id)]"  # this caused an error when I open the combo box.
    )

On 09/07/2015 07:24 PM, Togar Hutabarat wrote:

<blockquote cite="mid:CAD=nRr7LPfijVjs9_X8j7rBdHK=MrweiGaf2ScRwpsO584rTeg@mail.gmail.com" type="cite">
Hi,

Hmm.. Could you please share and explain your code?

On Mon, Sep 7, 2015 at 9:44 AM, vak0160 <vak0160.work@gmail.com> wrote:

Hello Togar,

Sorry for the late reply. I followed your suggestion of having relation to res.users in res.users model named parent_id, but I still get the same error with this domain: [('id', '=', user.id)] on my own model.

Is there any other solution? I just want to limit the res.users relation field in my model to child_of the current user login.

On 09/04/2015 04:15 PM, Togar Hutabarat wrote:
<blockquote cite="mid:CAD=nRr5ba_3pk_OPbOOGZF4Em1vF20FFFhmoRJ8Amyt-gv4jFg@mail.gmail.com" type="cite">
You need to add one additional many2one field on res.users, referenced to res.users itself, and the field name must be 'parent_id'. I guess that is the requirement of using child_of things.

On Fri, Sep 4, 2015 at 2:08 PM, vak0160 <vak0160.work@gmail.com> wrote:

Hello Community,


I have  a Many2one field
referenced to model res.users,
and I want this field filtered using child_of current
user login.


I already tried with
[('id', 'child_of',
user.id)]
but it gives me an error:


Error: NameError: name 'user' is not defined.



Is there any way to accomplish this?




-- 
Regards,
Andre



_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe





_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe






-- 
Regards,
Andre

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe

-- 
Regards,
Andre

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe