Py File
class DailyLog(models.Model):
_name = "daily.log"
_inherit = "mail.thread"
_order = "id desc"
@api.multi
def _current_user_get_fnc(self):
self.current_user = self.env.user.id
user_id = fields.Many2one('res.users', 'Assign to', track_visibility='onchange', default=lambda self: self.env.user, index=True)
current_user = fields.Many2one('res.users', 'Current User', compute='_current_user_get_fnc', store=False)
View file
<record id="daily_log_form_view" model="ir.ui.view">
<field name="name">daily.log.form</field>
<field name="model">daily.log</field>
<field name="arch" type="xml">
<form string="Daily Log">
<sheet>
<group>
<group>
<field name="user_id" options='{"no_create": True}' context="{'user_preference': 1}"/>
</group>
<group>
<field name="current_user"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
<record id="daily_log_form_view_inherited" model="ir.ui.view">
<field name="name">daily.log.form.inherited</field>
<field name="model">daily.log</field>
<field name="inherit_id" ref="crm_debranding.daily_log_form_view"/>
<field name="groups_id" eval="[(6,0, [ref('crm_base_debranding.group_telesales')])]" />
<field name="arch" type="xml">
<xpath expr="//form/sheet//field[@name='name']" position="attributes">
<attribute name="attrs">{'readonly': [('user_id', '!=', create_uid)]}</attribute>
</xpath>
</field>
</record>
The best method would be using the invisible field which holds the user id, and in attrs you can easily compare them
Thanks Hilar for response. It will not work, i tried that too.