1
0
forked from erp-dev/erp

feat: printing module

This commit is contained in:
2025-11-13 18:22:42 +08:00
parent 8097d6941c
commit f071e5fff9
35 changed files with 5537 additions and 440 deletions

View File

@@ -7,6 +7,18 @@ from . import models
class StateParameterInline(admin.StackedInline):
model = models.StateParameter
extra = 1
fields = ('key', 'value', 'attachment', 'description')
readonly_fields = ('attachment_preview',)
def attachment_preview(self, obj):
"""显示附件预览"""
if obj.attachment:
if obj.attachment.name.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp', '.webp')):
return mark_safe(f'<img src="{obj.attachment.url}" style="max-width: 200px; max-height: 200px;" />')
else:
return mark_safe(f'<a href="{obj.attachment.url}" target="_blank">查看附件</a>')
return "-"
attachment_preview.short_description = '附件预览'
class ProcessNodeInline(admin.StackedInline):
@@ -34,10 +46,15 @@ class StateAdmin(admin.ModelAdmin):
def parameter_overview(self, obj: models.State):
params = obj.parameters.all()
if params:
result = "<br>".join([f"{param.key}={param.value}" for param in params])
result = []
for param in params:
param_str = f"{param.key}={param.value}"
if param.attachment:
param_str += f' <a href="{param.attachment.url}" target="_blank">📎</a>'
result.append(param_str)
return mark_safe("<br>".join(result))
else:
result = "-"
return mark_safe(result)
return "-"
@admin.register(models.Process)
@@ -81,7 +98,7 @@ class BusinessObjectAdmin(admin.ModelAdmin):
)
search_fields = ('name', 'description')
list_filter = ('process', 'created_at', 'updated_at')
actions = ['advance_to_next_state_action', 'reset_progress_action']
actions = ['advance_to_next_state_action', 'step_back_one_state_action', 'reset_progress_action']
autocomplete_fields = ('process',)
inlines = [StateFlowRecordInline]
fieldsets = [
@@ -115,6 +132,20 @@ class BusinessObjectAdmin(admin.ModelAdmin):
self.message_user(request, f'成功推进 {success_count}/{queryset.count()} 个业务对象。详情: {"; ".join(messages[:5])}')
@action(description='回退一步')
def step_back_one_state_action(self, request, queryset):
from . import services
success_count = 0
messages = []
for obj in queryset:
success, message = services.step_back_one_state(obj, request.user)
if success:
success_count += 1
messages.append(f"{obj.name}: {message}")
self.message_user(request, f'成功回退 {success_count}/{queryset.count()} 个业务对象。详情: {"; ".join(messages[:5])}')
@action(description='重置进度')
def reset_progress_action(self, request, queryset):
from . import services