forked from erp-dev/erp
fix: process id change when plate_order and printing_order update
This commit is contained in:
@@ -514,6 +514,54 @@ class PrintingOrderAPITestCase(TestCase):
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
order.refresh_from_db()
|
||||
self.assertEqual(order.process.id, new_process.id)
|
||||
|
||||
def test_update_process_with_jobs_not_started_relinks_jobs(self):
|
||||
"""测试:有任务但均未开始时允许改流程,并对所有 jobs 重建/绑定新的 business_object"""
|
||||
order = printing_models.PrintingOrder.objects.create(
|
||||
merchant=self.merchant,
|
||||
customer=self.customer,
|
||||
fabric='测试布料',
|
||||
width='150cm',
|
||||
process=self.process,
|
||||
)
|
||||
|
||||
category = basic_models.ProductCategory.objects.create(
|
||||
name='测试类别2',
|
||||
merchant=self.merchant,
|
||||
)
|
||||
product = basic_models.Product.objects.create(
|
||||
name='测试产品2',
|
||||
category=category,
|
||||
merchant=self.merchant,
|
||||
)
|
||||
|
||||
job = printing_models.PrintingJob.objects.create(
|
||||
printing_order=order,
|
||||
product=product,
|
||||
quantity=10,
|
||||
unit='件',
|
||||
)
|
||||
# 绑定一个旧的 business_object(未推进过,未开始)
|
||||
old_bo = stateflow_models.BusinessObject.objects.create(
|
||||
name=f'PrintingJob-{job.id}',
|
||||
process=self.process,
|
||||
)
|
||||
job.business_object = old_bo
|
||||
job.save()
|
||||
|
||||
new_process = stateflow_models.Process.objects.create(name='新流程2')
|
||||
data = {'process': new_process.id}
|
||||
|
||||
response = self.client.patch(f'/api/v1/printing-orders/{order.id}/', data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
|
||||
order.refresh_from_db()
|
||||
self.assertEqual(order.process.id, new_process.id)
|
||||
|
||||
job.refresh_from_db()
|
||||
self.assertIsNotNone(job.business_object)
|
||||
self.assertNotEqual(job.business_object.id, old_bo.id)
|
||||
self.assertEqual(job.business_object.process.id, new_process.id)
|
||||
|
||||
def test_cannot_update_process_when_job_started(self):
|
||||
"""测试有已开始的任务时不能修改流程"""
|
||||
|
||||
Reference in New Issue
Block a user