'Assign the property field `name` for the records of model `model`
with `values` (dictionary mapping record ids to their value).
If the value for a given record is the same as the default
value, the property entry will not be stored, to avoid bloating
the database.
If `default_value` is provided, that value will be used instead
of the computed default value, to determine whether the value
for a record should be stored or not.'

@api.model
def set_multi(self, name, model, values, default_value=None):

    def clean(value):
        return (value.id if isinstance(value, models.BaseModel) else value)
    if (not values):
        return
    if (not default_value):
        domain = self._get_domain(name, model)
        if (domain is None):
            raise Exception()
        default_value = clean(self.get(name, model))
    self._cr.execute('SELECT    id    FROM    ir_model_fields    WHERE    name=%s    AND    model=%s', (name, model))
    field_id = self._cr.fetchone()[0]
    company_id = (self.env.context.get('force_company') or self.env['res.company']._company_default_get(model, field_id).id)
    refs = {('%s,%s' % (model, id)): id for id in values}
    props = self.search([('fields_id', '=', field_id), ('company_id', '=', company_id), ('res_id', 'in', list(refs))])
    for prop in props:
        id = refs.pop(prop.res_id)
        value = clean(values[id])
        if (value == default_value):
            prop.unlink()
        elif (value != clean(prop.get_by_record())):
            prop.write({'value': value})
    for (ref, id) in refs.iteritems():
        value = clean(values[id])
        if (value != default_value):
            self.create({'fields_id': field_id, 'company_id': company_id, 'res_id': ref, 'name': name, 'value': value, 'type': self.env[model]._fields[name].type})
