forked from erp-dev/erp
fix: little bugs, feat: woodpecker settings
This commit is contained in:
@@ -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