Notify processing departments about subscriptions
All checks were successful
Deploy production / deploy (push) Successful in 13m7s
All checks were successful
Deploy production / deploy (push) Successful in 13m7s
This commit is contained in:
parent
86fed54811
commit
47bf0cbcb9
@ -51,8 +51,6 @@ def create_procurement_request(
|
||||
**request_attributes,
|
||||
)
|
||||
procurement_request._notification_actor = requestor
|
||||
if procurement_request.request_type == ProcurementRequest.RequestType.SUBSCRIPTION:
|
||||
procurement_request._suppress_created_procurement_notifications = True
|
||||
procurement_request.save()
|
||||
|
||||
for raw_item in items:
|
||||
|
||||
@ -62,11 +62,19 @@ class MessageTemplates:
|
||||
title: str,
|
||||
department_name: str,
|
||||
author_name: str,
|
||||
request_type: str = "standard",
|
||||
) -> tuple[str, str]:
|
||||
notification_title = "Новая заявка на закупку"
|
||||
description = (
|
||||
f'{author_name} направил заявку "{title}" в отдел {department_name}.'
|
||||
)
|
||||
if request_type == "subscription":
|
||||
notification_title = "Новая заявка на подписку"
|
||||
description = (
|
||||
f'{author_name} направил заявку на подписку "{title}" '
|
||||
f"в отдел {department_name}."
|
||||
)
|
||||
else:
|
||||
notification_title = "Новая заявка на закупку"
|
||||
description = (
|
||||
f'{author_name} направил заявку "{title}" в отдел {department_name}.'
|
||||
)
|
||||
return notification_title, description
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -198,6 +198,7 @@ def notify_processing_department_request(request, actor=None):
|
||||
request.title,
|
||||
department_name,
|
||||
_actor_name(actor),
|
||||
request_type=request.request_type,
|
||||
)
|
||||
recipients = _processing_department_recipients(request)
|
||||
_notify_many(
|
||||
|
||||
@ -49,11 +49,6 @@ def create_request_notifications(sender, instance, created, **kwargs):
|
||||
if (
|
||||
request.status == ProcurementStatus.WAITING
|
||||
and request.processing_department_id
|
||||
and not getattr(
|
||||
request,
|
||||
"_suppress_created_procurement_notifications",
|
||||
False,
|
||||
)
|
||||
):
|
||||
notify_processing_department_request(
|
||||
request,
|
||||
|
||||
@ -1487,6 +1487,63 @@ class TestProcessingDepartmentWorkflow:
|
||||
)
|
||||
return employee
|
||||
|
||||
def test_subscription_creation_notifies_approver_and_processing_department(
|
||||
self,
|
||||
user,
|
||||
department,
|
||||
supply_department,
|
||||
supply_user,
|
||||
):
|
||||
from procurement.application import create_procurement_request
|
||||
|
||||
approver = Employee.objects.create_user(
|
||||
email="subscription-approver@example.com",
|
||||
password="testpass123",
|
||||
phone_number="+79998888894",
|
||||
first_name="Согласующий",
|
||||
last_name="Подписок",
|
||||
is_active=True,
|
||||
email_verified=True,
|
||||
send_activation_email=False,
|
||||
)
|
||||
procurement_settings = ProcurementSettings.get_solo()
|
||||
procurement_settings.subscription_approver = approver
|
||||
procurement_settings.save(update_fields=["subscription_approver"])
|
||||
|
||||
procurement_request = create_procurement_request(
|
||||
requestor=user,
|
||||
attributes={
|
||||
"title": "Подписка на сервис",
|
||||
"request_type": ProcurementRequest.RequestType.SUBSCRIPTION,
|
||||
"description": "Ежемесячный доступ к сервису",
|
||||
"department": department,
|
||||
"processing_department": supply_department,
|
||||
"urgency": UrgencyLevel.MEDIUM,
|
||||
},
|
||||
items=[],
|
||||
)
|
||||
|
||||
assert procurement_request.status == ProcurementStatus.PENDING
|
||||
request_id = procurement_request.id
|
||||
assert Approval.objects.filter(
|
||||
request_id=request_id,
|
||||
approver=approver,
|
||||
status=ApprovalStatus.PENDING,
|
||||
).exists()
|
||||
assert Notification.objects.filter(
|
||||
recipient=approver,
|
||||
verb="procurement_pending_approval",
|
||||
data__request_id=request_id,
|
||||
).exists()
|
||||
|
||||
department_notification = Notification.objects.get(
|
||||
recipient=supply_user,
|
||||
verb="procurement_department_request",
|
||||
data__request_id=request_id,
|
||||
)
|
||||
assert department_notification.data["title"] == "Новая заявка на подписку"
|
||||
assert "направил заявку на подписку" in department_notification.description
|
||||
|
||||
@pytest.fixture
|
||||
def supply_role_user(self, db, supply_department):
|
||||
employee = Employee.objects.create_user(
|
||||
|
||||
@ -1215,9 +1215,18 @@ export default function ProcurementPage() {
|
||||
type="button"
|
||||
onClick={() => setScope("subscriptions")}
|
||||
aria-pressed={scope === "subscriptions"}
|
||||
className={`inline-flex h-8 items-center rounded-full px-3 text-xs font-medium transition ${scope === "subscriptions" ? "app-pill-active" : "app-pill"}`}
|
||||
className={`inline-flex h-8 items-center gap-1.5 rounded-full px-3 text-xs font-medium transition ${scope === "subscriptions" ? "app-pill-active" : "app-pill"}`}
|
||||
>
|
||||
Подписки
|
||||
<span
|
||||
className={`app-badge px-1.5 py-0.5 text-[10px] font-bold ${
|
||||
scope === "subscriptions"
|
||||
? "app-pill-count-active"
|
||||
: "app-pill-count"
|
||||
}`}
|
||||
>
|
||||
{scopeCounts.subscriptions ?? 0}
|
||||
</span>
|
||||
</button>
|
||||
</HorizontalChipScroller>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user