Copy resources to created documents

Rational

Attachments and notes are flexible tools that user can use to share informal information.
But on document like sale or purchase orders, the information may need to be passed to created documents like shipments or invoices. This is mainly because the user has an information to share for a document (e.g. shipment that is not yet created). The natural place at that time is to put the information on the order that will create the document (e.g. the sale).

Proposal

We add on the ResourceMixin a MultiSelection field that contains the list of resources the record must be copied to. The selection is dynamic and depend on the main resource (E.g. for sale.sale, it will contain stock.shipment.out, account.invoice, stock.shipment.out.return).
Each module will be responsible to extend the mixin to fill the selection for its models.
The models that create other records will be copy all the resources that are selected to the new records. A mixin is created to contain those common operations.

Implementation

We may argument that this mechanism is limit to one level of creation. For example, it will not be possible to copy resources from sale → shipment → moves.
I do not think it is really needed and if such case appear, it is still possible to customize the copy of the resource of the 1st level to select automatically the second level.

Wouldn’t it be better to allow to relate an attachment to more than one record? If I understand your proposal correctly it will create unnecessary duplication of binary data if the binary data is stored in the database.

I do not think because:

  • It will add an indirection to find attachments/notes. So the client queries will be more expensive (and they are executed a lot)
  • Users may have difficulties to understand that such records are shared because nothing will indicate it.
  • The read state of note will be propagated to other documents which is probably not desired.
  • Edition should only affect the current record version.

In this case but this is not the default configuration and it is already the case if you attach twice the same date. By the way, I filled Do not copy Binary with file_id filled (#9153) · Issues · Tryton / Tryton · GitLab