This question has been flagged
2 Replies
5873 Views

Hello , I'm trying to create a custom fields that depends of other Fields. A custom field selection shows only data of other fields that i select previously.

I created a custom model called x_business.center with two fields called x_partner ( man2one to res.partner ) and x_name (char) as shown in the picture :

Image #1: http://es.zimagez.com/zimage/p1344.php

On the other hand I added a custom field called x_costcenter (many2one to x_business.center) sale.order model as shown in the picture :In Form view sale.order ( sale.order.form ) I added the x_costcenter field as shown in the picture :

Image #2: http://es.zimagez.com/zimage/p2254.php

I want to do is that the field Cost Center depends of Customer, in other words , the customer that i select, the Cost Center field shows only the Cost Centers that Customer , I don't want all cost centers are displayed.

Image #3: http://es.zimagez.com/zimage/p3184.php

Image #4: http://es.zimagez.com/zimage/p4158.php

That is all. I want to thank you for your time and dedication . Thanks I'll be waiting anxiously your advices and proposals. :)

Avatar
Discard
Best Answer

In sale order formview, Just add domain in you custom field 

....
<field name="x_costcenter" domain="[('x_partner','=',partner_id)]"/>

Avatar
Discard

how to do this in web site forms in odoo 12 using controllers.

Best Answer

I'm trying to understand what exactly you wanted to achieve :)

I was thinking how you can do it. In my case I've done something like this but in slightly complicated manner.

Created a few classes then depending on the value in first field second field is loading data from specific table then based on the value from second third is loaded and so on.

but I've had to create also a load of records in each of the classes.

For example if I choose Computer, next field loads data from table computers, then if I choose brand, next field loads data about model of this brand, then size and data about computers/model will be loaded and so on.


Avatar
Discard