it_manager: справочник типовых работ в журнале WorkLog.

Категория/работа/required_details вместо свободного work_type; seed Directory, отчёт и тесты.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-07 13:38:07 +03:00
parent be7e5853cb
commit 31bd4c8fa7
11 changed files with 822 additions and 112 deletions
+24 -27
View File
@@ -611,23 +611,27 @@ class ServiceCallForm(forms.ModelForm):
@admin.register(WorkLog)
class WorkLogAdmin(ModelAdmin):
form = WorkLogForm
list_display = ['date', 'technician', 'work_type_display', 'location',
list_display = ['date', 'technician', 'catalog_display', 'location',
'hours_spent', 'ticket', 'created_at']
list_filter = ['work_type', 'technician', 'date']
search_fields = ['description', 'result', 'technician__last_name',
'technician__first_name']
list_select_related = ['technician', 'location', 'ticket', 'equipment', 'work_type']
list_filter = ['catalog_work__parent', 'work_type', 'technician', 'date']
search_fields = ['description', 'result', 'catalog_work__name',
'technician__last_name', 'technician__first_name']
list_select_related = [
'technician', 'location', 'ticket', 'equipment',
'work_type', 'catalog_work', 'catalog_work__parent',
]
ordering = ['-date', '-created_at']
date_hierarchy = 'date'
raw_id_fields = ['catalog_work']
readonly_fields = ['created_at', 'updated_at']
fieldsets = (
(_('Работа'), {
'fields': ('date', 'technician', 'work_type', 'location'),
'fields': ('date', 'technician', 'catalog_work', 'details', 'location'),
}),
(_('Описание'), {
'fields': ('description', 'result', 'hours_spent'),
(_('Устарело / комментарий'), {
'fields': ('work_type', 'description', 'result', 'hours_spent'),
}),
(_('Связи'), {
'fields': ('equipment', 'ticket'),
@@ -638,25 +642,18 @@ class WorkLogAdmin(ModelAdmin):
}),
)
WORK_TYPE_COLORS = {
'maintenance': '#2563eb',
'installation': '#16a34a',
'repair': '#ca8a04',
'network': '#9333ea',
'software': '#0891b2',
'backup': '#6b7280',
'other': '#6b7280',
}
def work_type_display(self, obj):
color = self.WORK_TYPE_COLORS.get(obj.work_type.code, '#6b7280')
return format_html(
'<span style="color:{};font-weight:bold;">{}</span>',
color, obj.work_type.name
)
work_type_display.short_description = _('Вид работ')
work_type_display.admin_order_field = 'work_type__name'
def catalog_display(self, obj):
if obj.catalog_work_id:
cat = obj.catalog_work.parent.name if obj.catalog_work.parent_id else ''
label = obj.catalog_work.name
if cat:
return f'{cat}: {label}'
return label
if obj.work_type_id:
return obj.work_type.name
return (obj.description or '—')[:60]
catalog_display.short_description = _('Типовая работа')
catalog_display.admin_order_field = 'catalog_work__name'
def save_model(self, request, obj, form, change):
if not change and not obj.technician_id:
obj.technician = request.user