Community mailing list archives

community@mail.odoo.com

Re: hide product price for a specific category for some users[V8]

by
dom
- 05/19/2016 20:09:26

Hi Emna,
Good to hear that it solved your problem.
By the way, you shouldn't need the api.onchange decorator

Cheers,

On 20 May, 2016 4:52 am, "Emna Ragheb" <ragheb.amna@gmail.com> wrote:
Hi everyone !! 

Finally I've find the solution and it works fine , thank you for "Dominique KON-SUN-TACK" his suggestion helped me , so here is what I did : 

from openerp import models, api, fields


class custom_product(models.Model):
    _name = 'product.template'
    _inherit = 'product.template'
    
    @api.onchange('show')
    def _evaluate_show(self):
        
        if self.categ_id.id == 8:
                if self.env['res.users'].has_group('account.group_hr'):
                    self.show = True
                else:
                    self.show = False
            
        else:
            self.show = True
        
    
    show = fields.Boolean('show', compute='_evaluate_show', default=True)

And in my xml file : 

<record id="product_price_visibility_form_view" model="ir.ui.view">
            <field name="name">product.price.form.inherit</field>
            <field name="model">product.template</field>
            <field name="inherit_id" ref="product.product_template_form_view" />
            <field name="arch" type="xml">

            <xpath expr="/form/sheet/notebook/page/group/group/field[@name='list_price']" position="attributes">
                     <attribute name="attrs">{'invisible': [('show', '=', False)]}</attribute>
            </xpath>
          </field>
</record>


Thank you !! 

------------------------------------------------------------------------------------

Greetings ,

Emna RAGHEB 

Odoo Techno-functional Consultant



2016-05-19 14:46 GMT-04:00 Emna Ragheb <ragheb.amna@gmail.com>:
Hi, 

I've tried your suggestion  but now the field is always invisible for all categories and all users even the administrator here is my code : 

from openerp import models, api, fields
from openerp import SUPERUSER_ID

class custom_product(models.Model):
    _name = 'product.template'
    _inherit = 'product.template'
    
    def _evaluate_show(self, cr, uid, ids, context=None):
        res={}
        for product in self.browse(cr,uid,ids,context=context):
            if (product.categ_id.id == 8):
                if uid != SUPERUSER_ID and not self.pool['res.users'].has_group(cr, uid, 'account.group_bank_stmt_verifier'):
                    res[product.show] = False
                    
            res[product.show]=True
        
        return res
    
    
    show = fields.Boolean('show', compute='_evaluate_show', default=True)

and in the .xml I did this : 

  <xpath expr="/form/sheet/notebook/page/group/group/field[@name='list_price']" position="attributes">
                     <attribute name="attrs">{'invisible': [('show', '=', False)]}</attribute>
   </xpath>


Could you please help me to find what i did wrong in my code or what should I change .

'' in my case ; there is a category named ressource in wich we put all the employees and we need to hide all the prices for all users but 2 and ordninary users must see the prices for others products''


Thank you !! 

------------------------------------------------------------------------------------

Greetings ,

Emna RAGHEB 

Odoo Techno-functional Consultant



2016-05-16 10:20 GMT-04:00 Dominique KON SUN TACK <dominique.k@elico-corp.com.sg>:

To do what you want, you can create a field e.g.

-          show = fields.Boolean(‘show’, compute=’_evaluate_show’, default=False)

-          The _evaluate_show function can return True or False, depending on the group of the user

-          Then you can add in the xml of the view: attrs = “{‘invisible’: [(‘show’,’=’,false)]}”

 

Cheers,

 

Dominique KON-SUN-TACK

 

From: Emna Ragheb
Sent: Monday, May 16, 2016 10:13 PM
To: Community
Subject: hide product price for a specific category for some users[V8]

 

Hello Community , 

 

I would like to hide the product price for some users in a specific category , I've tried this code in the product view: 

 

<field name="price_list" groups="account.group_account_manager" attrs="{'invisible': ["[('categ_id', '=', 17)]}" />

 

the field is invisible only for this category but it is invisible for the account manager group as well , how could I make it visible for them.

 

 

Thank you !! 

------------------------------------------------------------------------------------

Greetings ,

Emna RAGHEB 

Odoo Techno-functional Consultant

http://s.c.lnkd.licdn.com/scds/common/u/img/webpromo/btn_liprofile_blue_80x15_fr_FR.png

_______________________________________________
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