Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions connector_extension/models/backend/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2025 NuoBiT - Deniz Gallo <dgallo@nuobit.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
import logging
from contextlib import contextmanager

import pytz

Expand Down Expand Up @@ -46,6 +47,13 @@ def _select_state(self):
default=lambda self: self.env.company,
string="Company",
)
user_id = fields.Many2one(
comodel_name="res.users",
string="User",
help="User used as the default responsible for records created by "
"this backend. If set, all operations (imports, exports, jobs) "
"will run under this user context.",
)

lang_ids = fields.Many2many(
comodel_name="res.lang",
Expand Down Expand Up @@ -122,6 +130,14 @@ def tz_to_local(self, datetime_utc_naive):
datetime_local_naive = datetime_local.replace(tzinfo=None)
return datetime_local_naive

@contextmanager
def work_on(self, model_name, **kwargs):
backend = self
if self.user_id:
backend = self.with_user(self.user_id)
with super(ConnectorBackend, backend).work_on(model_name, **kwargs) as work:
yield work

# Scheduler methods
@api.model
def _get_current_user_company(self):
Expand Down
Loading