forked from erp-dev/erp
fix: 出货单审核后也可以修改了(未绑定送货单都可以)
This commit is contained in:
@@ -1876,9 +1876,9 @@ class ShipmentQueryAPITestCase(TestCase):
|
||||
self.assertEqual(self.shipment1.contact_name, "王五")
|
||||
self.assertEqual(self.shipment1.contact_phone, "13700137000")
|
||||
|
||||
def test_patch_shipment_rejects_non_draft(self):
|
||||
def test_patch_shipment_allows_approved_shipment_without_delivery(self):
|
||||
"""
|
||||
非草稿状态的出货单不允许修改业务数据。
|
||||
已审核但未关联送货单的出货单允许修改业务数据。
|
||||
"""
|
||||
from shipment.services import modify_status
|
||||
|
||||
@@ -1887,6 +1887,33 @@ class ShipmentQueryAPITestCase(TestCase):
|
||||
target_status=shipment_models.ShipmentStatus.PUBLISHED,
|
||||
operator=self.user1,
|
||||
)
|
||||
modify_status(
|
||||
self.shipment1,
|
||||
target_status=shipment_models.ShipmentStatus.APPROVED,
|
||||
operator=self.user1,
|
||||
approved_by=self.user1,
|
||||
)
|
||||
|
||||
resp = self.client.patch(
|
||||
f"/api/v1/shipment/shipments/{self.shipment1.id}/",
|
||||
data={"area": "审核后可修改"},
|
||||
format="json",
|
||||
)
|
||||
self.assertEqual(resp.status_code, status.HTTP_200_OK)
|
||||
self.assertEqual(resp.json()["area"], "审核后可修改")
|
||||
|
||||
self.shipment1.refresh_from_db()
|
||||
self.assertEqual(self.shipment1.area, "审核后可修改")
|
||||
|
||||
def test_patch_shipment_rejects_when_bound_to_delivery(self):
|
||||
delivery = shipment_models.ShipmentDelivery.objects.create(
|
||||
merchant=self.merchant1,
|
||||
driver_name="绑定司机",
|
||||
vehicle_trip="LOCK-001",
|
||||
created_by=self.user1,
|
||||
)
|
||||
self.shipment1.delivery = delivery
|
||||
self.shipment1.save(update_fields=["delivery", "updated_at"])
|
||||
|
||||
resp = self.client.patch(
|
||||
f"/api/v1/shipment/shipments/{self.shipment1.id}/",
|
||||
@@ -1894,7 +1921,7 @@ class ShipmentQueryAPITestCase(TestCase):
|
||||
format="json",
|
||||
)
|
||||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
self.assertIn("仅草稿状态", resp.json()["detail"])
|
||||
self.assertIn("已关联送货单", resp.json()["detail"])
|
||||
|
||||
self.shipment1.refresh_from_db()
|
||||
self.assertEqual(self.shipment1.area, "A1")
|
||||
|
||||
@@ -113,8 +113,8 @@
|
||||
|
||||
- 仅允许修改业务数据字段:`customer`、`shipment_date`、`address`、`contact_name`、`contact_phone`、`area`、`remark`、`external_id`
|
||||
- 该接口不允许修改 `status`
|
||||
- 仅 `草稿(未发布)` 状态的出货单允许修改
|
||||
- 非草稿状态会返回 `400 Bad Request`
|
||||
- 仅“未关联送货单”的出货单允许修改
|
||||
- 一旦出货单已关联送货单,会返回 `400 Bad Request`
|
||||
|
||||
请求体示例:
|
||||
|
||||
@@ -132,7 +132,7 @@
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "仅草稿状态的出货单允许修改"
|
||||
"detail": "已关联送货单的出货单不允许修改"
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -708,13 +708,13 @@ def update_shipment(
|
||||
更新出货单业务数据。
|
||||
|
||||
说明:
|
||||
- 仅允许在草稿状态下修改
|
||||
- 仅允许修改未关联送货单的出货单
|
||||
- 不处理状态变更
|
||||
"""
|
||||
from basic_info.models import Customer
|
||||
|
||||
if shipment.status != ShipmentStatus.DRAFT:
|
||||
raise ValueError("仅草稿状态的出货单允许修改")
|
||||
if shipment.delivery_id is not None:
|
||||
raise ValueError("已关联送货单的出货单不允许修改")
|
||||
|
||||
if customer_id is not None:
|
||||
customer = Customer.objects.filter(id=customer_id).first()
|
||||
|
||||
Reference in New Issue
Block a user