跳至内容
菜单
此问题已终结
2 回复
3721 查看
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.








形象
丢弃
最佳答案

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.








形象
丢弃
编写者 最佳答案

i.imgur.com/qfhE2fr.png

If SalePerson == CurrentUserId:

    Email = Hidden

    Phone = Hidden

Everyone has methods.

Thanks.

形象
丢弃

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

编写者

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)

相关帖文 回复 查看 活动
2
1月 24
14339
2
4月 17
3306
1
5月 16
3481
4
2月 25
2316
1
8月 24
1963