openerp-india team mailing list archive
-
openerp-india team
-
Mailing list archive
-
Message #06830
[Bug 930127] 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
** Changed in: openobject-addons
Importance: Undecided => Low
** Changed in: openobject-addons
Status: New => In Progress
** Changed in: openobject-addons
Assignee: (unassigned) => OpenERP R&D Addons Team 2 (openerp-dev-addons2)
** Summary changed:
- [6.1] [delivery] method create_grid_lines should support request with id or ids
+ [6.1] [delivery] delivery.carrier.write() fails to handle ids=int case
--
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/930127
Title:
[6.1] [delivery] delivery.carrier.write() fails to handle ids=int case
Status in OpenERP Addons (modules):
In Progress
Bug description:
Hello,
In the module delivery, the method create_grid_lines breaks if there
is a write request with only one id.
I propose the following patch to solve the problem.
=== modified file 'delivery/delivery.py'
--- delivery/delivery.py 2012-01-31 13:36:57 +0000
+++ delivery/delivery.py 2012-02-10 12:22:58 +0000
@@ -98,6 +98,8 @@
return False
def create_grid_lines(self, cr, uid, ids, vals, context=None):
+ if isinstance(ids, int):
+ ids = [ids]
if context == None:
context = {}
grid_line_pool = self.pool.get('delivery.grid.line')
Best regards,
Benoît
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/930127/+subscriptions
References