1
0
forked from erp-dev/erp

feat: added shipments list api

This commit is contained in:
2026-01-15 16:47:12 +08:00
parent ea9f378de9
commit a0cd168397
6 changed files with 284 additions and 8 deletions

View File

@@ -553,3 +553,101 @@ class ShipmentExternalCreateAPITestCase(TestCase):
}
response = self.client.post('/api/v1/shipment/shipments/external/', data, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
class ShipmentQueryAPITestCase(TestCase):
"""测试出货单查询 API列表/详情)"""
def setUp(self):
self.client = APIClient()
self.merchant1 = basic_models.Merchant.objects.create(
name='商户1',
type=basic_models.MerchantTypeEnum.FACTORY
)
self.merchant2 = basic_models.Merchant.objects.create(
name='商户2',
type=basic_models.MerchantTypeEnum.FACTORY
)
self.user1 = User.objects.create_user(
username='u1',
password='pass123',
email='u1@example.com'
)
self.emp1 = basic_models.Employee.objects.create(
sys_user=self.user1,
merchant=self.merchant1,
name='员工1',
mobile='13800138010',
status=basic_models.EmployeeStatusEnum.ACTIVE
)
self.user2 = User.objects.create_user(
username='u2',
password='pass123',
email='u2@example.com'
)
self.emp2 = basic_models.Employee.objects.create(
sys_user=self.user2,
merchant=self.merchant2,
name='员工2',
mobile='13800138011',
status=basic_models.EmployeeStatusEnum.ACTIVE
)
self.customer1 = basic_models.Customer.objects.create(
merchant=self.merchant1,
name='客户1',
mobile='13900139010',
area='A'
)
self.customer2 = basic_models.Customer.objects.create(
merchant=self.merchant2,
name='客户2',
mobile='13900139011',
area='B'
)
self.shipment1 = shipment_models.Shipment.objects.create(
merchant=self.merchant1,
customer=self.customer1,
shipment_date='2026-01-15',
created_by=self.user1,
remark='s1',
)
self.shipment2 = shipment_models.Shipment.objects.create(
merchant=self.merchant2,
customer=self.customer2,
shipment_date='2026-01-15',
created_by=self.user2,
remark='s2',
)
self.client.force_authenticate(user=self.user1)
def test_list_shipments_only_current_merchant(self):
resp = self.client.get('/api/v1/shipment/shipments/')
self.assertEqual(resp.status_code, status.HTTP_200_OK)
data = resp.json()
# LimitOffsetPagination 结构count/next/previous/results
self.assertIn('count', data)
self.assertIn('results', data)
ids = [it['id'] for it in data['results']]
self.assertIn(self.shipment1.id, ids)
self.assertNotIn(self.shipment2.id, ids)
def test_retrieve_shipment_success(self):
resp = self.client.get(f'/api/v1/shipment/shipments/{self.shipment1.id}/')
self.assertEqual(resp.status_code, status.HTTP_200_OK)
self.assertEqual(resp.json()['id'], self.shipment1.id)
def test_retrieve_other_merchant_shipment_404(self):
resp = self.client.get(f'/api/v1/shipment/shipments/{self.shipment2.id}/')
self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)
def test_list_shipments_unauthenticated(self):
self.client.logout()
resp = self.client.get('/api/v1/shipment/shipments/')
self.assertEqual(resp.status_code, status.HTTP_401_UNAUTHORIZED)