How it works...

The method starts by checking whether the partner passed as an argument contains exactly one record by calling ensure_one(). This method will raise an exception if this is not the case, and the processing will abort. This is needed, because we cannot add the same contacts to several partners at the same time.

Then, the method checks that the contacts recordset is not empty, because we don't want to update the date of the partner if we are not modifying it.

Finally, the method modifies the values of the attributes of the partner record. Since child_ids is a One2many relation, its value is a recordset. We use |= to compute the union of the current contacts of the partner and the new contacts passed to the method. Refer to the Combining recordsets recipe for more information on these operators.

Note that no assumption is made on self. This method can be defined on any model class.