forked from erp-dev/erp
feat: app verion && some field modify (printing & shipment)
This commit is contained in:
20
shipment/migrations/0026_shipment_customer_address.py
Normal file
20
shipment/migrations/0026_shipment_customer_address.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Generated by Django 5.2.8 on 2026-07-08 05:38
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('basic_info', '0029_customeraddress_coordinates'),
|
||||
('shipment', '0025_alter_shipmentdelivery_options_and_more'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shipment',
|
||||
name='customer_address',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='shipments', to='basic_info.customeraddress', verbose_name='客户地址'),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,28 @@
|
||||
# Generated by Django 5.2.8 on 2026-07-08 05:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('shipment', '0026_shipment_customer_address'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='shipment',
|
||||
name='coordinates',
|
||||
field=models.CharField(blank=True, help_text='经纬度字符串,格式由调用方决定', max_length=100, null=True, verbose_name='经纬度'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='shipment',
|
||||
name='extra',
|
||||
field=models.JSONField(blank=True, null=True, verbose_name='扩展信息'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='shipment',
|
||||
name='area',
|
||||
field=models.CharField(blank=True, default='', help_text='出货地区(可空字符串)', max_length=100, verbose_name='地区'),
|
||||
),
|
||||
]
|
||||
@@ -149,6 +149,15 @@ class Shipment(ModelBase):
|
||||
related_name='shipments',
|
||||
verbose_name='客户'
|
||||
)
|
||||
|
||||
customer_address = models.ForeignKey(
|
||||
basic_models.CustomerAddress,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name='shipments',
|
||||
verbose_name='客户地址',
|
||||
)
|
||||
|
||||
shipment_date = models.DateField(
|
||||
verbose_name='出货日期',
|
||||
@@ -177,12 +186,20 @@ class Shipment(ModelBase):
|
||||
)
|
||||
|
||||
area = models.CharField(
|
||||
max_length=30,
|
||||
max_length=100,
|
||||
blank=True,
|
||||
default='',
|
||||
verbose_name='地区',
|
||||
help_text='出货地区(可空字符串)',
|
||||
)
|
||||
|
||||
coordinates = models.CharField(
|
||||
max_length=100,
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name='经纬度',
|
||||
help_text='经纬度字符串,格式由调用方决定',
|
||||
)
|
||||
|
||||
remark = models.TextField(
|
||||
blank=True,
|
||||
@@ -205,6 +222,12 @@ class Shipment(ModelBase):
|
||||
help_text='由 Geo 系统返回的坐标信息,结构由调用方决定,后端不作校验',
|
||||
)
|
||||
|
||||
extra = models.JSONField(
|
||||
null=True,
|
||||
blank=True,
|
||||
verbose_name='扩展信息',
|
||||
)
|
||||
|
||||
rejected_sales_item_ids = models.JSONField(
|
||||
default=list,
|
||||
blank=True,
|
||||
|
||||
@@ -710,8 +710,10 @@ def update_shipment(
|
||||
contact_name: str | None = None,
|
||||
contact_phone: str | None = None,
|
||||
area: str | None = None,
|
||||
coordinates=UNSET,
|
||||
remark: str | None = None,
|
||||
external_id: str | None = None,
|
||||
extra=UNSET,
|
||||
) -> Shipment:
|
||||
"""
|
||||
更新出货单业务数据。
|
||||
@@ -743,10 +745,14 @@ def update_shipment(
|
||||
shipment.contact_phone = contact_phone or ""
|
||||
if area is not None:
|
||||
shipment.area = (area or "").strip()
|
||||
if coordinates is not UNSET:
|
||||
shipment.coordinates = coordinates or None
|
||||
if remark is not None:
|
||||
shipment.remark = remark or ""
|
||||
if external_id is not None:
|
||||
shipment.external_id = (external_id or "").strip() or None
|
||||
if extra is not UNSET:
|
||||
shipment.extra = extra
|
||||
|
||||
shipment.save()
|
||||
return shipment
|
||||
@@ -759,11 +765,15 @@ def create_shipment(
|
||||
shipment_date,
|
||||
sales_item_ids: List[int],
|
||||
created_by,
|
||||
address_id: int | None = None,
|
||||
address: str = "",
|
||||
contact_name: str = "",
|
||||
contact_phone: str = "",
|
||||
remark: str = "",
|
||||
area: str = "",
|
||||
coordinates: str | None = None,
|
||||
extra: dict | list | None = None,
|
||||
status: int = ShipmentStatus.DRAFT,
|
||||
) -> Shipment:
|
||||
"""
|
||||
创建出货单并关联销售品
|
||||
@@ -781,7 +791,7 @@ def create_shipment(
|
||||
Raises:
|
||||
ValueError: 如果销售品不存在或已被关联到其他出货单
|
||||
"""
|
||||
from basic_info.models import Customer
|
||||
from basic_info.models import Customer, CustomerAddress
|
||||
|
||||
# 验证客户存在
|
||||
try:
|
||||
@@ -798,6 +808,20 @@ def create_shipment(
|
||||
if customer.merchant_id != merchant.id:
|
||||
raise ValueError("无权限为该客户创建出货单")
|
||||
|
||||
customer_address = None
|
||||
if address_id is not None:
|
||||
try:
|
||||
customer_address = CustomerAddress.objects.get(id=address_id)
|
||||
except CustomerAddress.DoesNotExist:
|
||||
raise ValueError(f"客户地址 {address_id} 不存在")
|
||||
|
||||
if customer_address.deleted_at is not None:
|
||||
raise ValueError(f"客户地址 {address_id} 已删除")
|
||||
if customer_address.merchant_id != merchant.id:
|
||||
raise ValueError("无权限使用该客户地址")
|
||||
if customer_address.customer_id != customer.id:
|
||||
raise ValueError("客户地址与客户不匹配")
|
||||
|
||||
# 验证销售品
|
||||
if sales_item_ids:
|
||||
from printing.models import PrintingJob
|
||||
@@ -844,22 +868,20 @@ def create_shipment(
|
||||
f"以下销售品关联的生产任务不存在,无法创建出货单: {affected_item_ids}"
|
||||
)
|
||||
|
||||
printing_order_ids = {
|
||||
printing_job_map[item.printing_job_id] for item in sales_items_list
|
||||
}
|
||||
if len(printing_order_ids) > 1:
|
||||
raise ValueError("出货单中的销售品必须来自同一个生产订单")
|
||||
|
||||
# 创建出货单
|
||||
shipment = Shipment.objects.create(
|
||||
merchant=merchant,
|
||||
customer=customer,
|
||||
customer_address=customer_address,
|
||||
shipment_date=shipment_date,
|
||||
address=address or "",
|
||||
contact_name=contact_name or "",
|
||||
contact_phone=contact_phone or "",
|
||||
area=(area or "").strip(),
|
||||
coordinates=coordinates or None,
|
||||
remark=remark,
|
||||
extra=extra,
|
||||
status=status,
|
||||
created_by=created_by,
|
||||
)
|
||||
|
||||
@@ -996,6 +1018,8 @@ def create_external_shipment(
|
||||
contact_phone: str = "",
|
||||
remark: str = "",
|
||||
area: str = "",
|
||||
coordinates: str | None = None,
|
||||
extra: dict | list | None = None,
|
||||
) -> Shipment:
|
||||
"""
|
||||
创建出货单(external 版),并批量写入外部成品表并关联到出货单。
|
||||
@@ -1035,7 +1059,9 @@ def create_external_shipment(
|
||||
contact_name=contact_name or "",
|
||||
contact_phone=contact_phone or "",
|
||||
area=(area or "").strip(),
|
||||
coordinates=coordinates or None,
|
||||
remark=remark,
|
||||
extra=extra,
|
||||
created_by=created_by,
|
||||
external_id=external_id,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user