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)
| 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: |