1
0
forked from erp-dev/erp

fix: appversions

This commit is contained in:
2026-07-11 00:05:05 +08:00
parent 48e4782e1e
commit e91d06e4b6
26 changed files with 2582 additions and 19 deletions

View File

@@ -2527,6 +2527,128 @@ class ShipmentQueryAPITestCase(TestCase):
self.assertIn("external_finished_products", result)
self.assertIsInstance(result["external_finished_products"], list)
def test_list_shipment_printing_jobs_returns_minimal_paginated_jobs(self):
other_order = printing_models.PrintingOrder.objects.create(
merchant=self.merchant1,
customer=self.customer1,
fabric="第二生产单面料",
width="160cm",
process=self.process1,
created_by=self.user1,
external_order_id="QUERY-PO-002",
)
other_job = printing_models.PrintingJob.objects.create(
merchant=self.merchant1,
printing_order=other_order,
product=self.product1,
quantity=10,
unit="",
created_by=self.user1,
)
shipment_models.SalesItem.objects.create(
merchant=self.merchant1,
shipment=self.shipment1,
name="重复销售品",
quantity=Decimal("1.00"),
unit=shipment_models.UnitChoices.METER,
printing_job_id=self.printing_job1.id,
customer_id=self.customer1.id,
created_by=self.user1,
)
shipment_models.SalesItem.objects.create(
merchant=self.merchant1,
shipment=self.shipment1,
name="第二销售品",
quantity=Decimal("2.00"),
unit=shipment_models.UnitChoices.METER,
printing_job_id=other_job.id,
customer_id=self.customer1.id,
created_by=self.user1,
)
resp = self.client.get(f"/api/v1/shipment/shipments/{self.shipment1.id}/printing-jobs/?limit=1")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
data = resp.json()
self.assertEqual(data["count"], 2)
self.assertEqual(len(data["results"]), 1)
item = data["results"][0]
self.assertEqual(set(item.keys()), {"id", "printing_order_id", "external_order_id", "customer_name"})
self.assertEqual(item["id"], self.printing_job1.id)
self.assertEqual(item["printing_order_id"], self.printing_order1.id)
self.assertEqual(item["external_order_id"], "QUERY-PO-001")
self.assertEqual(item["customer_name"], "客户1")
def test_list_delivery_printing_jobs_returns_jobs_across_shipments(self):
delivery = shipment_models.ShipmentDelivery.objects.create(
merchant=self.merchant1,
driver_name="生产任务司机",
vehicle_trip="JOB-DELIVERY",
created_by=self.user1,
)
self.shipment1.delivery = delivery
self.shipment1.save(update_fields=["delivery", "updated_at"])
other_order = printing_models.PrintingOrder.objects.create(
merchant=self.merchant1,
customer=self.customer1,
fabric="送货单生产单面料",
width="160cm",
process=self.process1,
created_by=self.user1,
external_order_id="QUERY-PO-DELIVERY",
)
other_job = printing_models.PrintingJob.objects.create(
merchant=self.merchant1,
printing_order=other_order,
product=self.product1,
quantity=10,
unit="",
created_by=self.user1,
)
other_shipment = shipment_models.Shipment.objects.create(
merchant=self.merchant1,
customer=self.customer1,
shipment_date="2026-01-24",
created_by=self.user1,
delivery=delivery,
)
shipment_models.SalesItem.objects.create(
merchant=self.merchant1,
shipment=other_shipment,
name="送货单销售品",
quantity=Decimal("2.00"),
unit=shipment_models.UnitChoices.METER,
printing_job_id=other_job.id,
customer_id=self.customer1.id,
created_by=self.user1,
)
resp = self.client.get(f"/api/v1/shipment/deliveries/{delivery.id}/printing-jobs/?limit=10")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
data = resp.json()
self.assertEqual(data["count"], 2)
ids = [item["id"] for item in data["results"]]
self.assertEqual(ids, [self.printing_job1.id, other_job.id])
def test_printing_jobs_sub_endpoints_respect_merchant_scope(self):
other_delivery = shipment_models.ShipmentDelivery.objects.create(
merchant=self.merchant2,
driver_name="其他商户司机",
vehicle_trip="OTHER-MERCHANT",
created_by=self.user2,
)
shipment_resp = self.client.get(
f"/api/v1/shipment/shipments/{self.shipment2.id}/printing-jobs/"
)
delivery_resp = self.client.get(
f"/api/v1/shipment/deliveries/{other_delivery.id}/printing-jobs/"
)
self.assertEqual(shipment_resp.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(delivery_resp.status_code, status.HTTP_404_NOT_FOUND)
def test_patch_shipment_area_success(self):
"""
新增字段 area支持更新PATCH并回显。
@@ -3548,14 +3670,43 @@ class ShipmentDeliveryAPITestCase(APITestCase):
self.assertEqual(data["results"][0]["id"], delivery.id)
def test_detail_returns_nested_shipment_summaries(self):
customer_address = basic_models.CustomerAddress.objects.create(
merchant=self.merchant,
customer=self.customer,
address="客户地址库地址",
contact_name="地址库联系人",
contact_phone="13600136000",
area="杭州",
coordinates="120.1551,30.2741",
created_by=self.employee,
)
delivery = shipment_models.ShipmentDelivery.objects.create(
merchant=self.merchant,
driver_name="张司机",
vehicle_trip="KD-004",
created_by=self.user,
)
self.shipment1.customer_address = customer_address
self.shipment1.address = "杭州市测试路 1 号"
self.shipment1.contact_name = "张三"
self.shipment1.contact_phone = "13800138000"
self.shipment1.area = "华东"
self.shipment1.coordinates = "120.1551,30.2741"
self.shipment1.geo_coordinates = {"lng": 120.1551, "lat": 30.2741}
self.shipment1.extra = {"dock": "A"}
self.shipment1.delivery = delivery
self.shipment1.save(update_fields=["delivery", "updated_at"])
self.shipment1.save(update_fields=[
"customer_address",
"address",
"contact_name",
"contact_phone",
"area",
"coordinates",
"geo_coordinates",
"extra",
"delivery",
"updated_at",
])
self.shipment2.delivery = delivery
self.shipment2.save(update_fields=["delivery", "updated_at"])
@@ -3572,6 +3723,14 @@ class ShipmentDeliveryAPITestCase(APITestCase):
self.assertIn("fabric", item)
self.assertIn("order_description", item)
first_shipment = next(item for item in data["shipments"] if item["id"] == self.shipment1.id)
self.assertEqual(first_shipment["address_id"], customer_address.id)
self.assertEqual(first_shipment["address"], "杭州市测试路 1 号")
self.assertEqual(first_shipment["contact_name"], "张三")
self.assertEqual(first_shipment["contact_phone"], "13800138000")
self.assertEqual(first_shipment["area"], "华东")
self.assertEqual(first_shipment["coordinates"], "120.1551,30.2741")
self.assertEqual(first_shipment["geo_coordinates"], {"lng": 120.1551, "lat": 30.2741})
self.assertEqual(first_shipment["extra"], {"dock": "A"})
self.assertIsNone(first_shipment["fabric"])
self.assertIsNone(first_shipment["order_description"])