Fix payroll scheduled change row locking
Some checks failed
Deploy production / deploy (push) Failing after 12m47s

This commit is contained in:
admin i 2026-10-02 12:10:33 +03:00
parent e72a039744
commit 1873dd604a
2 changed files with 35 additions and 1 deletions

View File

@ -52,7 +52,7 @@ def materialize_scheduled_changes(
component.code: component for component in get_payroll_components(target_period)
}
source_lines = list(
PayrollInputLine.objects.select_for_update()
PayrollInputLine.objects.select_for_update(of=("self",))
.select_related("created_by", "approved_by")
.filter(
period=source_period,

View File

@ -237,6 +237,40 @@ def test_marker_waits_until_the_next_period_is_created(scheduled_workspace):
assert len(row["applied_scheduled_changes"]) == 1
def test_materialization_locks_only_payroll_input_lines(
scheduled_workspace,
monkeypatch,
):
from django.db.models import QuerySet
lock_targets = []
original_select_for_update = QuerySet.select_for_update
def track_select_for_update(queryset, *args, **kwargs):
if queryset.model is PayrollInputLine:
lock_targets.append(kwargs.get("of"))
return original_select_for_update(queryset, *args, **kwargs)
monkeypatch.setattr(QuerySet, "select_for_update", track_select_for_update)
workspace = scheduled_workspace
component = create_scheduled_component(
workspace["client"],
name="Маркер с безопасной блокировкой",
source_period=workspace["periods"][7],
)
response = set_cell(
workspace["client"],
period=workspace["periods"][7],
employee=workspace["employee"],
component_code=component["code"],
amount="500.00",
)
assert response.status_code == 201, response.content
assert ("self",) in lock_targets
def test_closed_next_period_rejects_marker_value(scheduled_workspace):
workspace = scheduled_workspace
target = workspace["periods"][8]