[FIX] base_automation: avoid key error when trying to return a warning
Before the refactoring introduced at 0a744ac, it was possible to return
a warning from a `code`-type base automation with the `action` variable:
```py
if len(record.name) > 20:
action = {
"warning": {
"title": "Name too long",
"message": "The name of the record is too long",
}
}
```
This would trigger a visual dialog with the title and message in the
client.
Due to a louche `+=` operator change in the refacto, this kind of
automation raises a key error on the server, as the additive part of
the operator will try to access the 'warning' key in the result dict,
which may not (and usually will not) exist.
I assume this was done in an attempt to 'accumulate' warnings, but the
warnings in questions are dict that are not really additive anyway.
Better to support the *last* returned warning rather than none at all.
This commit basically returns to the previous situation for onchange
warnings.
closes odoo/odoo#148140
Signed-off-by: Bouvy Damien (dbo) <dbo@odoo.com>
This commit is contained in:
@@ -805,7 +805,7 @@ class BaseAutomation(models.Model):
|
||||
if 'domain' in res:
|
||||
result.setdefault('domain', {}).update(res['domain'])
|
||||
if 'warning' in res:
|
||||
result['warning'] += res["warning"]
|
||||
result['warning'] = res["warning"]
|
||||
return result
|
||||
|
||||
return base_automation_onchange
|
||||
|
||||
Reference in New Issue
Block a user