Odoo Add domain for a field only in create view
<p>In my module I have to create a view to set goals for departments. In create form view there is a dropdown (many2one field related to hr.department) with selection widget to select the department. I have 2 requirements:</p>

<ol>
<li>Departments dropdown should be filtered.</li>
<li>Filtration should only occur in create view.</li>
</ol>

<p>I tried with <code>fields_view_get</code> and its working fine for the create view. But the problem is filtration occurs in both form view and form update :(</p>

<p>This is my code used in <code>fields_view_get</code>:</p>

<pre><code>def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    result = super(hr_appraisal_goal_department, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)

    if view_type=='form':
        current_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
        dept_ids = []
        for groups in current_user.groups_id:
            if groups.name == "Define All Departmental Goals":
                dept_ids= self.pool.get('res.users').search(cr, uid, [])
            elif groups.name == "Define Departmental Goals Only to My Own Department":
                dept_ids.append(current_user.employee_ids.department_id.id)

            #there may be additional conditions in future 

        doc = etree.XML(result['arch'])
        nodes = doc.xpath("//field[@name='department_id']")
        for node in nodes:
            node.set('domain', "[('id', 'in',["+','.join(map(str, dept_ids)) +"])]")
            result['arch'] = etree.tostring(doc)

    return result
</code></pre>

<p>Thanks for a kind help.</p>