erp5_collection_experimental
Rationale
This supports a case when one needs to group arbitrary objects into one set to be able to process them all together, and it has to be operated manually by a user.
The most obviouse Use Case is mass mailing in CRM application: a user wants to send one a mass email to all customers which fulfill one criterion, and all customers which fulfill another criterion, plus some he particularly likes. He should be able to search once, add them to collection, search again, add to collection, then manually pick some more and add them one by one.
There can be plenty other uses for it - e.g. community portal (collection = my friends").
Architecture
Very simple: a Collection is a document which is related by collection relation to any number of objects of any portal type. A Collection has an attribute portal_type_id which is used to make managing objects easier, since a Collection can be dedicated to storing only selected portal types, or any at all.
How to use
- create Collection
Within Collection Module, create a Collection. Optionally specify some portal types (freehand entry).
- add objects to Collection
From a context of any object (except modules), do an action "Add to Collection" - the dialog displays Collections which are meant to store this portal type. Pick one, confirm.
- navigation
Every object (which is not a module) has a jump to collections which it is a member of.
- remove from Collection
Collection -> "List" tab, then every line has a "remove" option, effective immediately. Yes, it is a lame solution - see Discussion below.
- use for various actions
Implementation level - once you have a Collection you can do whatever you wish.
Discussion and TODOs
Collection content management
I don't know how to cleanly implement managing of Collection content. The obvious tool for it is MultiRelationStringField, but this tool is good only when a number of related objects is small - with Collection, it can easily run in hundreds or even thousands, so it should be done with a searchable and sortable ListBox.
The most ergonomic way would be to allow user to tick some checkboxes in select column and then press a "delete" button. How to do it?
I tried two approaches, both failed:
- Use stock listbox in list mode (form_list)
This mode seems to be usable only on module level; it doesn't display tabs, so in the context of an object it is not good. Also, "delete" button is not configurable, it is meant to manage only contained objects.
- Use form_view with select column
This does not work because all actions that can be added (object_action, object_button, whatever) are just URLs, there is no way to add a POST action which would submit a form.
So I came up with a somewhat lame solution of "remove" column in the listbox. It is not very good because you can't delete many objects at a time, and there is no confirmation dialog (and shouldn't be since you can't delete many objects at a time...).
TODO: Mass adding to Collection
Now the objects can be added only one by one - enter an object, click "add to Collection".
The goal is: a user opens a module, makes some search or domain selection, then clicks "add all to Collection" and the whole listbox is added to a Collection at one go.