+5 votes

 def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):

res = super(ClassName, self).fields_view_get(view_id, view_type, toolbar=toolbar, submenu=submenu)

###code here

return res
in Back-end by (410 points) | 1.3k views

1 Answer

+4 votes
you can add a domain in the method   "fields_view_get"
like this example : 
class ClassName(models.Model):
    _inherit = 'model.name'

    def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
            Add domain 'allow_check_writting = True' on journal_id field and remove 'widget = selection' on the same
            field because the dynamic domain is not allowed on such widget
        if not context: context = {}
        res = super(ClassName, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
        doc = etree.XML(res['arch'])
        nodes = doc.xpath("//field[@name='journal_id']")
        if context.get('write_check', False) :
            for node in nodes:
                node.set('domain', "[('type', '=', 'bank'), ('allow_check_writing','=',True),('your_field','=','value')]")
                node.set('widget', '')
            res['arch'] = etree.tostring(doc)
        return res
by (8.8k points)
204 questions
180 answers
214,110 users