-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
shopfloor_base: improve lock for update action
Add the skip locked option.
- Loading branch information
Showing
3 changed files
with
51 additions
and
4 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
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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2023 Camptocamp SA (http://www.camptocamp.com) | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). | ||
from contextlib import closing | ||
|
||
from .common import CommonCase | ||
|
||
|
||
class ActionsLockCase(CommonCase): | ||
@classmethod | ||
def setUpClassBaseData(cls): | ||
super().setUpClassBaseData() | ||
cls.partner = cls.env.ref("base.res_partner_12") | ||
with cls.work_on_actions(cls) as work: | ||
cls.lock = work.component(usage="lock") | ||
|
||
def test_select_for_update_skip_locked_ok(self): | ||
"""Check the lock is obtained and True is returned.""" | ||
result = self.lock.for_update(self.partner, skip_locked=True) | ||
self.assertTrue(result) | ||
|
||
def test_select_for_update_skip_locked_not_ok(self): | ||
"""Check the lock is NOT obtained and False is returned.""" | ||
with closing(self.registry.cursor()) as cr: | ||
# Simulate another user locked a row | ||
cr.execute( | ||
"SELECT id FROM res_partner WHERE id=%s FOR UPDATE", (self.partner.id,) | ||
) | ||
result = self.lock.for_update(self.partner, skip_locked=True) | ||
self.assertFalse(result) |