19 Commits

Author SHA1 Message Date
lizerk
4555ee9bf7 Fix procurement viewed state and item actions 2026-06-08 16:25:19 +03:00
lizerk
d6a7ce530d Fix procurement unit selection and labels 2026-06-08 15:46:42 +03:00
lizerk
a794ff40c8 Support multiple expected delivery dates 2026-06-01 22:13:40 +03:00
lizerk
e6eee5ddf8 Allow procurement requests for any department 2026-06-01 11:26:33 +03:00
lizerk
5b422fd34e procurement: use actual item price for approval totals 2026-05-26 17:43:28 +03:00
lizerk
e3ba6ea925 refactor(ui): stabilize equipment deep links and qr flow 2026-04-12 16:09:38 +03:00
lizerk
3f59f8ebb9 Add backend OpenAPI docs and clean test suite 2026-03-31 17:05:31 +03:00
lizerk
f88d90230b refactor: clean architecture, align tests to current API contracts, all tests green [deploy-ready] 2026-03-30 04:27:18 +03:00
lizerk
2031872461 refactor(procurement): approval logic now fully driven by ApprovalRoute table (priority+min_amount), removed hardcoded steps, all workflow is DB-driven; tests and migrations updated 2026-03-30 02:16:29 +03:00
427f5ed22f feat(procurement): frontend templates + API-based rendering; update models, serializers, views and tests 2025-12-10 14:09:49 +03:00
ccbc8c5452 feat(procurement): полный жизненный цикл заявок
Добавлены endpoints:
- start_work: APPROVED → IN_PROGRESS
- complete: IN_PROGRESS → COMPLETED
- cancel: отмена заявки с любого статуса кроме завершённых
- create_equipment: создание оборудования из позиции завершённой заявки

Frontend:
- Модальные окна approve/reject/cancel
- POST handler для создания заявок
- Django формы для заявок

Тесты: 19 новых тестов lifecycle, всего 136 тестов procurement passed
2025-12-09 16:46:21 +03:00
8b8974e3ef feat: refactor equipment API permissions
- Add DeptPerm.MANAGE_EQUIPMENT scoped permission constant
- Create migration 0035 for new DepartmentPermission
- Refactor CanManageEquipment permission class with:
  * Admin/staff/superuser → full access
  * Model permissions → full access (add/change/delete_equipment)
  * Department head → own department, can choose responsible
  * Scoped permission → own department, responsible forced to head
  * Regular members → no access
- Update EquipmentListSerializer with:
  * Permission level detection (full/dept_head/scoped/None)
  * Auto-fill department and responsible based on permission level
  * Validation that responsible is in same department
- Add create_options endpoint returning:
  * allowed_departments, can_choose_department, can_choose_responsible
  * default_responsible, permission_level
- Add bulk equipment creation support with auto-generated inventory numbers
- Implement 45 comprehensive permission tests (all passing)
- Fix is_active=True in test make_user() fixture

Tests: 45/45 passing ✅
2025-12-09 16:14:30 +03:00
d04b5e38c2 feat: add procurement integration with notifications and real-time
Stage 7 - Integration:
- Create notification types migration for procurement
- Fix signals to use pre_save for status tracking
- Add broadcast_request_update function for WebSocket events
- Add procurement_update handler in UserConsumer
- Add 6 integration tests for signals and notifications
- Update README with integration details

All 72 tests passing (66 base + 6 integration).
2025-12-09 12:23:02 +03:00
3cd161d83c feat: add equipment management with QR codes and transfers
Stage 5 (Inventory) implementation:
- Add EquipmentTransferLog model for tracking equipment movements
- Add EquipmentViewSet actions:
  - transfer: move equipment between departments/users
  - write_off: decommission equipment
  - add_maintenance: record maintenance activities
  - qr_code: generate QR code for equipment
  - transfer_history: view equipment transfer history
- Use existing QRCodeGenerator and InventoryNumberGenerator services
- Fix EquipmentStatus constants usage (IN_USE, RETIRED)
- Add 14 new tests for inventory functionality

Test results: 66/66 PASSED
- 20/20 Model tests
- 12/12 API tests
- 9/9 Workflow tests
- 11/11 Budget tests
- 14/14 Inventory tests (NEW)
2025-12-09 10:42:07 +03:00
69402567e3 feat(procurement): add budget control and alerts
Budget Model Enhancements:
- Add reserved_amount property (sum of pending requests)
- Add available_amount property (remaining - reserved)
- Add _quarter_months() helper method

API Endpoints:
- Add /budgets/my-department/ endpoint for user's department budget
- Add /stats/overview/ for procurement statistics
- Add /stats/by-department/ for department-level statistics
- Register ProcurementStatsViewSet in urls.py

Budget Alerts:
- Add _check_budget_alert() method in ProcurementRequestViewSet
- Send notifications when budget < 20% (low) or < 10% (critical)
- Alerts sent to department head via NotificationService

Serializers:
- Add reserved_amount, available_amount to BudgetSerializer
- Add BudgetDetailSerializer with pending_requests list

Permissions:
- Fix led_departments → headed_departments in BudgetViewSet
- Allow my_department endpoint for all authenticated users

Tests:
- Add test_budget.py with 11 new tests
- TestBudgetReservedAmount (3 tests)
- TestBudgetMyDepartmentEndpoint (3 tests)
- TestProcurementStatsEndpoints (4 tests)
- TestBudgetAlerts (1 test)

All 52 procurement tests passing:
✅ 20/20 Model tests
✅ 12/12 API tests
✅ 9/9 Workflow tests
✅ 11/11 Budget tests (NEW)
2025-12-09 10:19:24 +03:00
f0e619e6fb fix: Extend ProcurementRequest queryset to include approvers
- Added Q(approvals__approver=user) filter to ProcurementRequestViewSet.get_queryset()
- Ensures users can see requests where they are designated approvers
- Added .distinct() to prevent duplicate results from approval JOIN
- Updated test_cannot_approve_without_permission to accept 404 (more secure)
- Cleaned up debug statements from test_workflow.py

This fixes the 404 errors in multi-level approval workflow:
- test_multi_level_approval: PASSED ✅
- test_cannot_approve_without_permission: PASSED ✅

All 41 procurement tests now passing: 20 models + 12 API + 9 workflow
2025-12-09 10:00:28 +03:00
814d383c15 fix(procurement): fix workflow tests - add estimated_cost and budget year
- Add estimated_cost to all test ProcurementRequests
- Fix budget year from 2024 Q1 to 2025 Q4
- Fix finance manager lookup to check user_permissions too
- Remove debug print from test_submit_request_creates_approvals

Result: 39/41 tests PASSED (was 38/41)
Remaining: 2 tests with 404 on /approve/ endpoint
2025-12-09 09:50:24 +03:00
d2a3a97165 fix(procurement): resolve test failures
- Fix led_departments -> headed_departments (permissions.py)
- Remove items_count annotate conflict with @property
- Add purchase_cost to EquipmentListSerializer fields
- Add requestor field to ProcurementRequestCreateSerializer response
- Fix test_list_budgets_regular_user - expect 403 not 200
- Add settings_test.py with InMemoryChannelLayer for tests
- Update pytest.ini to use settings_test

Result: 38/41 tests PASSED (was 26/41)
2025-12-09 09:41:26 +03:00
f483750873 feat(procurement): add stages 1-3 - models, API, workflow
- Stage 1: 8 models with admin interface (20/20 tests)
- Stage 2: REST API with 50+ endpoints (6/12 tests)
- Stage 3: django-fsm workflow with notifications (1/9 tests)
- Known issue: items_count property conflicts with annotate()
2025-12-09 09:03:21 +03:00