In the odoo environment it seems relatively simple to compute the priority.
Once in developer mode, I simply create a new custom field with the dependencies and it works just fine.
<------------------------------->
field = x_priority : My selection field with the values [(low), (normal), (high), (higher), (highest)]
With the dependencies: [has_cc, arc, location] with either boolean or integer (location =0-4) values.
Now here my (working) code:
try:
for record in self:
if (record.has_cc) and (record.arc) and (record.location) >= "3":
record['x_priority'] = "4"
elif (record.has_cc) and (record.location) >= "3":
record['x_priority'] = "3"
elif (record.arc) and (record.location) >= "3":
record['x_priority'] = "3"
elif not (record.has_cc) and (record.location) >= "3":
record['x_priority'] = "2"
elif (record.location) == "2" or (record.location) == "1":
record['x_priority'] = "1"
else:
record['x_priority'] = "0"
except: None
<----------------------------------------------------->
well, so far so good.
Now here my Problem:
How can I adapt this into working python code?
I tried the following in my model:
priority = fields.Selection(compute='_compute_priority', default='0', readonly=True)
@api.depends('has_cc', 'arc', 'location')
def _compute_priority(self):
try:
for record in self:
if (record.has_cc) and (record.arc) and (record.location) >= "3":
record['priority'] = "4"
elif (record.has_cc) and (record.location) >= "3":
record['priority'] = "3"
elif (record.arc) and (record.location) >= "3":
record['priority'] = "3"
elif not (record.has_cc) and (record.location) >= "3":
record['priority'] = "2"
elif (record.location) == "2" or (record.location) == "1":
record['priority'] = "1"
else:
record['priority'] = "0"
except:None
This will result to stop (overload the server immidiately)
Anyone who can tell me what I am missing here?
Maybe there is also a complete different way to compute priority?