Skip to Content
Menu
This question has been flagged
1 Reply
2001 Views

Hello everyone,

I have inherite pos.config model, adding a field many2one for user.groups, that user will choose a group, base on this field, I will hide some pos button in pos,

my pos.config looks like this:

from odoo import api, fields, models

class PosConfig(models.Model):
    _inherit = 'pos.config'
    groups_id = fields.Many2one('res.groups'string='Allow groups')


Have add it in the pos.config sucessfully,  can give it a value, I want to compare this group with the current group ids for current user, if this group is in the current groups I will show fields, otherwise no.

So in pos.xml template, in NumpadWidget widget, I use this:

           <t t-foreach="widget.pos.user.groups_id" t-as="gr">
    
               <t t-if="widget.pos.config.groups_id == gr">
                    <p> it is ok</p>
                </t>  
            </t> 


the issue is:

widget.pos.user.groups_id shows only ids, so gr only id
widget.pos.config.groups_id shows (id, name)


I need to get id for both, or get name for both.


Can someone help me?


Thanks

Avatar
Discard
Author Best Answer

Hi all,

I have resolved the issue, both are tuples so both can be iterate with foreach, here the solution in case:

            <t t-set="i" t-value="0"/>            
            <t t-foreach="widget.pos.config.groups_id" t-as="gr">
                <t t-if = "i == 0">
                    <t t-foreach="widget.pos.user.groups_id" t-as="gr1">
                        <t t-if="gr1 == gr">
                            <t t-set="invisible" t-value="0"/>
                        </t>
                    </t>  
                </t>
                <t t-set="i" t-value="1"/> 
            </t> 
Avatar
Discard
Related Posts Replies Views Activity
2
Mar 24
598
3
Jan 25
3274
3
Apr 21
13330
1
Apr 16
2867
1
Feb 25
879