odoo-dev/odoo — pull request #17 by odony (2014-06-27 14:39:07+00:00)
Title: orm/models, fields: new @copy attribute for fields, o2m not copied by default

Introduction of a new `copy` attribute for all fields, both in the new and old API. Depending on the value
of this attribute, the field will be copied or discarded during a record copy() operation.

The value of `copy` defaults to True for all fields except computed fields (`fields.function` in the old
API, or any field witth a `compute` attribute in the new API) and one2many fields (fields.one2many / fields.One2many), which both default to False.

This represents an important change for One2many fields, as they used to be copied by default. This was a source of dangerous bugs, as one2many fields do not always represent composition/ownership relationships.
When they do not, duplicating the o2m lines often lead to unwanted duplication of other records.

As of v8 one2many copy will be opt-in, so any declaration of a one2many field that should be copied (typically a "line" object) will have to be explicitly done with copy=True:

line_ids = fields.One2Many(order.line, order_id, string="Lines", copy=True)

For all other fields, `copy=False` can be used to easily reset/skip the field during duplication.
This is something that used to require an explicit override of the copy() method.

All modules/apps were updated to add an explicit copy=True parameter for one2many fields that do need
to be copied (e.g. Sales Order lines, etc.).
Whenever possible overridden copy/copy_data methods were dropped and replaced by extra
`copy=False` parameters.

Next step: we might remove 80% of the remaining use cases for overriding copy() if we allow passing a
translatable string pattern for altering text fields during copy, for example copy='%s (copy)'.