How to change the selection in an OpenERP selection box based on other field values?

I have a form with four fields:

  • Cropping - choice
  • Active From - Date
  • Active date -
  • Block Area - Select

How to make available parameters in the block area dependent on the values ​​that the user selects for other fields?

+4
source share
3 answers

I don’t know if you can do this with a selection field, but you can change the domain of a multi-valued field when another field changes value. You can also just use other fields in the domain of the BlockArea field and not change it at all. See how the partner address screen sets the domain for the state_id field. You may find this related question helpful.

If you need to change the domain when another field changes, then the on_change event may include a domain entry in the dictionary that it returns.

I found a discussion thread that says you can use the select widget in the many-to-one field so that it can work if you set the domain field. I have not tried it myself.

+3
source

To limit the available options based on other field values, you can use domain . For example, this is used in the standard project_issue module:

Quoting the corresponding lines:

 class project_issue(crm.crm_case, osv.osv): _columns = { 'project_id':fields.many2one('project.project', 'Project'), 'type_id': fields.many2one ('project.task.type', 'Stages', domain="[('project_ids', '=', project_id)]"), } 

In this example, the available type_id parameters type_id selected from the project.task.type table depending on the value of the project_id field.

+1
source

Try the on_change function .. create the on_change function and at the end of the function return the domain condition for the block_area field for example

 def onchange_for_block_area(self,cr,uid,ids,crop,from_date,to_date,context): domain=[] # #some statements for finding the domain # return {'domain':{'block_area': domain}} 

provides an onchange function for crop, from_date and to_date fields

+1
source

Source: https://habr.com/ru/post/1383859/


All Articles