'set the value of field ``self`` on ``record``'

def __set__(self, record, value):

    env = record.env
    record.ensure_one()
    value = self.convert_to_cache(value, record)
    if (env.in_draft or (not record.id)):
        spec = self.modified_draft(record)
        record._cache[self] = value
        if env.in_onchange:
            for invf in record._field_inverses[self]:
                invf._update(record[self.name], record)
            record._set_dirty(self.name)
        if self.relational:
            spec += self.modified_draft(record)
        env.invalidate(spec)
    else:
        write_value = self.convert_to_write(self.convert_to_record(value, record), record)
        record.write({self.name: write_value})
        if (not (self.relational and (not all(value)))):
            record._cache[self] = value
