Skip to Content
Menu
This question has been flagged
2 Replies
39279 Zobrazenia

Hi All,

I have fields,

owner_user_id = fields.Many2one('res.users', string='Assignee')

project_name = fields.Char('Project Name')

project_manager = fields.Many2one('res.users', string='Project Manager',index=True, track_visibility='always')

remarks = fields.Char('Remarks', size=100)


I need in my view for perticular assignee if i enter project name in field project manager should be mandatory.

If Project name is not entered for that assignee remarks should be mandatory?

How can i achieve this??


Thanku

Avatar
Zrušiť
Best Answer

Hello Savita,


By using 'attrs' attribute we can do it. you can see the following code


<field name="project_manager" attrs="{'required': ['|',('project_name','!=', False),('project_name','!=', '')]}"/>


<field name="remarks" attrs="{'required': ['|',('project_name','=', False),('project_name','=', '')]}"/>

<field name="owner_user_id" attrs="{'required': ['|',('project_name','=', False),('project_name','=', '')]}"/>


if the above code is not working you can try the following code.

declare a new Boolean field  'required_condition'


@api.multi

def onchange_project_name(self)

for rec in self:

if rec.project_name:

required_condition = True

else:

required_condition = False


<field name="project_manager" attrs="{'required': [('required_condition','=', True)]}"/>

<field name="remarks" attrs="{'required': [('required_condition','=', False)]}"/>

<field name="owner_user_id" attrs="{'required': [('required_condition','=', False)]}"/>

Avatar
Zrušiť

Thank you for the answer. In case someone needs to exchange the "|" with "&" and gets an XML error: You need to replace '&' with '&amp;' in this case

Best Answer

Hi,

Try this in your xml file

<field name="project_manager" attrs="{'required': [('project_name','!=', False)]}"/>

<field name="remarks" attrs="{'required': [('project_name','=', False)]}"/>


Avatar
Zrušiť