forked from erp-dev/erp
fin
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
"""
|
||||
PrintingJob API 测试
|
||||
"""
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from django.test import TestCase
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from rest_framework.test import APIClient
|
||||
from rest_framework import status
|
||||
from django.contrib.auth import get_user_model
|
||||
@@ -187,10 +189,74 @@ class PrintingJobAPITestCase(TestCase):
|
||||
|
||||
# 新增字段:批量推进记录(稳定输出 key)
|
||||
for item in response.data['results']:
|
||||
self.assertIn('customer_name', item)
|
||||
self.assertEqual(item['customer_name'], self.customer.name)
|
||||
self.assertIn('batch_advance_records', item)
|
||||
self.assertIsInstance(item['batch_advance_records'], list)
|
||||
self.assertEqual(len(item['batch_advance_records']), 0)
|
||||
|
||||
def test_filter_printing_jobs_by_customer_name(self):
|
||||
"""测试按客户名称筛选款式明细列表"""
|
||||
other_customer = basic_models.Customer.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='其他客户',
|
||||
mobile='13900139001',
|
||||
area='测试地区'
|
||||
)
|
||||
other_order = printing_models.PrintingOrder.objects.create(
|
||||
customer=other_customer,
|
||||
fabric='其他布料',
|
||||
width='150cm',
|
||||
process=self.process,
|
||||
)
|
||||
matched_job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
)
|
||||
other_job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=other_order,
|
||||
product=self.product,
|
||||
quantity=200,
|
||||
unit='米',
|
||||
)
|
||||
|
||||
response = self.client.get('/api/v1/printing-jobs/?customer_name=测试客')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
ids = {item['id'] for item in response.data['results']}
|
||||
self.assertIn(matched_job.id, ids)
|
||||
self.assertNotIn(other_job.id, ids)
|
||||
|
||||
def test_filter_printing_jobs_by_created_at_date_range_includes_whole_to_day(self):
|
||||
"""测试 created_at_to 传日期时包含整天"""
|
||||
tz = timezone.get_current_timezone()
|
||||
in_range = timezone.make_aware(datetime(2026, 7, 3, 23, 30, 0), tz)
|
||||
out_range = timezone.make_aware(datetime(2026, 7, 4, 0, 0, 0), tz)
|
||||
|
||||
matched_job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
)
|
||||
out_job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=200,
|
||||
unit='米',
|
||||
)
|
||||
printing_models.PrintingJob.objects.filter(id=matched_job.id).update(created_at=in_range)
|
||||
printing_models.PrintingJob.objects.filter(id=out_job.id).update(created_at=out_range)
|
||||
|
||||
response = self.client.get(
|
||||
'/api/v1/printing-jobs/?created_at_from=2026-07-03&created_at_to=2026-07-03'
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
ids = {item['id'] for item in response.data['results']}
|
||||
self.assertIn(matched_job.id, ids)
|
||||
self.assertNotIn(out_job.id, ids)
|
||||
|
||||
def test_list_printing_jobs_includes_is_sales_order_bound(self):
|
||||
"""测试列表返回是否已绑定销售单字段,并支持关闭该字段"""
|
||||
unbound_job = printing_models.PrintingJob.objects.create(
|
||||
|
||||
Reference in New Issue
Block a user