Comment 1 for bug 930127

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote : Re: [6.1] [delivery] method create_grid_lines should support request with id or ids

Hello Benoit,

I think you indeed face a bug, but the proposed solution is not correct.

All exposed OpenERP API methods (all the model methods that can be used through XML-RPC) are only supposed to work on batches, and must accept a list of IDs as parameters. There are a few exception such as some core ORM methods giving greater flexibility by accepting a single integer/long parameter too, but that is a case-by-case exception, and in fact it is a legacy and discouraged thing to do, because it forces all overriders to copy/paste the same boilerplate code everywhere.
This bad practice is the very reason for the bug... for example if you are calling write() on delivery.carrier with a single ID it will fail because the overridden write() on delivery.carrier does not properly care for it - not because of create_grid_lines() which is correct.

When a method is supposed to compute something it's even worse because the return value will change depending on the parameters (e.g. read() or browse() have a variable result type, that's not very good for consistency)
In general we would like to avoid repeating these lines everywhere and have a consistent API: all methods should work on a list of IDs.

I suggest to fix this by correcting the overridden delivery.carrier.write() instead. In most cases it will also be trivial to call write() with a list of IDs instead of a single value!

Thanks for reporting