I am using odoo 10e. What i want to do is i want to set domain criteria inside fields_view_get
method
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(Customer, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
doc = etree.XML(res['arch'])
if view_type == 'tree':
if self.env.user.partner_id.parent_id.id is False:
id = self.env.user.id
else:
id = self.env.user.partner_id.parent_id.id
doc.attrib['domain'] = "[('custodians','='," + str(id) + ")]"
for node_form in doc.xpath("//tree"):
node_form.attrib['duplicate'] = '0'
res['arch'] = etree.tostring(doc)
for node_form in doc.xpath("//form"):
node_form.attrib['duplicate'] = '0'
res['arch'] = etree.tostring(doc)
return res
this is what i did tried. But its not working. You can see why i want to set domain from backend because i have to set user_id based on condition.
Please let me know if i am doing wrong or is there any better way.
Edit
I have defined custodians fields as follow
custodians = fields.Many2one('res.users', string="Custodian", domain=[('groups_id', 'in', [12])],
readonly=[('readonly_custodian', '=', True)])
actually when ever a loggedin user create a Customer
records we set him as a custodian for that Customer
and all i want to do is when that user loggin again he should be able to see his and his parent custodian records
fields_get
. What exactly are you trying to achieve? – traviswif view_type == 'tree'
. This is the condition i want to achieve in domain – Ancient