MCPcopy
hub / github.com/odoo/odoo / with_context

Method with_context

odoo/orm/models.py:6021–6055  ·  view source on GitHub ↗

Return a new version of this recordset attached to an extended context. The extended context is either the provided ``context`` in which ``overrides`` are merged or the *current* context in which ``overrides`` are merged e.g.:: # current context is {'ke

(self, ctx: dict[str, typing.Any] | None = None, /, **overrides)

Source from the content-addressed store, hash-verified

6019
6020 @api.private
6021 def with_context(self, ctx: dict[str, typing.Any] | None = None, /, **overrides) -> Self:
6022 """ Return a new version of this recordset attached to an extended
6023 context.
6024
6025 The extended context is either the provided ``context`` in which
6026 ``overrides`` are merged or the *current* context in which
6027 ``overrides`` are merged e.g.::
6028
6029 # current context is {'key1': True}
6030 r2 = records.with_context({}, key2=True)
6031 # -> r2.env.context is {'key2': True}
6032 r2 = records.with_context(key2=True)
6033 # -> r2.env.context is {'key1': True, 'key2': True}
6034
6035 .. note:
6036
6037 The returned recordset has the same prefetch object as ``self``.
6038 """ # noqa: RST210
6039 context = dict(ctx if ctx is not None else self.env.context, **overrides)
6040 if 'force_company' in context:
6041 warnings.warn(
6042 "Since 19.0, context key 'force_company' is no longer supported. "
6043 "Use with_company(company) instead.",
6044 DeprecationWarning,
6045 )
6046 if 'company' in context:
6047 warnings.warn(
6048 "Context key 'company' is not recommended, because "
6049 "of its special meaning in @depends_context.",
6050 )
6051 if 'allowed_company_ids' not in context and 'allowed_company_ids' in self.env.context:
6052 # Force 'allowed_company_ids' to be kept when context is overridden
6053 # without 'allowed_company_ids'
6054 context['allowed_company_ids'] = self.env.context['allowed_company_ids']
6055 return self.with_env(self.env(context=context))
6056
6057 @api.private
6058 def with_prefetch(self, prefetch_ids: Reversible[IdType] | None = None) -> Self:

Callers 15

loadMethod · 0.95
_auto_initMethod · 0.95
_order_field_to_sqlMethod · 0.95
copy_dataMethod · 0.95
copyMethod · 0.95
with_companyMethod · 0.95
get_langFunction · 0.80
_export_imdinfoMethod · 0.80
load_languageFunction · 0.80
_eval_xmlFunction · 0.80

Calls 3

with_envMethod · 0.95
warnMethod · 0.45
envMethod · 0.45

Tested by 15

test_noupdateMethod · 0.64
test_lang_with_baseMethod · 0.64
test_lazy_translationMethod · 0.64
test_export_importMethod · 0.64
converterMethod · 0.64