-
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] impersonate_login: Update create_uid for impersonated record cr…
…eation - Ensure impersonation is properly reflected in record creation - Update related tests to verify correct impersonation behavior
- Loading branch information
Showing
2 changed files
with
19 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,23 +2,35 @@ | |
# @author Kévin Roche <[email protected]> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from psycopg2.extensions import AsIs | ||
|
||
from odoo import api, models | ||
from odoo.http import request | ||
|
||
|
||
class BaseModel(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
@api.model_create_multi | ||
@api.model | ||
def _create(self, data_list): | ||
res = super()._create(data_list) | ||
if ( | ||
request | ||
and request.session.impersonate_from_uid | ||
and "create_uid" in self._fields | ||
): | ||
for rec in res: | ||
rec["create_uid"] = request.session.impersonate_from_uid | ||
self.env.cr.execute( | ||
""" | ||
UPDATE %(table)s | ||
SET create_uid = %(impersonator_id)s | ||
WHERE id IN %(record_ids)s | ||
""", | ||
{ | ||
"table": AsIs(self._table), | ||
"impersonator_id": request.session.impersonate_from_uid, | ||
"record_ids": tuple(rec.id for rec in res), | ||
}, | ||
) | ||
return res | ||
|
||
def write(self, vals): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters