forked from erp-dev/erp
fix: little bugs, feat: woodpecker settings
This commit is contained in:
@@ -115,17 +115,7 @@ class PlateOrderAdmin(admin.ModelAdmin):
|
||||
|
||||
@admin.display(description='进度')
|
||||
def progress_display(self, obj):
|
||||
progress = obj.progress_percentage
|
||||
if progress >= 100:
|
||||
color = 'green'
|
||||
elif progress >= 50:
|
||||
color = 'orange'
|
||||
else:
|
||||
color = 'gray'
|
||||
return format_html(
|
||||
'<span style="color: {}; font-weight: bold;">{:.1f}%</span>',
|
||||
color, progress
|
||||
)
|
||||
return obj.progress_percentage
|
||||
|
||||
@admin.display(description='当前状态')
|
||||
def status_display(self, obj):
|
||||
@@ -139,13 +129,13 @@ class PlateOrderAdmin(admin.ModelAdmin):
|
||||
|
||||
for obj in queryset:
|
||||
if not obj.business_object:
|
||||
messages.append(f"{obj.plate_code}: 没有关联的流程实例,无法推进")
|
||||
messages.append(f"{obj.id}: 没有关联的流程实例,无法推进")
|
||||
continue
|
||||
|
||||
success, message = services.advance_to_next_state(obj.business_object, request.user)
|
||||
if success:
|
||||
success_count += 1
|
||||
messages.append(f"{obj.plate_code}: {message}")
|
||||
messages.append(f"{obj.id}: {message}")
|
||||
|
||||
self.message_user(request, f'成功推进 {success_count}/{queryset.count()} 个开版订单。详情: {"; ".join(messages[:5])}')
|
||||
|
||||
@@ -157,13 +147,13 @@ class PlateOrderAdmin(admin.ModelAdmin):
|
||||
|
||||
for obj in queryset:
|
||||
if not obj.business_object:
|
||||
messages.append(f"{obj.plate_code}: 没有关联的流程实例,无法回退")
|
||||
messages.append(f"{obj.id}: 没有关联的流程实例,无法回退")
|
||||
continue
|
||||
|
||||
success, message = services.step_back_one_state(obj.business_object, request.user)
|
||||
if success:
|
||||
success_count += 1
|
||||
messages.append(f"{obj.plate_code}: {message}")
|
||||
messages.append(f"{obj.id}: {message}")
|
||||
|
||||
self.message_user(request, f'成功回退 {success_count}/{queryset.count()} 个开版订单。详情: {"; ".join(messages[:5])}')
|
||||
|
||||
|
||||
18
printing/migrations/0012_plateorder_process.py
Normal file
18
printing/migrations/0012_plateorder_process.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.7 on 2025-11-14 06:22
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('printing', '0011_alter_plateorder_options_plateorder_is_invalid'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='plateorder',
|
||||
name='process',
|
||||
field=models.IntegerField(default=14, verbose_name='关联流程'),
|
||||
),
|
||||
]
|
||||
@@ -87,6 +87,7 @@ class PlateOrder(ModelBase):
|
||||
customer_feedback = models.TextField(blank=True, null=True, verbose_name='客户修改意见')
|
||||
|
||||
# 流程管理
|
||||
process = models.IntegerField(default=settings.PLATE_ORDER_DEFAULT_PROCESS_ID, verbose_name='关联流程')
|
||||
business_object = models.OneToOneField(
|
||||
stateflow_models.BusinessObject,
|
||||
on_delete=models.SET_NULL,
|
||||
@@ -97,7 +98,30 @@ class PlateOrder(ModelBase):
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.human_id or f'PlateOrder-{self.id}'
|
||||
return f'PlateOrder-{self.id}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""保存时自动创建 BusinessObject"""
|
||||
# 先保存以获取 ID(如果是新建)
|
||||
is_new = self.pk is None
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
# 如果有 process 且没有 business_object,则自动创建
|
||||
if self.process and not self.business_object:
|
||||
try:
|
||||
from stateflow.models import Process
|
||||
process_obj = Process.objects.get(id=self.process)
|
||||
|
||||
# 创建 BusinessObject
|
||||
business_object = stateflow_models.BusinessObject.objects.create(
|
||||
process=process_obj
|
||||
)
|
||||
self.business_object = business_object
|
||||
# 再次保存以更新 business_object 字段
|
||||
super().save(update_fields=['business_object'])
|
||||
except Process.DoesNotExist:
|
||||
# 如果流程不存在,忽略错误
|
||||
pass
|
||||
|
||||
class Meta:
|
||||
verbose_name = '开版订单'
|
||||
|
||||
Reference in New Issue
Block a user