'Defines a default value for the given model and field_name. Any previous
default for the same scope (model, field_name, value, for_all_users, company_id, condition)
will be replaced and lost in the process.
Defaults can be later retrieved via :meth:`~.get_defaults`, which will return
the highest priority default for any given field. Defaults that are more specific
have a higher priority, in the following order (highest to lowest):
* specific to user and company
* specific to user only
* specific to company only
* global to everyone
:param string model: model name
:param string field_name: field name to which the default applies
:param value: the default field value to set
:type value: any serializable Python value
:param bool for_all_users: whether the default should apply to everybody or only
the user calling the method
:param int company_id: optional ID of the company to which the default should
apply. If omitted, the default will be global. If True
is passed, the current user\'s company will be used.
:param string condition: optional condition specification that can be used to
restrict the applicability of the default values
(e.g. based on another field\'s value). This is an
opaque string as far as the API is concerned, but client
stacks typically use single-field conditions in the
form ``\'key=stringified_value\'``.
(Currently, the condition is trimmed to 200 characters,
so values that share the same first 200 characters always
match)
:return: the newly created ir.values entry'

@api.model
@api.returns('self', (lambda value: value.id))
def set_default(self, model, field_name, value, for_all_users=True, company_id=False, condition=False):

    if isinstance(value, unicode):
        value = value.encode('utf8')
    if (company_id is True):
        company_id = self.env.user.company_id.id
    search_criteria = [('key', '=', 'default'), ('key2', '=', (condition and condition[:200])), ('model', '=', model), ('name', '=', field_name), ('user_id', '=', (False if for_all_users else self._uid)), ('company_id', '=', company_id)]
    self.search(search_criteria).unlink()
    return self.create({'name': field_name, 'value': pickle.dumps(value), 'model': model, 'key': 'default', 'key2': (condition and condition[:200]), 'user_id': (False if for_all_users else self._uid), 'company_id': company_id})
