1
0
forked from erp-dev/erp

feat: stateflow v2 (params required)

This commit is contained in:
2025-11-15 19:39:15 +08:00
parent 9ad404a365
commit 9c38e2ac09
24 changed files with 3670 additions and 547 deletions

View File

@@ -132,7 +132,7 @@ class PlateOrderAdmin(admin.ModelAdmin):
messages.append(f"{obj.id}: 没有关联的流程实例,无法推进")
continue
success, message = services.advance_to_next_state(obj.business_object, request.user)
success, message, _ = services.advance_to_next_state(obj.business_object, request.user)
if success:
success_count += 1
messages.append(f"{obj.id}: {message}")

View File

@@ -54,7 +54,6 @@ class PlateOrderModelTestCase(TestCase):
def test_create_plate_order_basic(self):
"""测试创建基本的开版订单"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-1',
design_code='DES001',
customer=self.customer,
plate_type='首版',
@@ -65,14 +64,14 @@ class PlateOrderModelTestCase(TestCase):
)
self.assertIsNotNone(plate_order.id)
self.assertEqual(plate_order.plate_code, '20251113-1')
self.assertEqual(plate_order.design_code, 'DES001')
self.assertEqual(plate_order.customer, self.customer)
self.assertEqual(plate_order.style_name, '测试款式')
def test_plate_order_with_employees(self):
"""测试带销售员和跟单员的开版订单"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-2',
design_code='DES002',
customer=self.customer,
salesperson=self.salesperson,
merchandiser=self.merchandiser,
@@ -86,7 +85,7 @@ class PlateOrderModelTestCase(TestCase):
def test_plate_order_with_ratings(self):
"""测试带质量评级的开版订单"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-3',
design_code='DES003',
customer=self.customer,
drawing_rating='A',
color_matching_rating='B',
@@ -108,7 +107,7 @@ class PlateOrderModelTestCase(TestCase):
required_date = (now + timezone.timedelta(days=10)).date()
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-4',
design_code='DES004',
customer=self.customer,
plate_date=now,
completion_date=completion_date,
@@ -122,7 +121,7 @@ class PlateOrderModelTestCase(TestCase):
def test_plate_order_with_sample_info(self):
"""测试带样品信息的开版订单"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-5',
design_code='DES005',
customer=self.customer,
sample_meter='米样1',
required_sample_meters=Decimal('100.50'),
@@ -134,7 +133,7 @@ class PlateOrderModelTestCase(TestCase):
def test_plate_order_status_without_business_object(self):
"""测试没有 business_object 时的状态"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-6',
design_code='DES006',
customer=self.customer,
)
@@ -161,7 +160,7 @@ class PlateOrderModelTestCase(TestCase):
# 创建开版订单
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-7',
design_code='DES007',
customer=self.customer,
business_object=business_object,
)
@@ -175,7 +174,7 @@ class PlateOrderModelTestCase(TestCase):
# 刷新并检查状态
plate_order.refresh_from_db()
self.assertEqual(plate_order.status, state2.name) # 应该在第二个状态
self.assertEqual(plate_order.status, state1.name) # current_state 是最后完成的状态state1
self.assertFalse(plate_order.is_completed)
self.assertTrue(plate_order.has_started)
self.assertGreater(plate_order.progress_percentage, 0)
@@ -183,16 +182,16 @@ class PlateOrderModelTestCase(TestCase):
def test_plate_order_str(self):
"""测试字符串表示"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-8',
design_code='DES008',
customer=self.customer,
)
self.assertEqual(str(plate_order), '20251113-8')
self.assertEqual(str(plate_order), f'PlateOrder-{plate_order.id}')
def test_plate_order_with_approval_and_order_status(self):
"""测试带审批和订单状态的开版订单"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-9',
design_code='DES009',
customer=self.customer,
approval_result='通过',
is_ordered=True,
@@ -203,24 +202,19 @@ class PlateOrderModelTestCase(TestCase):
self.assertTrue(plate_order.is_ordered)
self.assertEqual(plate_order.customer_feedback, '颜色需要调整')
def test_plate_order_unique_plate_code(self):
"""测试版单编号的唯一性"""
printing_models.PlateOrder.objects.create(
plate_code='20251113-10',
def test_plate_order_with_invalid_flag(self):
"""测试作废标记"""
plate_order = printing_models.PlateOrder.objects.create(
design_code='DES010',
customer=self.customer,
is_invalid=True,
)
# 尝试创建相同编号的订单应该失败
with self.assertRaises(Exception):
printing_models.PlateOrder.objects.create(
plate_code='20251113-10',
customer=self.customer,
)
self.assertTrue(plate_order.is_invalid)
def test_plate_order_nullable_fields(self):
"""测试可空字段"""
plate_order = printing_models.PlateOrder.objects.create(
plate_code='20251113-11',
customer=self.customer,
)