Skip to Content

Welcome!

Share and discuss the best content and new marketing ideas, build your professional profile and become a better marketer together.

Sign up

You need to be registered to interact with the community.
This question has been flagged
1 Reply
36 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

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

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!