1
0
forked from erp-dev/erp

feat: added print_count api, added merchant setting model, added manual mode setting for purchase order

This commit is contained in:
2025-11-28 15:01:11 +08:00
parent 53f2a24b20
commit 0c62398120
36 changed files with 1634 additions and 478 deletions

View File

@@ -139,11 +139,16 @@ class PurchaseOrderAPITestCase(TestCase):
def setUp(self):
self.merchant = Merchant.objects.create(name='PO商户', type=MerchantTypeEnum.FACTORY)
self.supplier = Supplier.objects.create(merchant=self.merchant, name='供应商A')
self.warehouse = WareHouse.objects.create(
self.warehouse_strict = WareHouse.objects.create(
merchant=self.merchant,
name='',
name='严进',
mode=WareHouseModeEnum.RESTRICT_IN,
)
self.warehouse_relaxed = WareHouse.objects.create(
merchant=self.merchant,
name='宽进仓',
mode=WareHouseModeEnum.UNRESTRICTED,
)
category = ProductCategory.objects.create(
merchant=self.merchant,
name='品类',
@@ -164,39 +169,66 @@ class PurchaseOrderAPITestCase(TestCase):
)
self.client = APIClient()
self.client.force_authenticate(user=self.user)
self.payload = {
self.strict_payload = {
'supplier': self.supplier.id,
'warehouse': self.warehouse.id,
'warehouse': self.warehouse_strict.id,
'order_date': '2025-11-26',
'total_amount': '1500.00',
'items': [
{
'product_id': self.product.id,
'quantities': ['10.0', '5.0'],
'numbers': [10, 5],
'price': '12.5',
'unit': '',
}
],
'remarks': '接口测试',
}
self.relaxed_payload = {
'supplier': self.supplier.id,
'warehouse': self.warehouse_relaxed.id,
'order_date': '2025-11-26',
'items': [
{
'product_id': self.product.id,
'quantity': 120,
'num_of_rolls': 3,
'price': '10.5',
}
],
}
def test_create_purchase_order_success(self):
def test_create_purchase_order_success_strict(self):
with patch('business.services.create_purchase_order_stock_entries.delay') as mock_delay:
response = self.client.post('/api/v1/purchase-orders/', self.payload, format='json')
response = self.client.post('/api/v1/purchase-orders/', self.strict_payload, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertIn('id', response.data)
mock_delay.assert_called_once()
def test_create_purchase_order_invalid_supplier(self):
payload = {**self.payload, 'supplier': 999}
payload = {**self.strict_payload, 'supplier': 999}
response = self.client.post('/api/v1/purchase-orders/', payload, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn('不存在', response.data['error'])
def test_create_purchase_order_unauthenticated(self):
self.client.force_authenticate(user=None)
response = self.client.post('/api/v1/purchase-orders/', self.payload, format='json')
response = self.client.post('/api/v1/purchase-orders/', self.strict_payload, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_create_purchase_order_relaxed_mode(self):
with patch('business.services.create_purchase_order_stock_entries.delay') as mock_delay:
response = self.client.post('/api/v1/purchase-orders/', self.relaxed_payload, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
mock_delay.assert_called_once()
def test_mode_mismatch_raises(self):
payload = {**self.relaxed_payload}
payload['warehouse'] = self.warehouse_strict.id # 严进仓却传宽进参数
response = self.client.post('/api/v1/purchase-orders/', payload, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn('严进模式', response.data['error'])
@override_settings(
CELERY_TASK_ALWAYS_EAGER=True,