Be able to set one2many/many2many values in a more convenient way

Bug #1179313 reported by Sébastien Alix
18
This bug affects 3 people
Affects Status Importance Assigned to Milestone
OERPLib
Fix Released
Low
Unassigned

Bug Description

On browse_records objects, many2one fields can be updated with either an ID or a browse_record.
It will be nice if a similar behaviour can be done for many2many and one2many fields, with a default set to [(6, 0, ids)].

See: https://answers.launchpad.net/oerplib/+question/228611

summary: - Be able to set many2many values in a more convenient way
+ Be able to set one2many/many2many values in a more convenient way
Revision history for this message
Sébastien Alix (sebastien-alix) wrote :

Fix commited about this:

- my_record.many_ids = [(4, IDS), ...] # As usual, OERP tuples are detected here
- my_record.many_ids = [IDS or records] # Converted to [(6, 0, IDS)]
- my_record.many_ids = [] # [(5,)]
- my_record.many_ids = False # [(5,)]

Support for '+=' and '-=' operators coming soon.

Changed in oerplib:
status: New → Fix Committed
Revision history for this message
Sébastien Alix (sebastien-alix) wrote :

That's done.

With a list of records::

    >>> records = oerp.get('my.model').browse([4, 5])
    >>> my_record.many_ids += list(records)
    >>> [r.id for r in my_record.many_ids]
    [1, 2, 3, 4, 5]

With a list of record IDs::

    >>> my_record.many_ids += [4, 5]
    >>> [r.id for r in my_record.many_ids]
    [1, 2, 3, 4, 5]

With an ID only::

    >>> my_record.many_ids -= 4
    >>> [r.id for r in my_record.many_ids]
    [1, 2, 3, 5]

With a record only::

    >>> record = oerp.get('my.model').browse(5)
    >>> my_record.many_ids -= record
    >>> [r.id for r in my_record.many_ids]
    [1, 2, 3]

Changed in oerplib:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.