forked from erp-dev/erp
fix: process id change when plate_order and printing_order update
This commit is contained in:
@@ -35,6 +35,14 @@ class PlateOrderAPITestCase(TestCase):
|
||||
password='testpass123',
|
||||
email='test@example.com'
|
||||
)
|
||||
# PlateOrderViewSet 默认做 merchant 隔离;本测试集不关注该隔离逻辑,
|
||||
# 设为 superuser 以避免因测试数据未设置 merchant 导致的 404/列表为空。
|
||||
self.user.is_superuser = True
|
||||
self.user.save(update_fields=['is_superuser'])
|
||||
# PlateOrder/Printing 视图集默认做 merchant 隔离;本测试集不关注该隔离逻辑,
|
||||
# 设为 superuser 以避免因测试数据未设置 merchant 导致的 404/列表为空。
|
||||
self.user.is_superuser = True
|
||||
self.user.save(update_fields=['is_superuser'])
|
||||
|
||||
# 创建员工并关联商户
|
||||
self.employee = basic_models.Employee.objects.create(
|
||||
@@ -72,6 +80,7 @@ class PlateOrderAPITestCase(TestCase):
|
||||
# 创建客户
|
||||
self.customer = basic_models.Customer.objects.create(
|
||||
merchant=self.merchant,
|
||||
created_by=self.employee,
|
||||
name='测试客户',
|
||||
mobile='13900139000',
|
||||
area='测试地区'
|
||||
@@ -930,7 +939,7 @@ class PlateOrderAPITestCase(TestCase):
|
||||
# 获取原来的 business_object
|
||||
old_business_object_id = plate_order.business_object.id if plate_order.business_object else None
|
||||
|
||||
# 更新流程(注意:这只会更新 process 字段,不会重新创建 business_object)
|
||||
# 更新流程:应重建并重新绑定 business_object(若存在未撤销进度则应拒绝)
|
||||
data = {
|
||||
'customer': self.customer.id,
|
||||
'design_code': 'DESIGN105',
|
||||
@@ -943,10 +952,40 @@ class PlateOrderAPITestCase(TestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['process'], process2.id)
|
||||
|
||||
# 验证 business_object 没有改变(因为已经存在)
|
||||
# 验证 business_object 已重建并绑定到新流程
|
||||
plate_order.refresh_from_db()
|
||||
if old_business_object_id:
|
||||
self.assertEqual(plate_order.business_object.id, old_business_object_id)
|
||||
self.assertNotEqual(plate_order.business_object.id, old_business_object_id)
|
||||
self.assertEqual(plate_order.business_object.process.id, process2.id)
|
||||
|
||||
def test_cannot_update_plate_order_process_when_started(self):
|
||||
"""测试:存在未撤销进度时不允许修改开版流程"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN105X',
|
||||
plate_type='圆网',
|
||||
style_name='测试款式',
|
||||
process=self.process.id,
|
||||
)
|
||||
self.assertIsNotNone(plate_order.business_object)
|
||||
|
||||
# 推进一步以制造“未撤销进度”
|
||||
from stateflow.services import advance_to_next_state
|
||||
advance_to_next_state(plate_order.business_object, self.user)
|
||||
|
||||
process2 = stateflow_models.Process.objects.create(name='另一个流程')
|
||||
stateflow_models.ProcessNode.objects.create(process=process2, state=self.state1, order=0)
|
||||
|
||||
data = {
|
||||
'customer': self.customer.id,
|
||||
'design_code': 'DESIGN105X',
|
||||
'plate_type': '圆网',
|
||||
'style_name': '测试款式',
|
||||
'process': process2.id,
|
||||
}
|
||||
response = self.client.put(f'/api/v1/plate-orders/{plate_order.id}/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn('process', response.data)
|
||||
|
||||
def test_business_object_auto_creation(self):
|
||||
"""测试 BusinessObject 自动创建逻辑"""
|
||||
@@ -1163,6 +1202,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
# 创建客户
|
||||
self.customer = basic_models.Customer.objects.create(
|
||||
merchant=self.merchant,
|
||||
created_by=self.employee,
|
||||
name='测试客户',
|
||||
mobile='13900139000',
|
||||
area='测试地区'
|
||||
@@ -1188,6 +1228,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
def test_invalidate_plate_order_without_permission(self):
|
||||
"""测试无权限作废开版订单"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1208,6 +1249,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
self.user.user_permissions.add(invalidate_perm)
|
||||
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1229,6 +1271,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
self.user.user_permissions.add(invalidate_perm)
|
||||
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1243,6 +1286,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
def test_activate_plate_order_without_permission(self):
|
||||
"""测试无权限恢复开版订单"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1264,6 +1308,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
self.user.user_permissions.add(activate_perm)
|
||||
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1286,6 +1331,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
self.user.user_permissions.add(activate_perm)
|
||||
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN001',
|
||||
plate_type='圆网',
|
||||
@@ -1336,6 +1382,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
def test_update_plate_order_designer(self):
|
||||
"""测试更新开版订单的设计师"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_UPDATE_DESIGNER',
|
||||
plate_type='圆网',
|
||||
@@ -1358,6 +1405,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
def test_list_plate_orders_includes_designer_name(self):
|
||||
"""测试列表接口包含设计师字段"""
|
||||
printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_LIST_1',
|
||||
plate_type='圆网',
|
||||
@@ -1365,6 +1413,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
designer=self.designer,
|
||||
)
|
||||
printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_LIST_2',
|
||||
plate_type='平网',
|
||||
@@ -1382,6 +1431,7 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
def test_retrieve_plate_order_includes_designer(self):
|
||||
"""测试详情接口包含设计师信息"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_RETRIEVE',
|
||||
plate_type='圆网',
|
||||
|
||||
Reference in New Issue
Block a user