On 19/06/13 16:00 +0200, Guillem Barba Domingo wrote: > 2013/6/19 Cédric Krier <[email protected]> > > > Hi, > > > > In the same idea as the changeset [1], I would like to propose this > > change for the write method: > > > > sounds good > > > > @classmethod > > def write(cls, records, values): > > … > > > > => > > > > @classmethod > > def write(cls, records, values, *args): > > assert not len(args) % 2 > > all_records = [] > > actions = iter((records, values) + args) > > for records, values in zip(actions, actions): > > … > > all_records += records > > > > cls._validate(all_records) > > > > I don't understand the treatment of 'actions'. Which extra arguments can be > expected?
The same as two first:
write(cls, records, values, records, values, …)
> This has two advantages:
> >
> > - call validate for a larger set of records which will benefit of
> > the prefetching
> > - reduce the number of RPC calls
> >
>
> The only cons I found is if you want to set a value (the same) to a lot of
> records (for example, set the state of a list of 'order' records after
> processed their lines.
Just use the write as now.
> But I understand that there are more cases where it is an improvement.
>
> It could be possible to get this behaviour using 'active record'?
> An usage example:
>
> for move in todo_moves:
> move.quantity += 3
> ...
> save(todo_moves)
Yes from a One2Many if we take care of it.
Otherwise the code will need to be written like this:
Move.write(*chain(*(([m], m._save_values) for m in todo_moves)))
--
Cédric Krier
B2CK SPRL
Rue de Rotterdam, 4
4000 Liège
Belgium
Tel: +32 472 54 46 59
Email/Jabber: [email protected]
Website: http://www.b2ck.com/
pgpleViasvdcI.pgp
Description: PGP signature
