We sell a dashboard module for Odoo and ship it for seven versions, 14 through 20. Same features, one codebase, a small script that rewrites the bits that differ. Most of the port is boring. A few things are not, and they cost us hours each time, so here is the list.
safe_eval changed shape in 19.
Up to 18 you call safe_eval(code, ctx, mode='exec', nocopy=True) if you want the script to change your context. In 19 the signature is safe_eval(expr, /, context, *, mode) and it updates the dict in place, nocopy is gone. We just try the old call and fall back on TypeError:
try:
safe_eval(code, ctx, mode='exec', nocopy=True) # <= 18
except TypeError:
safe_eval(code, ctx, mode='exec') # 19+
Users: groups_id became group_ids.
Any test that creates a user with groups breaks. 'group_ids' if 'group_ids' in Users._fields else 'groups_id' fixes it without version checks.
Binary fields in 20 are not base64 anymore.
Reading record.file gives you a BinaryValue with the raw bytes. Writing plain bytes in a test fails with "use BinaryValue instead of bytes". We now read with base64.b64decode(f) if isinstance(f, (bytes, str)) else bytes(f).
Recursion checks.
_check_recursion() is replaced by _has_cycle() from 17. Easy, but it fails silently in a constraint if you forget.
The frontend is the real port.
14 to 16 still ship Chart.js 2. Options like plugins.legend and indexAxis simply do nothing there, so a horizontal bar quietly renders vertical. We keep two chart config builders and the port script swaps them. Also /** @odoo-module */ must be the first line on 15/16. Our script once wrote that header and emptied the file in the same line (open for write before reading). The module installed fine and one button was just missing. Test the UI, not only the Python.
Our routine now
- Build on 19, write tests there.
- Run the port script per version, run the tests on 15 to 20.
- Open the UI on the oldest and newest version and click through.
If you want to see where all of this ended up, the module is Dashboard Studio Pro: https://technoversesystems.com/odoo-dashboard-studio . We do Odoo work at Technoverse Systems (https://technoversesystems.com), happy to compare notes in the comments.
Top comments (0)