I am trying to create a server action via the Odoo UI that will alter the domain of another field in the view. This seems to be a pretty common use-case when dealing with the Odoo source code as you can see in the following documentation:
https://www.odoo.com/documentation/10.0/reference/orm.html#odoo.api.onchange
In those docs, they indicate that if I were in the source code of the model, I can define an onchange
method and return a domain, for example, the behavior I'm trying to accomplish in the sale.order.line
model would be:
@api.onchange('product_id')
def _onchange_product(self):
return {
'domain': {'route_id': [('id', 'in', x_all_route_ids.ids)]}
}
In other words, when the product of an sales order line changes, update the available options in the route_id field.
Is there any way to accomplish this same thing via a server action created through the UI? I am having trouble figuring out how to return a domain from the Python code.
The notes in the code section say:
# Available variables:
# - time, datetime, dateutil, timezone: Python libraries
# - env: Odoo Environement
# - model: Model of the record on which the action is triggered
# - record: Record on which the action is triggered if there is one, otherwise None
# - records: Records on which the action is triggered if there is one, otherwise None
# - log : log(message), function to log debug information in logging table
# - Warning: Warning Exception to use with raise
# To return an action, assign: action = {...}
I don't see how I can use this to return a domain. Does anybody have any idea?
I have tried setting the python code field to simply:
domain = {'route_id': [('id', 'in', record.x_all_route_ids)]}
But that doesn't work. The route_id list is unchanged.