This question has been flagged
2 Replies
2638 Views
class PartnerSales(models.Model):
_inherit = "res.partner"
    cuid = fields.Integer(string="Get Current User ID", compute="_dp_cuid")
    cspid = fields.Integer(string="Get Current Sale Person ID", related="user_id.id")

    @api.depends("cuid")
    @api.one
    def _dp_cuid(self):
    self.cuid = self.env.user.id
<?xml version="1.0" encoding="UTF-8"?> 
<odoo>
<record id="view_dham_customers_form" model="ir.ui.view">
<field name="name">KSK DN</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='email']" position="attributes">
<attribute name="attrs">
{'invisible': [('cspid','=', 'cuid')]}
</attribute>
</xpath>
</field>
</record>

Email field is not hidden. How to fix it?

Thanks in advance.








Avatar
Discard
Best Answer

Hi DHA, 

cspid = fields.Integer(string="Get Current Sale Person ID", related="user_id.id", store=True)


Second Question :

For that i would suggest the following logic : 
1- create a boolean like this : 

        is_salesperson = fields.Boolean(compute='compute_is_salesperson', store=True)
@api.multi
@api.depends('user_id')
def compute_is_salesperson(self):
user = self.env.user
  for record in self:
     if record.user_id and record.user_id.id == user.id : 
            return True

and in your xml field Email declaration you add attribute attrs like this : 

 attrs="{'invisible': [('is_salesperson','=', True)]}"

And of course the declaration of your boolean if form view : 

<field name="is_salesperson" invisible="1"/>

Upvote if this helps! 
Thank you.








Avatar
Discard
Author Best Answer

i.imgur.com/qfhE2fr.png

If SalePerson == CurrentUserId:

    Email = Hidden

    Phone = Hidden

Everyone has methods.

Thanks.

Avatar
Discard

Please upvote if any of the answers work(s) for you. That encourages the community to keep answering questions or at least making efforts :)

Please read Second Question section in my previous answer ;)

Author

I have tested it but not working

what value does is_salesperson get in your form view ? (you can make it temporarely visible to see its value)