forked from erp-dev/erp
feat: added type field into warehouse model
This commit is contained in:
@@ -38,7 +38,6 @@ class PlateOrderAPITestCase(TestCase):
|
||||
merchant=self.merchant,
|
||||
name='测试员工',
|
||||
mobile='13800138000',
|
||||
job_type=basic_models.EmployeeTypeEnum.PRINTER,
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
@@ -47,7 +46,6 @@ class PlateOrderAPITestCase(TestCase):
|
||||
merchant=self.merchant,
|
||||
name='测试业务员',
|
||||
mobile='13800138001',
|
||||
job_type=basic_models.EmployeeTypeEnum.PRINTER,
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
@@ -56,7 +54,14 @@ class PlateOrderAPITestCase(TestCase):
|
||||
merchant=self.merchant,
|
||||
name='测试跟单员',
|
||||
mobile='13800138002',
|
||||
job_type=basic_models.EmployeeTypeEnum.WARE,
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
# 创建设计师
|
||||
self.designer = basic_models.Employee.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='测试设计师',
|
||||
mobile='13800138003',
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
@@ -189,7 +194,7 @@ class PlateOrderAPITestCase(TestCase):
|
||||
self.assertIn('salesperson_name', response.data)
|
||||
|
||||
def test_design_code_fallback_in_detail(self):
|
||||
"""design_code 为空时返回补零后的主键"""
|
||||
"""design_code 为空时返回主键ID"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='',
|
||||
@@ -200,10 +205,10 @@ class PlateOrderAPITestCase(TestCase):
|
||||
|
||||
response = self.client.get(f'/api/v1/plate-orders/{plate_order.id}/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['design_code'], f'{plate_order.id:06d}')
|
||||
self.assertEqual(response.data['design_code'], str(plate_order.id))
|
||||
|
||||
def test_design_code_fallback_in_list(self):
|
||||
"""列表接口也应返回补零后的设计编号"""
|
||||
"""列表接口也应返回主键ID"""
|
||||
printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='',
|
||||
@@ -215,7 +220,7 @@ class PlateOrderAPITestCase(TestCase):
|
||||
response = self.client.get('/api/v1/plate-orders/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
results = response.data['results'] if isinstance(response.data, dict) else response.data
|
||||
self.assertEqual(results[0]['design_code'], f"{results[0]['id']:06d}")
|
||||
self.assertEqual(results[0]['design_code'], str(results[0]['id']))
|
||||
|
||||
def test_fabric_source_field_in_detail(self):
|
||||
"""验证布料来源字段在返回中存在"""
|
||||
@@ -777,7 +782,22 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
merchant=self.merchant,
|
||||
name='测试员工',
|
||||
mobile='13800138000',
|
||||
job_type=basic_models.EmployeeTypeEnum.PRINTER,
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
# 创建业务员
|
||||
self.salesperson = basic_models.Employee.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='测试业务员',
|
||||
mobile='13800138001',
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
# 创建设计师
|
||||
self.designer = basic_models.Employee.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='测试设计师',
|
||||
mobile='13800138003',
|
||||
status=basic_models.EmployeeStatusEnum.ACTIVE
|
||||
)
|
||||
|
||||
@@ -917,3 +937,101 @@ class PlateOrderInvalidateAPITestCase(TestCase):
|
||||
response = self.client.post(f'/api/v1/plate-orders/{plate_order.id}/activate/')
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn('未作废', response.data['detail'])
|
||||
|
||||
def test_create_plate_order_with_designer(self):
|
||||
"""测试创建带设计师的开版订单"""
|
||||
data = {
|
||||
'customer': self.customer.id,
|
||||
'design_code': 'DESIGN_DESIGNER_001',
|
||||
'plate_type': '圆网',
|
||||
'style_name': '测试款式-设计师',
|
||||
'fabric': '棉布',
|
||||
'width': '150cm',
|
||||
'designer': self.designer.id,
|
||||
'salesperson': self.salesperson.id,
|
||||
}
|
||||
|
||||
response = self.client.post('/api/v1/plate-orders/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.data['designer'], self.designer.id)
|
||||
|
||||
# 验证数据库中创建了记录并关联了设计师
|
||||
plate_order = printing_models.PlateOrder.objects.get(id=response.data['id'])
|
||||
self.assertEqual(plate_order.designer, self.designer)
|
||||
|
||||
def test_create_plate_order_without_designer(self):
|
||||
"""测试创建不带设计师的开版订单"""
|
||||
data = {
|
||||
'customer': self.customer.id,
|
||||
'design_code': 'DESIGN_NO_DESIGNER',
|
||||
'plate_type': '圆网',
|
||||
'style_name': '测试款式-无设计师',
|
||||
'fabric': '棉布',
|
||||
'width': '150cm',
|
||||
}
|
||||
|
||||
response = self.client.post('/api/v1/plate-orders/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertIsNone(response.data['designer'])
|
||||
|
||||
def test_update_plate_order_designer(self):
|
||||
"""测试更新开版订单的设计师"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_UPDATE_DESIGNER',
|
||||
plate_type='圆网',
|
||||
style_name='测试款式',
|
||||
fabric='棉布',
|
||||
)
|
||||
|
||||
data = {
|
||||
'designer': self.designer.id,
|
||||
}
|
||||
|
||||
response = self.client.patch(f'/api/v1/plate-orders/{plate_order.id}/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['designer'], self.designer.id)
|
||||
|
||||
# 验证数据库已更新
|
||||
plate_order.refresh_from_db()
|
||||
self.assertEqual(plate_order.designer, self.designer)
|
||||
|
||||
def test_list_plate_orders_includes_designer_name(self):
|
||||
"""测试列表接口包含设计师字段"""
|
||||
printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_LIST_1',
|
||||
plate_type='圆网',
|
||||
style_name='测试款式1',
|
||||
designer=self.designer,
|
||||
)
|
||||
printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_LIST_2',
|
||||
plate_type='平网',
|
||||
style_name='测试款式2',
|
||||
)
|
||||
|
||||
response = self.client.get('/api/v1/plate-orders/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
results = response.data['results'] if isinstance(response.data, dict) else response.data
|
||||
|
||||
# 验证数据包含designer字段(designer_name在designer为空时可能不存在)
|
||||
self.assertIn('designer', results[0])
|
||||
|
||||
def test_retrieve_plate_order_includes_designer(self):
|
||||
"""测试详情接口包含设计师信息"""
|
||||
plate_order = printing_models.PlateOrder.objects.create(
|
||||
customer=self.customer,
|
||||
design_code='DESIGN_RETRIEVE',
|
||||
plate_type='圆网',
|
||||
style_name='测试款式',
|
||||
designer=self.designer,
|
||||
salesperson=self.salesperson,
|
||||
)
|
||||
|
||||
response = self.client.get(f'/api/v1/plate-orders/{plate_order.id}/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(response.data['designer'], self.designer.id)
|
||||
self.assertIn('designer_name', response.data)
|
||||
|
||||
Reference in New Issue
Block a user