Improve copy() to make it more flexible
Currently a call to copy() returns the new records created but in some cases it is not ideal because it'd be better to work on batch (only one defaults can be given).
An example is at [1]
So we have a couple of possibilities:
- Use copy(records, defaults, records, defaults, **) just like write()
- Make copy more active record oriented. Something in the lines:
def copy(cls, records, defaults=None):
new_records = super(X, cls).copy(records, defaults)
for new_record in new_records:
if new_record.one_field == 'some value':
new_record.another_field = None
return new_records
And use it like this:
new_records = Model.copy(records)
for new_record in new_records:
new_record.code = random()
Model.save(new_records)
I personally would try the second option as only one write operation is executed.
[1] https://tryton-rietveld.appspot.com/26311002/diff/20001/production.py