forked from erp-dev/erp
fix: merchant not required at customer create api
This commit is contained in:
@@ -10,6 +10,7 @@ from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from basic_info import models as basic_models
|
||||
from printing import models as printing_models
|
||||
from shipment import models as shipment_models
|
||||
from stateflow import models as stateflow_models
|
||||
|
||||
User = get_user_model()
|
||||
@@ -228,6 +229,91 @@ class PrintingJobAPITestCase(TestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('batch_advance_records', response.data)
|
||||
self.assertEqual(len(response.data['batch_advance_records']), 1)
|
||||
|
||||
def test_list_printing_jobs_includes_saleitems(self):
|
||||
"""测试 list 返回包含关联的 shipment.SalesItem 数组"""
|
||||
job1 = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
job2 = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=200,
|
||||
unit='米',
|
||||
size='60*70',
|
||||
pieces=20
|
||||
)
|
||||
|
||||
item1 = shipment_models.SalesItem.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='销售品A',
|
||||
quantity='88.50',
|
||||
unit=shipment_models.UnitChoices.METER,
|
||||
created_by=self.user,
|
||||
printing_job_id=job1.id,
|
||||
customer_id=self.customer.id,
|
||||
position='A1-01',
|
||||
remark='备注A',
|
||||
)
|
||||
item2 = shipment_models.SalesItem.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='销售品B',
|
||||
quantity='12.00',
|
||||
unit=shipment_models.UnitChoices.PIECE,
|
||||
created_by=self.user,
|
||||
printing_job_id=job1.id,
|
||||
customer_id=self.customer.id,
|
||||
position='A1-02',
|
||||
remark='备注B',
|
||||
)
|
||||
|
||||
response = self.client.get(f'/api/v1/printing-jobs/?printing_order={self.printing_order.id}')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
data_by_id = {item['id']: item for item in response.data['results']}
|
||||
self.assertIn('saleitems', data_by_id[job1.id])
|
||||
self.assertEqual(len(data_by_id[job1.id]['saleitems']), 2)
|
||||
self.assertEqual([item['id'] for item in data_by_id[job1.id]['saleitems']], [item1.id, item2.id])
|
||||
self.assertEqual(data_by_id[job1.id]['saleitems'][0]['printing_job_id'], job1.id)
|
||||
self.assertEqual(data_by_id[job1.id]['saleitems'][0]['name'], '销售品A')
|
||||
|
||||
self.assertIn('saleitems', data_by_id[job2.id])
|
||||
self.assertEqual(data_by_id[job2.id]['saleitems'], [])
|
||||
|
||||
def test_retrieve_printing_job_includes_saleitems(self):
|
||||
"""测试 detail 返回包含关联的 shipment.SalesItem 数组"""
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=self.printing_order,
|
||||
product=self.product,
|
||||
quantity=100,
|
||||
unit='米',
|
||||
size='50*60',
|
||||
pieces=10
|
||||
)
|
||||
|
||||
shipment_models.SalesItem.objects.create(
|
||||
merchant=self.merchant,
|
||||
name='详情销售品',
|
||||
quantity='66.00',
|
||||
unit=shipment_models.UnitChoices.METER,
|
||||
created_by=self.user,
|
||||
printing_job_id=job.id,
|
||||
customer_id=self.customer.id,
|
||||
position='B2-01',
|
||||
remark='详情备注',
|
||||
)
|
||||
|
||||
response = self.client.get(f'/api/v1/printing-jobs/{job.id}/')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('saleitems', response.data)
|
||||
self.assertEqual(len(response.data['saleitems']), 1)
|
||||
self.assertEqual(response.data['saleitems'][0]['printing_job_id'], job.id)
|
||||
self.assertEqual(response.data['saleitems'][0]['name'], '详情销售品')
|
||||
|
||||
def test_update_printing_job(self):
|
||||
"""测试更新款式明细"""
|
||||
|
||||
Reference in New Issue
Block a user