forked from erp-dev/erp
feat: app verion && some field modify (printing & shipment)
This commit is contained in:
@@ -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