Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
3727 Vizualizări
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.








Imagine profil
Abandonează
Cel mai bun răspuns

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.








Imagine profil
Abandonează
Autor Cel mai bun răspuns

i.imgur.com/qfhE2fr.png

If SalePerson == CurrentUserId:

    Email = Hidden

    Phone = Hidden

Everyone has methods.

Thanks.

Imagine profil
Abandonează

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 ;)

Autor

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)

Related Posts Răspunsuri Vizualizări Activitate
2
ian. 24
14341
2
apr. 17
3307
1
mai 16
3484
4
feb. 25
2319
1
aug. 24
1965