Compare commits
11
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f24fd9658 | ||
|
|
2045e7de89 | ||
|
|
eab882f92c | ||
|
|
04450fff88 | ||
|
|
82c21262ed | ||
|
|
8ac835fa96 | ||
|
|
e9f3602459 | ||
|
|
d2b8a573a1 | ||
|
|
79d1242d25 | ||
|
|
12652b826d | ||
|
|
be0ba622a0 |
No files matched your search
@@ -2206,8 +2206,7 @@ def create_plan(
|
|||||||
create_by=user.id,
|
create_by=user.id,
|
||||||
create_dept_id=user.dept_id,
|
create_dept_id=user.dept_id,
|
||||||
)
|
)
|
||||||
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_version
|
# 证件额度规则版本在首次安排时按生效时间打标,创建不打标。
|
||||||
stamp_plan_rule_version(db, user, plan)
|
|
||||||
db.add(plan)
|
db.add(plan)
|
||||||
|
|
||||||
# 添加产品明细
|
# 添加产品明细
|
||||||
@@ -2379,8 +2378,7 @@ def create_plan_full(
|
|||||||
create_by=user.id,
|
create_by=user.id,
|
||||||
create_dept_id=user.dept_id,
|
create_dept_id=user.dept_id,
|
||||||
)
|
)
|
||||||
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_version
|
# 证件额度规则版本在首次安排时按生效时间打标,创建不打标。
|
||||||
stamp_plan_rule_version(db, user, plan)
|
|
||||||
db.add(plan)
|
db.add(plan)
|
||||||
db.flush()
|
db.flush()
|
||||||
|
|
||||||
@@ -2531,8 +2529,7 @@ def create_from_contract(
|
|||||||
create_by=user.id,
|
create_by=user.id,
|
||||||
create_dept_id=user.dept_id,
|
create_dept_id=user.dept_id,
|
||||||
)
|
)
|
||||||
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_version
|
# 证件额度规则版本在首次安排时按生效时间打标,创建不打标。
|
||||||
stamp_plan_rule_version(db, user, plan)
|
|
||||||
db.add(plan)
|
db.add(plan)
|
||||||
|
|
||||||
# 查询合同产品明细
|
# 查询合同产品明细
|
||||||
|
|||||||
@@ -888,7 +888,10 @@ def arrange_transport(
|
|||||||
)
|
)
|
||||||
apply_resource_snapshot_json(plan=plan, transport=transport, snapshot=snapshot)
|
apply_resource_snapshot_json(plan=plan, transport=transport, snapshot=snapshot)
|
||||||
from app.services.pl_quota_planning import pin_measurement_version
|
from app.services.pl_quota_planning import pin_measurement_version
|
||||||
|
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_on_arrange
|
||||||
pin_measurement_version(db, user, plan)
|
pin_measurement_version(db, user, plan)
|
||||||
|
# 首次安排按生效时间打标并冻结;改派不重打。
|
||||||
|
stamp_plan_rule_on_arrange(db, user, plan)
|
||||||
plan.transport_status = "arranged"
|
plan.transport_status = "arranged"
|
||||||
plan.follow_status = "arranged"
|
plan.follow_status = "arranged"
|
||||||
plan.freight_amount = freight_amount or 0
|
plan.freight_amount = freight_amount or 0
|
||||||
@@ -1304,11 +1307,13 @@ def process_approval(
|
|||||||
transport.carrier_name = vehicle_info['carrier_name']
|
transport.carrier_name = vehicle_info['carrier_name']
|
||||||
snapshot = build_transport_resource_snapshot(db, tenant_no, transport.vehicle_id,
|
snapshot = build_transport_resource_snapshot(db, tenant_no, transport.vehicle_id,
|
||||||
selected_driver_id=transport.driver_id, selected_escort_id=transport.escort_id)
|
selected_driver_id=transport.driver_id, selected_escort_id=transport.escort_id)
|
||||||
|
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_on_arrange
|
||||||
for plan in plans:
|
for plan in plans:
|
||||||
assert_pl_row_in_scope(db, plan, PlPlan, user, tenant_no)
|
assert_pl_row_in_scope(db, plan, PlPlan, user, tenant_no)
|
||||||
plan.vehicle_id = transport.vehicle_id
|
plan.vehicle_id = transport.vehicle_id
|
||||||
plan.license_plate = transport.license_plate
|
plan.license_plate = transport.license_plate
|
||||||
apply_resource_snapshot_json(plan=plan, transport=transport, snapshot=snapshot)
|
apply_resource_snapshot_json(plan=plan, transport=transport, snapshot=snapshot)
|
||||||
|
stamp_plan_rule_on_arrange(db, user, plan)
|
||||||
apply_plan_quota(db, user, plan, "reserve", payload)
|
apply_plan_quota(db, user, plan, "reserve", payload)
|
||||||
plan.transport_status = "arranged"
|
plan.transport_status = "arranged"
|
||||||
plan.follow_status = "arranged"
|
plan.follow_status = "arranged"
|
||||||
|
|||||||
@@ -370,7 +370,8 @@ class PlPlan(Base):
|
|||||||
quota_cert_waived_by = Column(String(64), nullable=True, comment="证书齐备确认人ID")
|
quota_cert_waived_by = Column(String(64), nullable=True, comment="证书齐备确认人ID")
|
||||||
quota_cert_waived_by_name = Column(String(100), nullable=True, comment="证书齐备确认人姓名")
|
quota_cert_waived_by_name = Column(String(100), nullable=True, comment="证书齐备确认人姓名")
|
||||||
quota_cert_waived_time = Column(DateTime, nullable=True, comment="证书齐备确认时间")
|
quota_cert_waived_time = Column(DateTime, nullable=True, comment="证书齐备确认时间")
|
||||||
cert_quota_rule_version = Column(String(32), nullable=True, comment="证件额度规则版本 legacy|customer_category;创建时打标")
|
cert_quota_rule_version = Column(String(32), nullable=True, comment="证件额度规则版本 legacy|customer_category;首次安排时打标并冻结")
|
||||||
|
cert_quota_arranged_at = Column(DateTime, nullable=True, comment="首次安排时间(证件额度切点用);再次安排不改")
|
||||||
quota_cert_pending_fulfill = Column(SmallInteger, nullable=False, default=0, comment="新规则证书齐备待完善 0-否 1-是")
|
quota_cert_pending_fulfill = Column(SmallInteger, nullable=False, default=0, comment="新规则证书齐备待完善 0-否 1-是")
|
||||||
erp_entered = Column(SmallInteger, nullable=False, default=0, comment="是否已录入ERP 0-否 1-是")
|
erp_entered = Column(SmallInteger, nullable=False, default=0, comment="是否已录入ERP 0-否 1-是")
|
||||||
cancel_reason = Column(String(500), nullable=True, comment="作废原因")
|
cancel_reason = Column(String(500), nullable=True, comment="作废原因")
|
||||||
|
|||||||
@@ -417,7 +417,8 @@ class PlanRead(PlanBase, PlanResourceSnapshotMixin):
|
|||||||
quota_cert_waived_by: Optional[str] = Field(default=None, alias="quotaCertWaivedBy", description="证书齐备确认人ID")
|
quota_cert_waived_by: Optional[str] = Field(default=None, alias="quotaCertWaivedBy", description="证书齐备确认人ID")
|
||||||
quota_cert_waived_by_name: Optional[str] = Field(default=None, alias="quotaCertWaivedByName", description="证书齐备确认人姓名")
|
quota_cert_waived_by_name: Optional[str] = Field(default=None, alias="quotaCertWaivedByName", description="证书齐备确认人姓名")
|
||||||
quota_cert_waived_time: Optional[datetime] = Field(default=None, alias="quotaCertWaivedTime", description="证书齐备确认时间")
|
quota_cert_waived_time: Optional[datetime] = Field(default=None, alias="quotaCertWaivedTime", description="证书齐备确认时间")
|
||||||
cert_quota_rule_version: Optional[str] = Field(default=None, alias="certQuotaRuleVersion", description="legacy|customer_category")
|
cert_quota_rule_version: Optional[str] = Field(default=None, alias="certQuotaRuleVersion", description="legacy|customer_category;首次安排打标")
|
||||||
|
cert_quota_arranged_at: Optional[datetime] = Field(default=None, alias="certQuotaArrangedAt", description="首次安排时间(证件额度切点)")
|
||||||
quota_cert_pending_fulfill: int = Field(default=0, alias="quotaCertPendingFulfill", description="新规则齐备待完善 0否 1是")
|
quota_cert_pending_fulfill: int = Field(default=0, alias="quotaCertPendingFulfill", description="新规则齐备待完善 0否 1是")
|
||||||
erp_entered: int = Field(default=0, alias="erpEntered", description="是否已录入ERP 0-否 1-是")
|
erp_entered: int = Field(default=0, alias="erpEntered", description="是否已录入ERP 0-否 1-是")
|
||||||
cancel_reason: Optional[str] = Field(default=None, alias="cancelReason", description="作废原因")
|
cancel_reason: Optional[str] = Field(default=None, alias="cancelReason", description="作废原因")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
"""客户品类额度规则切点:系统信息配置;未配置则拦住安排。"""
|
"""客户品类额度规则切点:按首次安排时间打标;切点前已安排归档跳过校证。"""
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
@@ -58,20 +58,103 @@ def assert_cert_quota_rule_configured(db: Session, tenant_no: str) -> datetime:
|
|||||||
return effective_at
|
return effective_at
|
||||||
|
|
||||||
|
|
||||||
def resolve_rule_version_for_create(db: Session, tenant_no: str, create_time: Optional[datetime] = None) -> str:
|
def resolve_rule_version_for_arrange(
|
||||||
"""计划创建时打标;未配置生效时间时仍标 legacy(安排会被拦住)。"""
|
db: Session, tenant_no: str, arrange_time: Optional[datetime] = None
|
||||||
|
) -> str:
|
||||||
|
"""首次安排时打标:安排时刻 >= 生效时间 → 新规则,否则祖父 legacy。"""
|
||||||
effective_at = get_effective_at(db, tenant_no)
|
effective_at = get_effective_at(db, tenant_no)
|
||||||
when = create_time or datetime.now()
|
when = arrange_time or datetime.now()
|
||||||
if effective_at is not None and when >= effective_at:
|
if effective_at is not None and when >= effective_at:
|
||||||
return VERSION_CUSTOMER_CATEGORY
|
return VERSION_CUSTOMER_CATEGORY
|
||||||
return VERSION_LEGACY
|
return VERSION_LEGACY
|
||||||
|
|
||||||
|
|
||||||
def stamp_plan_rule_version(db: Session, user, plan) -> str:
|
# 兼容旧测试/调用名;语义已改为安排时刻。
|
||||||
version = resolve_rule_version_for_create(db, user.tenant_no, getattr(plan, 'create_time', None) or datetime.now())
|
resolve_rule_version_for_create = resolve_rule_version_for_arrange
|
||||||
|
|
||||||
|
|
||||||
|
def stamp_plan_rule_on_arrange(
|
||||||
|
db: Session, user, plan, *, arrange_time: Optional[datetime] = None
|
||||||
|
) -> str:
|
||||||
|
"""首次安排写入版本与安排时刻;再次安排冻结,不改版本。"""
|
||||||
|
if getattr(plan, 'cert_quota_arranged_at', None) is not None:
|
||||||
|
return getattr(plan, 'cert_quota_rule_version', None) or VERSION_LEGACY
|
||||||
|
when = arrange_time or datetime.now()
|
||||||
|
version = resolve_rule_version_for_arrange(db, user.tenant_no, when)
|
||||||
|
plan.cert_quota_arranged_at = when
|
||||||
plan.cert_quota_rule_version = version
|
plan.cert_quota_rule_version = version
|
||||||
|
# 安排前已按旧判定齐备时,打成新规则后回补待完善,避免待完善列表漏单。
|
||||||
|
if (
|
||||||
|
version == VERSION_CUSTOMER_CATEGORY
|
||||||
|
and int(getattr(plan, 'quota_cert_waived', 0) or 0) == 1
|
||||||
|
and int(getattr(plan, 'quota_cert_pending_fulfill', 0) or 0) != 1
|
||||||
|
):
|
||||||
|
plan.quota_cert_pending_fulfill = 1
|
||||||
return version
|
return version
|
||||||
|
|
||||||
|
|
||||||
|
def stamp_plan_rule_version(db: Session, user, plan) -> str:
|
||||||
|
"""兼容旧名:等价于首次安排打标(创建路径不应再调用)。"""
|
||||||
|
return stamp_plan_rule_on_arrange(db, user, plan)
|
||||||
|
|
||||||
|
|
||||||
def plan_uses_customer_category(plan) -> bool:
|
def plan_uses_customer_category(plan) -> bool:
|
||||||
|
"""仅看已落库版本;空版本视为 legacy。安排前请用 plan_applies_customer_category_rule。"""
|
||||||
return (getattr(plan, 'cert_quota_rule_version', None) or VERSION_LEGACY) == VERSION_CUSTOMER_CATEGORY
|
return (getattr(plan, 'cert_quota_rule_version', None) or VERSION_LEGACY) == VERSION_CUSTOMER_CATEGORY
|
||||||
|
|
||||||
|
|
||||||
|
def plan_applies_customer_category_rule(db: Session, tenant_no: str, plan) -> bool:
|
||||||
|
"""业务是否按新规则:已打 customer_category,或尚未安排且按当前时刻将落入新规则。
|
||||||
|
|
||||||
|
安排前 `cert_quota_rule_version` 常为空;不能把空当成 legacy,否则会误走合同绑证、
|
||||||
|
漏写齐备待完善。已首次安排并打成 legacy 的计划保持旧规则。
|
||||||
|
"""
|
||||||
|
if plan_uses_customer_category(plan):
|
||||||
|
return True
|
||||||
|
if getattr(plan, 'cert_quota_arranged_at', None) is not None:
|
||||||
|
return False
|
||||||
|
return resolve_rule_version_for_arrange(db, tenant_no) == VERSION_CUSTOMER_CATEGORY
|
||||||
|
|
||||||
|
|
||||||
|
def plan_requires_cert_fulfill(db: Session, tenant_no: str, plan) -> bool:
|
||||||
|
"""齐备后是否须进待完善;与安排是否走新规则同一判定。"""
|
||||||
|
return plan_applies_customer_category_rule(db, tenant_no, plan)
|
||||||
|
|
||||||
|
|
||||||
|
def infer_arranged_at(db: Session, plan) -> Optional[datetime]:
|
||||||
|
"""历史缺字段时用关联运输单创建时间推断首次安排。"""
|
||||||
|
stamped = getattr(plan, 'cert_quota_arranged_at', None)
|
||||||
|
if stamped is not None:
|
||||||
|
return stamped
|
||||||
|
transport_id = getattr(plan, 'transport_id', None)
|
||||||
|
tenant_no = getattr(plan, 'tenant_no', None)
|
||||||
|
if not transport_id or not tenant_no or db is None:
|
||||||
|
return None
|
||||||
|
from app.models.pl_models import PlTransport
|
||||||
|
|
||||||
|
transport = (
|
||||||
|
db.query(PlTransport)
|
||||||
|
.filter_by(id=transport_id, tenant_no=tenant_no, del_flag=0)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
return getattr(transport, 'create_time', None) if transport else None
|
||||||
|
|
||||||
|
|
||||||
|
def plan_skips_archive_cert_quota(plan, db: Session = None, tenant_no: str = None) -> bool:
|
||||||
|
"""首次安排早于生效时间则归档跳过校证。
|
||||||
|
|
||||||
|
优先比较安排时刻与生效时间;若无生效配置或无法得到安排时刻,则不因空版本自动跳过
|
||||||
|
(避免误伤仍走合同绑证结转的历史路径;迁移/安排打标会补齐 arranged_at)。
|
||||||
|
"""
|
||||||
|
tn = tenant_no or getattr(plan, 'tenant_no', None)
|
||||||
|
arranged_at = getattr(plan, 'cert_quota_arranged_at', None)
|
||||||
|
if arranged_at is None and db is not None:
|
||||||
|
arranged_at = infer_arranged_at(db, plan)
|
||||||
|
if arranged_at is None:
|
||||||
|
return False
|
||||||
|
if db is not None and tn:
|
||||||
|
effective_at = get_effective_at(db, tn)
|
||||||
|
if effective_at is not None:
|
||||||
|
return arranged_at < effective_at
|
||||||
|
# 已记录首次安排且版本为 legacy(安排时未达生效点)→ 跳过
|
||||||
|
return not plan_uses_customer_category(plan)
|
||||||
@@ -1166,7 +1166,9 @@ def create_transport_for_plan(
|
|||||||
escort_id=escort_id,
|
escort_id=escort_id,
|
||||||
)
|
)
|
||||||
from app.services.pl_quota_planning import pin_measurement_version
|
from app.services.pl_quota_planning import pin_measurement_version
|
||||||
|
from app.services.pl_cert_quota_rule_config_service import stamp_plan_rule_on_arrange
|
||||||
pin_measurement_version(db, user, plan)
|
pin_measurement_version(db, user, plan)
|
||||||
|
stamp_plan_rule_on_arrange(db, user, plan)
|
||||||
plan.transport_status = "arranged"
|
plan.transport_status = "arranged"
|
||||||
plan.follow_status = "arranged"
|
plan.follow_status = "arranged"
|
||||||
plan.freight_amount = freight_amount or 0
|
plan.freight_amount = freight_amount or 0
|
||||||
|
|||||||
@@ -831,6 +831,15 @@ def assert_stop_contract_required(
|
|||||||
raise HTTPException(status_code=422, detail=f"请为{side_label}选择合同")
|
raise HTTPException(status_code=422, detail=f"请为{side_label}选择合同")
|
||||||
|
|
||||||
|
|
||||||
|
def _clear_internal_stop_product_contracts(stop) -> None:
|
||||||
|
"""山峡/云栋段不占用外部合同;客户端若仍回传产品行合同字段,保存前强制清空。"""
|
||||||
|
if stop is None or not is_internal_customer_name(getattr(stop, 'customer_name', None)):
|
||||||
|
return
|
||||||
|
for prod in getattr(stop, 'products', None) or []:
|
||||||
|
prod.contract_id = None
|
||||||
|
prod.contract_product_id = None
|
||||||
|
|
||||||
|
|
||||||
def _resolve_stop_contracts(
|
def _resolve_stop_contracts(
|
||||||
db: Session,
|
db: Session,
|
||||||
tenant_no: str,
|
tenant_no: str,
|
||||||
@@ -975,6 +984,7 @@ def validate_plan_stops_write(
|
|||||||
"装货合同",
|
"装货合同",
|
||||||
expected_supplier_name=entity_name,
|
expected_supplier_name=entity_name,
|
||||||
)
|
)
|
||||||
|
_clear_internal_stop_product_contracts(load)
|
||||||
|
|
||||||
resolved_deliveries: list[PlanDeliveryBody] = []
|
resolved_deliveries: list[PlanDeliveryBody] = []
|
||||||
for idx, delivery in enumerate(deliveries, start=1):
|
for idx, delivery in enumerate(deliveries, start=1):
|
||||||
@@ -990,6 +1000,7 @@ def validate_plan_stops_write(
|
|||||||
f"送货段#{idx}合同",
|
f"送货段#{idx}合同",
|
||||||
expected_supplier_name=entity_name,
|
expected_supplier_name=entity_name,
|
||||||
)
|
)
|
||||||
|
_clear_internal_stop_product_contracts(delivery)
|
||||||
resolved_deliveries.append(delivery)
|
resolved_deliveries.append(delivery)
|
||||||
|
|
||||||
enrich_stop_addresses_from_library(db, tenant_no, load, resolved_deliveries)
|
enrich_stop_addresses_from_library(db, tenant_no, load, resolved_deliveries)
|
||||||
@@ -1443,6 +1454,7 @@ def replace_plan_stops(
|
|||||||
stop.customer_name, kind, body.generate_dibang, body.dibang_direction)
|
stop.customer_name, kind, body.generate_dibang, body.dibang_direction)
|
||||||
stop.same_city = 1 if int(getattr(body, "same_city", 0) or 0) == 1 else 0
|
stop.same_city = 1 if int(getattr(body, "same_city", 0) or 0) == 1 else 0
|
||||||
stop.del_flag, stop.update_by, stop.update_time = 0, user_id, now
|
stop.del_flag, stop.update_by, stop.update_time = 0, user_id, now
|
||||||
|
internal_stop = is_internal_customer_name(body.customer_name)
|
||||||
model = PlPlanLoadProduct if kind == 'load' else PlPlanDeliveryProduct
|
model = PlPlanLoadProduct if kind == 'load' else PlPlanDeliveryProduct
|
||||||
for idx, (row, product, linked) in enumerate(product_jobs or []):
|
for idx, (row, product, linked) in enumerate(product_jobs or []):
|
||||||
if row is None:
|
if row is None:
|
||||||
@@ -1453,6 +1465,10 @@ def replace_plan_stops(
|
|||||||
for field in product_fields:
|
for field in product_fields:
|
||||||
if field in product.model_fields_set or row.id is None:
|
if field in product.model_fields_set or row.id is None:
|
||||||
setattr(row, field, getattr(product, field))
|
setattr(row, field, getattr(product, field))
|
||||||
|
if internal_stop:
|
||||||
|
# 内部客户段即使客户端漏清/省略合同字段,落库也不得保留外部合同绑定。
|
||||||
|
row.contract_id = None
|
||||||
|
row.contract_product_id = None
|
||||||
row.plan_product_id = linked
|
row.plan_product_id = linked
|
||||||
row.order_num, row.update_by, row.update_time = idx, user_id, now
|
row.order_num, row.update_by, row.update_time = idx, user_id, now
|
||||||
for row in removed:
|
for row in removed:
|
||||||
|
|||||||
@@ -120,12 +120,21 @@ def apply_plan_quota(db, user, plan, action, payload=None):
|
|||||||
evidenceUrls=getattr(payload, 'quota_evidence_urls', None),
|
evidenceUrls=getattr(payload, 'quota_evidence_urls', None),
|
||||||
sourceNote=getattr(payload, 'quota_source_note', None))
|
sourceNote=getattr(payload, 'quota_source_note', None))
|
||||||
from app.services.pl_quota_waiver import assert_waived_sources, quota_cert_waived
|
from app.services.pl_quota_waiver import assert_waived_sources, quota_cert_waived
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
from app.services.pl_cert_quota_rule_config_service import (
|
||||||
|
plan_skips_archive_cert_quota,
|
||||||
|
plan_uses_customer_category,
|
||||||
|
)
|
||||||
# 新规则:齐备仅放行安排/改派预占;归档与实际调整必须真证结转。
|
# 新规则:齐备仅放行安排/改派预占;归档与实际调整必须真证结转。
|
||||||
# 旧规则(legacy):齐备仍跳过安排与归档(祖父兼容)。
|
# 切点前首次安排:归档/实调不校证件(无需齐备);齐备仍可跳过安排预占。
|
||||||
skip_actions = ('reserve', 'resize')
|
skip_actions = ('reserve', 'resize')
|
||||||
if not plan_uses_customer_category(plan):
|
if not plan_uses_customer_category(plan):
|
||||||
skip_actions = ('reserve', 'resize', 'settle', 'actual_adjust')
|
skip_actions = ('reserve', 'resize', 'settle', 'actual_adjust')
|
||||||
|
grandfather_archive_skip = (
|
||||||
|
action in ('settle', 'actual_adjust')
|
||||||
|
and plan_skips_archive_cert_quota(plan, db, getattr(user, 'tenant_no', None))
|
||||||
|
)
|
||||||
|
if grandfather_archive_skip:
|
||||||
|
return {'operationId': ledger_id, 'usageIds': [], 'waived': True, 'skippedCertQuota': True}
|
||||||
if quota_cert_waived(plan) and action in skip_actions:
|
if quota_cert_waived(plan) and action in skip_actions:
|
||||||
if action in ('reserve', 'resize'):
|
if action in ('reserve', 'resize'):
|
||||||
assert_waived_sources(db, user, plan, lock=True)
|
assert_waived_sources(db, user, plan, lock=True)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from app.models.pl_quota_models import (
|
|||||||
PlTransportCert,
|
PlTransportCert,
|
||||||
PlTransportCertPurchaseRef,
|
PlTransportCertPurchaseRef,
|
||||||
PlCertQtyLog,
|
PlCertQtyLog,
|
||||||
|
PlPlanCertUsage,
|
||||||
)
|
)
|
||||||
from app.schemas.pl.quota_planning import ManualQuantity
|
from app.schemas.pl.quota_planning import ManualQuantity
|
||||||
from app.services.pl_cert_category_service import category_ids_for_product
|
from app.services.pl_cert_category_service import category_ids_for_product
|
||||||
@@ -16,8 +17,29 @@ from app.services.pl_quota_cert_service import is_single_use_consumed
|
|||||||
from app.services.pl_quota_units import same_quantity_unit, standard_conversion_ratio
|
from app.services.pl_quota_units import same_quantity_unit, standard_conversion_ratio
|
||||||
|
|
||||||
|
|
||||||
def _available(cert):
|
def _plan_own_reserved(db, user, plan_id, cert_type, cert_id) -> Decimal:
|
||||||
return Decimal(cert.total_qty) - Decimal(cert.used_qty) - Decimal(cert.reserved_qty)
|
"""本计划对该证的预占量;再安排时加回余量,避免把本单占用当成他人占用。"""
|
||||||
|
if not plan_id:
|
||||||
|
return Decimal('0')
|
||||||
|
row = (
|
||||||
|
db.query(PlPlanCertUsage)
|
||||||
|
.filter_by(
|
||||||
|
tenant_no=user.tenant_no,
|
||||||
|
plan_id=plan_id,
|
||||||
|
cert_type=cert_type,
|
||||||
|
cert_id=cert_id,
|
||||||
|
del_flag=0,
|
||||||
|
)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
if row is None:
|
||||||
|
return Decimal('0')
|
||||||
|
return Decimal(row.reserved_qty or 0)
|
||||||
|
|
||||||
|
|
||||||
|
def _available(cert, *, own_reserved=None):
|
||||||
|
own = Decimal(own_reserved if own_reserved is not None else 0)
|
||||||
|
return Decimal(cert.total_qty) - Decimal(cert.used_qty) - Decimal(cert.reserved_qty) + own
|
||||||
|
|
||||||
|
|
||||||
def _in_force(cert, on_date: date) -> bool:
|
def _in_force(cert, on_date: date) -> bool:
|
||||||
@@ -226,6 +248,7 @@ def _linked_transports(db, user, customer_id, purchase_id):
|
|||||||
|
|
||||||
def _diagnose_select_failure(
|
def _diagnose_select_failure(
|
||||||
db, user, source, *, vehicle_no: str, on_date: date, candidates, manual_allocations=(),
|
db, user, source, *, vehicle_no: str, on_date: date, candidates, manual_allocations=(),
|
||||||
|
plan_id=None,
|
||||||
):
|
):
|
||||||
"""选证失败时按证据优先给出单一可执行原因,避免笼统兜底句。"""
|
"""选证失败时按证据优先给出单一可执行原因,避免笼统兜底句。"""
|
||||||
place = '同市' if not source.requires_transport else '异地'
|
place = '同市' if not source.requires_transport else '异地'
|
||||||
@@ -269,7 +292,7 @@ def _diagnose_select_failure(
|
|||||||
if not _in_force(purchase, on_date):
|
if not _in_force(purchase, on_date):
|
||||||
expired_buy.append(purchase)
|
expired_buy.append(purchase)
|
||||||
continue
|
continue
|
||||||
if is_single_use_consumed(db, user, 'purchase', purchase):
|
if is_single_use_consumed(db, user, 'purchase', purchase, exclude_plan_id=plan_id):
|
||||||
consumed_buy.append(purchase)
|
consumed_buy.append(purchase)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
@@ -280,7 +303,8 @@ def _diagnose_select_failure(
|
|||||||
except HTTPException:
|
except HTTPException:
|
||||||
unit_buy.append(purchase)
|
unit_buy.append(purchase)
|
||||||
continue
|
continue
|
||||||
if _available(purchase) < need:
|
buy_own = _plan_own_reserved(db, user, plan_id, 'purchase', purchase.id)
|
||||||
|
if _available(purchase, own_reserved=buy_own) < need:
|
||||||
short_buy.append((purchase, need))
|
short_buy.append((purchase, need))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -305,7 +329,7 @@ def _diagnose_select_failure(
|
|||||||
if not _in_force(transport, on_date):
|
if not _in_force(transport, on_date):
|
||||||
expired_move.append(transport)
|
expired_move.append(transport)
|
||||||
continue
|
continue
|
||||||
if is_single_use_consumed(db, user, 'transport', transport):
|
if is_single_use_consumed(db, user, 'transport', transport, exclude_plan_id=plan_id):
|
||||||
consumed_move.append(transport)
|
consumed_move.append(transport)
|
||||||
continue
|
continue
|
||||||
if not _vehicle_ok(transport, vehicle_no):
|
if not _vehicle_ok(transport, vehicle_no):
|
||||||
@@ -319,7 +343,8 @@ def _diagnose_select_failure(
|
|||||||
except HTTPException:
|
except HTTPException:
|
||||||
unit_move.append(transport)
|
unit_move.append(transport)
|
||||||
continue
|
continue
|
||||||
if _available(transport) < t_need:
|
move_own = _plan_own_reserved(db, user, plan_id, 'transport', transport.id)
|
||||||
|
if _available(transport, own_reserved=move_own) < t_need:
|
||||||
short_move.append((transport, t_need))
|
short_move.append((transport, t_need))
|
||||||
continue
|
continue
|
||||||
purchase_had_ready_transport = True
|
purchase_had_ready_transport = True
|
||||||
@@ -428,11 +453,13 @@ def _diagnose_select_failure(
|
|||||||
|
|
||||||
def select_whole_cover_certs(
|
def select_whole_cover_certs(
|
||||||
db, user, sources, *, vehicle_no: str, on_date: date, manual_allocations=(),
|
db, user, sources, *, vehicle_no: str, on_date: date, manual_allocations=(),
|
||||||
|
plan_id=None,
|
||||||
):
|
):
|
||||||
"""返回 purchase_cert_ids, transport_cert_ids, manual_allocations。
|
"""返回 purchase_cert_ids, transport_cert_ids, manual_allocations。
|
||||||
|
|
||||||
每个来源必须由一张购买证整笔覆盖;异地再配一张关联且车号/余量够的运输证。
|
每个来源必须由一张购买证整笔覆盖;异地再配一张关联且车号/余量够的运输证。
|
||||||
单位无法自动换算时,使用计划段次用证已保存的人工换算量。
|
单位无法自动换算时,使用计划段次用证已保存的人工换算量。
|
||||||
|
plan_id:再安排时排除本计划已占用的一次有效证,并把本单预占加回可选余量。
|
||||||
"""
|
"""
|
||||||
if not sources:
|
if not sources:
|
||||||
return [], [], []
|
return [], [], []
|
||||||
@@ -467,7 +494,7 @@ def select_whole_cover_certs(
|
|||||||
continue
|
continue
|
||||||
if not _in_force(purchase, on_date):
|
if not _in_force(purchase, on_date):
|
||||||
continue
|
continue
|
||||||
if is_single_use_consumed(db, user, 'purchase', purchase):
|
if is_single_use_consumed(db, user, 'purchase', purchase, exclude_plan_id=plan_id):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
need = _need_permit_qty(
|
need = _need_permit_qty(
|
||||||
@@ -476,7 +503,8 @@ def select_whole_cover_certs(
|
|||||||
)
|
)
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
continue
|
continue
|
||||||
if _available(purchase) < need:
|
buy_own = _plan_own_reserved(db, user, plan_id, 'purchase', purchase.id)
|
||||||
|
if _available(purchase, own_reserved=buy_own) < need:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not source.requires_transport:
|
if not source.requires_transport:
|
||||||
@@ -495,7 +523,7 @@ def select_whole_cover_certs(
|
|||||||
continue
|
continue
|
||||||
if not _in_force(transport, on_date):
|
if not _in_force(transport, on_date):
|
||||||
continue
|
continue
|
||||||
if is_single_use_consumed(db, user, 'transport', transport):
|
if is_single_use_consumed(db, user, 'transport', transport, exclude_plan_id=plan_id):
|
||||||
continue
|
continue
|
||||||
if not _vehicle_ok(transport, vehicle_no):
|
if not _vehicle_ok(transport, vehicle_no):
|
||||||
continue
|
continue
|
||||||
@@ -506,7 +534,8 @@ def select_whole_cover_certs(
|
|||||||
)
|
)
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
continue
|
continue
|
||||||
if _available(transport) < t_need:
|
move_own = _plan_own_reserved(db, user, plan_id, 'transport', transport.id)
|
||||||
|
if _available(transport, own_reserved=move_own) < t_need:
|
||||||
continue
|
continue
|
||||||
chosen_purchase = purchase
|
chosen_purchase = purchase
|
||||||
chosen_transport = transport
|
chosen_transport = transport
|
||||||
@@ -522,6 +551,7 @@ def select_whole_cover_certs(
|
|||||||
_diagnose_select_failure(
|
_diagnose_select_failure(
|
||||||
db, user, source, vehicle_no=vehicle_no, on_date=on_date,
|
db, user, source, vehicle_no=vehicle_no, on_date=on_date,
|
||||||
candidates=candidates, manual_allocations=saved_manuals,
|
candidates=candidates, manual_allocations=saved_manuals,
|
||||||
|
plan_id=plan_id,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -131,8 +131,8 @@ def build_usage_request(db, user, plan_id, operation, action, *, lock=False, che
|
|||||||
sources, actuals = [], {}
|
sources, actuals = [], {}
|
||||||
else:
|
else:
|
||||||
sources, actuals = extract_sources(db, user, plan_id, mapping, actual=action in ('settle', 'actual_adjust'), lock=lock, preview_vehicle=preview_vehicle, measurement_version=config.measurement_version)
|
sources, actuals = extract_sources(db, user, plan_id, mapping, actual=action in ('settle', 'actual_adjust'), lock=lock, preview_vehicle=preview_vehicle, measurement_version=config.measurement_version)
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
from app.services.pl_cert_quota_rule_config_service import plan_applies_customer_category_rule
|
||||||
customer_rule = plan_uses_customer_category(plan)
|
customer_rule = plan_applies_customer_category_rule(db, user.tenant_no, plan)
|
||||||
if action in ('reserve', 'resize') and not explicit and sources:
|
if action in ('reserve', 'resize') and not explicit and sources:
|
||||||
if customer_rule:
|
if customer_rule:
|
||||||
# 新规则:禁止手工选证;按客户+品类整笔自动选证
|
# 新规则:禁止手工选证;按客户+品类整笔自动选证
|
||||||
@@ -144,6 +144,7 @@ def build_usage_request(db, user, plan_id, operation, action, *, lock=False, che
|
|||||||
purchase_ids, transport_ids, manuals = select_whole_cover_certs(
|
purchase_ids, transport_ids, manuals = select_whole_cover_certs(
|
||||||
db, user, sources, vehicle_no=vehicle, on_date=on_date,
|
db, user, sources, vehicle_no=vehicle, on_date=on_date,
|
||||||
manual_allocations=config.manual_allocations,
|
manual_allocations=config.manual_allocations,
|
||||||
|
plan_id=plan.id,
|
||||||
)
|
)
|
||||||
config = config.model_copy(update={
|
config = config.model_copy(update={
|
||||||
'purchase_cert_ids': purchase_ids,
|
'purchase_cert_ids': purchase_ids,
|
||||||
@@ -228,10 +229,10 @@ def preview_plan(db, user, plan_id, config, preview_vehicle=None):
|
|||||||
|
|
||||||
def save_configuration(db, user, plan_id, config):
|
def save_configuration(db, user, plan_id, config):
|
||||||
from app.services.pl_plan_service import record_plan_change
|
from app.services.pl_plan_service import record_plan_change
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
from app.services.pl_cert_quota_rule_config_service import plan_applies_customer_category_rule
|
||||||
config = config if isinstance(config, PlanQuotaConfiguration) else PlanQuotaConfiguration.model_validate(config)
|
config = config if isinstance(config, PlanQuotaConfiguration) else PlanQuotaConfiguration.model_validate(config)
|
||||||
plan = _plan(db, user, plan_id, lock=True)
|
plan = _plan(db, user, plan_id, lock=True)
|
||||||
if plan_uses_customer_category(plan):
|
if plan_applies_customer_category_rule(db, user.tenant_no, plan):
|
||||||
raise HTTPException(409, '新规则下安排仅自动选证,不支持手工保存用证配置')
|
raise HTTPException(409, '新规则下安排仅自动选证,不支持手工保存用证配置')
|
||||||
if plan.transport_status == 'arranged' or plan.archive_status == 'archived':
|
if plan.transport_status == 'arranged' or plan.archive_status == 'archived':
|
||||||
raise HTTPException(409, '已安排计划请通过调整运输在同一事务重算用证')
|
raise HTTPException(409, '已安排计划请通过调整运输在同一事务重算用证')
|
||||||
@@ -336,13 +337,35 @@ def get_plan_quota(db, user, plan_id):
|
|||||||
if row.contract_product_id in cert['productIds']]})
|
if row.contract_product_id in cert['productIds']]})
|
||||||
if product.is_toxic == 1:
|
if product.is_toxic == 1:
|
||||||
options.append(item)
|
options.append(item)
|
||||||
usages = db.query(PlPlanCertUsage).filter_by(tenant_no=user.tenant_no, plan_id=plan_id, del_flag=0).order_by(PlPlanCertUsage.create_time.desc()).all()
|
# 关联证件展示只含仍占用/结转中的用量;released 已从配置摘除,不再算作当前关联。
|
||||||
|
usages = (
|
||||||
|
db.query(PlPlanCertUsage)
|
||||||
|
.filter(
|
||||||
|
PlPlanCertUsage.tenant_no == user.tenant_no,
|
||||||
|
PlPlanCertUsage.plan_id == plan_id,
|
||||||
|
PlPlanCertUsage.del_flag == 0,
|
||||||
|
PlPlanCertUsage.usage_status != 'released',
|
||||||
|
)
|
||||||
|
.order_by(PlPlanCertUsage.create_time.desc())
|
||||||
|
.all()
|
||||||
|
)
|
||||||
version = resolve_measurement_version(db, user, plan)
|
version = resolve_measurement_version(db, user, plan)
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
from app.services.pl_cert_quota_rule_config_service import (
|
||||||
customer_rule = plan_uses_customer_category(plan)
|
VERSION_LEGACY,
|
||||||
|
plan_applies_customer_category_rule,
|
||||||
|
resolve_rule_version_for_arrange,
|
||||||
|
)
|
||||||
|
customer_rule = plan_applies_customer_category_rule(db, user.tenant_no, plan)
|
||||||
|
stamped = getattr(plan, 'cert_quota_rule_version', None)
|
||||||
|
if stamped:
|
||||||
|
rule_version = stamped
|
||||||
|
elif getattr(plan, 'cert_quota_arranged_at', None) is None:
|
||||||
|
rule_version = resolve_rule_version_for_arrange(db, user.tenant_no)
|
||||||
|
else:
|
||||||
|
rule_version = VERSION_LEGACY
|
||||||
result = {'planId': plan.id, 'planNo': plan.plan_no, 'licensePlate': plan.license_plate,
|
result = {'planId': plan.id, 'planNo': plan.plan_no, 'licensePlate': plan.license_plate,
|
||||||
'quotaCertWaived': int(getattr(plan, 'quota_cert_waived', 0) or 0) == 1,
|
'quotaCertWaived': int(getattr(plan, 'quota_cert_waived', 0) or 0) == 1,
|
||||||
'certQuotaRuleVersion': getattr(plan, 'cert_quota_rule_version', None) or 'legacy',
|
'certQuotaRuleVersion': rule_version or VERSION_LEGACY,
|
||||||
'measurementVersion': version,
|
'measurementVersion': version,
|
||||||
'configuration': {**(plan.cert_configuration or {}), 'measurementVersion': version}, 'sourceOptions': options,
|
'configuration': {**(plan.cert_configuration or {}), 'measurementVersion': version}, 'sourceOptions': options,
|
||||||
'stopProducts': stop_products,
|
'stopProducts': stop_products,
|
||||||
|
|||||||
@@ -185,9 +185,9 @@ def _execute(db,user,r,digest,plan):
|
|||||||
raise ValueError('已执行用证不得释放预占,请先结转实际量')
|
raise ValueError('已执行用证不得释放预占,请先结转实际量')
|
||||||
for k,u in usages.items():
|
for k,u in usages.items():
|
||||||
certs[k].reserved_qty-=u.reserved_qty; u.reserved_qty=ZERO
|
certs[k].reserved_qty-=u.reserved_qty; u.reserved_qty=ZERO
|
||||||
u.usage_status='released'
|
u.usage_status='released'; u.del_flag=1
|
||||||
for item in items[k]:
|
for item in items[k]:
|
||||||
item.reserved_qty=ZERO; item.item_status='released'
|
item.reserved_qty=ZERO; item.item_status='released'; item.del_flag=1
|
||||||
else:
|
else:
|
||||||
supplement=_settle(db,user,r,certs,usages,items,plan)
|
supplement=_settle(db,user,r,certs,usages,items,plan)
|
||||||
for k,u in usages.items():
|
for k,u in usages.items():
|
||||||
@@ -343,7 +343,12 @@ def _reserve(db,user,r,plan,certs,usages,items,selected,preview=False,lock_previ
|
|||||||
if item.actual_cert_qty is not None or item.item_status in ('in_transit','settled'): raise ValueError('已执行明细不能移除')
|
if item.actual_cert_qty is not None or item.item_status in ('in_transit','settled'): raise ValueError('已执行明细不能移除')
|
||||||
item.del_flag=1; item.reserved_qty=ZERO; item.item_status='released'
|
item.del_flag=1; item.reserved_qty=ZERO; item.item_status='released'
|
||||||
new_qty=sum((a.permit_quantity for a in allocations),ZERO)
|
new_qty=sum((a.permit_quantity for a in allocations),ZERO)
|
||||||
c.reserved_qty+=new_qty-u.reserved_qty; u.reserved_qty=new_qty; u.usage_status='reserved' if allocations else 'released'
|
c.reserved_qty+=new_qty-u.reserved_qty; u.reserved_qty=new_qty
|
||||||
|
# 无分配时标记释放并软删,详情「关联证件」不再展示;再预占同证时复用本行并恢复 del_flag。
|
||||||
|
if allocations:
|
||||||
|
u.usage_status='reserved'; u.del_flag=0
|
||||||
|
else:
|
||||||
|
u.usage_status='released'; u.del_flag=1
|
||||||
u.cert_revision=c.revision; u.confirmed_by=user.id; u.confirmed_time=datetime.now()
|
u.cert_revision=c.revision; u.confirmed_by=user.id; u.confirmed_time=datetime.now()
|
||||||
u.confirmation_snapshot={'executed':False,'vehicleNo':r.vehicle_no,
|
u.confirmation_snapshot={'executed':False,'vehicleNo':r.vehicle_no,
|
||||||
'measurementVersion': next((s.snapshot.get('measurementVersion', 'legacy_single_side') for s in r.sources), 'legacy_single_side')}
|
'measurementVersion': next((s.snapshot.get('measurementVersion', 'legacy_single_side') for s in r.sources), 'legacy_single_side')}
|
||||||
|
|||||||
@@ -269,7 +269,17 @@ def mark_ready(db, user, plan_id):
|
|||||||
plan = _plan(db, user, plan_id, lock=True)
|
plan = _plan(db, user, plan_id, lock=True)
|
||||||
if plan.follow_status == "cancelled" or plan.archive_status == "cancelled":
|
if plan.follow_status == "cancelled" or plan.archive_status == "cancelled":
|
||||||
raise HTTPException(409, "已作废的计划不能标记证书齐备")
|
raise HTTPException(409, "已作废的计划不能标记证书齐备")
|
||||||
|
from app.services.pl_cert_quota_rule_config_service import plan_requires_cert_fulfill
|
||||||
|
|
||||||
if quota_cert_waived(plan):
|
if quota_cert_waived(plan):
|
||||||
|
# 历史:安排前齐备按空版本当成 legacy,漏写 pending;再次调用时回补。
|
||||||
|
if (
|
||||||
|
plan_requires_cert_fulfill(db, user.tenant_no, plan)
|
||||||
|
and int(getattr(plan, "quota_cert_pending_fulfill", 0) or 0) != 1
|
||||||
|
):
|
||||||
|
plan.quota_cert_pending_fulfill = 1
|
||||||
|
plan.update_by = user.id
|
||||||
|
db.flush()
|
||||||
labels = _product_names(db, user, [plan.id])
|
labels = _product_names(db, user, [plan.id])
|
||||||
return _row(plan, labels.get(plan.id, ""))
|
return _row(plan, labels.get(plan.id, ""))
|
||||||
if not db.query(PlPlan.id).filter(PlPlan.id == plan.id, _toxic_exists(db, user.tenant_no)).first():
|
if not db.query(PlPlan.id).filter(PlPlan.id == plan.id, _toxic_exists(db, user.tenant_no)).first():
|
||||||
@@ -290,8 +300,7 @@ def mark_ready(db, user, plan_id):
|
|||||||
plan.quota_cert_waived_by = user.id
|
plan.quota_cert_waived_by = user.id
|
||||||
plan.quota_cert_waived_by_name = name[:100] if name else None
|
plan.quota_cert_waived_by_name = name[:100] if name else None
|
||||||
plan.quota_cert_waived_time = datetime.now()
|
plan.quota_cert_waived_time = datetime.now()
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
if plan_requires_cert_fulfill(db, user.tenant_no, plan):
|
||||||
if plan_uses_customer_category(plan):
|
|
||||||
plan.quota_cert_pending_fulfill = 1
|
plan.quota_cert_pending_fulfill = 1
|
||||||
change_content = "标记证书齐备:可安排运输;归档前须在证书齐备中完善并关闭"
|
change_content = "标记证书齐备:可安排运输;归档前须在证书齐备中完善并关闭"
|
||||||
else:
|
else:
|
||||||
@@ -313,15 +322,15 @@ def mark_ready(db, user, plan_id):
|
|||||||
|
|
||||||
|
|
||||||
def list_pending_fulfill_plans(db, user, page=1, page_size=20, keyword=""):
|
def list_pending_fulfill_plans(db, user, page=1, page_size=20, keyword=""):
|
||||||
"""新规则下已齐备、待完善挂证的计划。"""
|
"""新规则下已齐备、待完善挂证的计划。
|
||||||
from app.services.pl_cert_quota_rule_config_service import VERSION_CUSTOMER_CATEGORY
|
|
||||||
|
|
||||||
|
以 pending 为准;安排前版本可能仍为空,不能再要求 cert_quota_rule_version。
|
||||||
|
"""
|
||||||
query = db.query(PlPlan).filter(
|
query = db.query(PlPlan).filter(
|
||||||
PlPlan.tenant_no == user.tenant_no,
|
PlPlan.tenant_no == user.tenant_no,
|
||||||
PlPlan.del_flag == 0,
|
PlPlan.del_flag == 0,
|
||||||
PlPlan.follow_status != "cancelled",
|
PlPlan.follow_status != "cancelled",
|
||||||
PlPlan.archive_status != "cancelled",
|
PlPlan.archive_status != "cancelled",
|
||||||
PlPlan.cert_quota_rule_version == VERSION_CUSTOMER_CATEGORY,
|
|
||||||
PlPlan.quota_cert_pending_fulfill == 1,
|
PlPlan.quota_cert_pending_fulfill == 1,
|
||||||
PlPlan.quota_cert_waived == 1,
|
PlPlan.quota_cert_waived == 1,
|
||||||
)
|
)
|
||||||
@@ -345,14 +354,14 @@ def list_pending_fulfill_plans(db, user, page=1, page_size=20, keyword=""):
|
|||||||
|
|
||||||
def fulfill_plan_certs(db, user, plan_id, *, operation_id=None):
|
def fulfill_plan_certs(db, user, plan_id, *, operation_id=None):
|
||||||
"""完善并关闭:按安排同款自动选证并 reserve,成功后出队。"""
|
"""完善并关闭:按安排同款自动选证并 reserve,成功后出队。"""
|
||||||
from app.services.pl_cert_quota_rule_config_service import plan_uses_customer_category
|
from app.services.pl_cert_quota_rule_config_service import plan_requires_cert_fulfill
|
||||||
from app.services.pl_plan_service import record_plan_change
|
from app.services.pl_plan_service import record_plan_change
|
||||||
from app.services.pl_quota_business import apply_plan_quota
|
from app.services.pl_quota_business import apply_plan_quota
|
||||||
from app.services.pl_quota_planning import _plan
|
from app.services.pl_quota_planning import _plan
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
|
|
||||||
plan = _plan(db, user, plan_id, lock=True)
|
plan = _plan(db, user, plan_id, lock=True)
|
||||||
if not plan_uses_customer_category(plan):
|
if not plan_requires_cert_fulfill(db, user.tenant_no, plan):
|
||||||
raise HTTPException(409, '仅新规则计划支持完善并关闭')
|
raise HTTPException(409, '仅新规则计划支持完善并关闭')
|
||||||
if int(getattr(plan, 'quota_cert_pending_fulfill', 0) or 0) != 1:
|
if int(getattr(plan, 'quota_cert_pending_fulfill', 0) or 0) != 1:
|
||||||
raise HTTPException(409, '该计划不在证书齐备待完善列表中')
|
raise HTTPException(409, '该计划不在证书齐备待完善列表中')
|
||||||
|
|||||||
@@ -19,16 +19,94 @@ def test_assert_rule_not_configured_blocks_arrange():
|
|||||||
assert '系统信息' in str(exc.value.detail)
|
assert '系统信息' in str(exc.value.detail)
|
||||||
|
|
||||||
|
|
||||||
def test_resolve_rule_version_by_effective_at():
|
def test_resolve_rule_version_by_arrange_effective_at():
|
||||||
from app.services import pl_cert_quota_rule_config_service as cfg
|
from app.services import pl_cert_quota_rule_config_service as cfg
|
||||||
|
|
||||||
db = MagicMock()
|
db = MagicMock()
|
||||||
row = SimpleNamespace(effective_at=datetime(2026, 11, 14, 0, 0, 0))
|
row = SimpleNamespace(effective_at=datetime(2026, 11, 14, 0, 0, 0))
|
||||||
db.query.return_value.filter_by.return_value.first.return_value = row
|
db.query.return_value.filter_by.return_value.first.return_value = row
|
||||||
assert cfg.resolve_rule_version_for_create(db, 't', datetime(2026, 11, 13)) == 'legacy'
|
assert cfg.resolve_rule_version_for_arrange(db, 't', datetime(2026, 11, 13)) == 'legacy'
|
||||||
assert cfg.resolve_rule_version_for_create(db, 't', datetime(2026, 11, 14)) == 'customer_category'
|
assert cfg.resolve_rule_version_for_arrange(db, 't', datetime(2026, 11, 14)) == 'customer_category'
|
||||||
db.query.return_value.filter_by.return_value.first.return_value = None
|
db.query.return_value.filter_by.return_value.first.return_value = None
|
||||||
assert cfg.resolve_rule_version_for_create(db, 't', datetime(2026, 11, 20)) == 'legacy'
|
assert cfg.resolve_rule_version_for_arrange(db, 't', datetime(2026, 11, 20)) == 'legacy'
|
||||||
|
|
||||||
|
|
||||||
|
def test_stamp_plan_rule_version_freezes_first_arrange():
|
||||||
|
from app.services import pl_cert_quota_rule_config_service as cfg
|
||||||
|
|
||||||
|
db = MagicMock()
|
||||||
|
row = SimpleNamespace(effective_at=datetime(2026, 11, 14, 0, 0, 0))
|
||||||
|
db.query.return_value.filter_by.return_value.first.return_value = row
|
||||||
|
user = SimpleNamespace(tenant_no='t', id='u')
|
||||||
|
plan = SimpleNamespace(cert_quota_rule_version=None, cert_quota_arranged_at=None)
|
||||||
|
first = cfg.stamp_plan_rule_on_arrange(db, user, plan, arrange_time=datetime(2026, 11, 13, 10, 0, 0))
|
||||||
|
assert first == 'legacy'
|
||||||
|
assert plan.cert_quota_rule_version == 'legacy'
|
||||||
|
assert plan.cert_quota_arranged_at == datetime(2026, 11, 13, 10, 0, 0)
|
||||||
|
second = cfg.stamp_plan_rule_on_arrange(db, user, plan, arrange_time=datetime(2026, 11, 20, 10, 0, 0))
|
||||||
|
assert second == 'legacy'
|
||||||
|
assert plan.cert_quota_rule_version == 'legacy'
|
||||||
|
assert plan.cert_quota_arranged_at == datetime(2026, 11, 13, 10, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_stamp_after_cutoff_uses_customer_category_even_if_created_earlier():
|
||||||
|
from app.services import pl_cert_quota_rule_config_service as cfg
|
||||||
|
|
||||||
|
db = MagicMock()
|
||||||
|
row = SimpleNamespace(effective_at=datetime(2026, 11, 14, 0, 0, 0))
|
||||||
|
db.query.return_value.filter_by.return_value.first.return_value = row
|
||||||
|
user = SimpleNamespace(tenant_no='t', id='u')
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
create_time=datetime(2026, 11, 1),
|
||||||
|
cert_quota_rule_version=None,
|
||||||
|
cert_quota_arranged_at=None,
|
||||||
|
)
|
||||||
|
version = cfg.stamp_plan_rule_on_arrange(db, user, plan, arrange_time=datetime(2026, 11, 15))
|
||||||
|
assert version == 'customer_category'
|
||||||
|
assert plan.cert_quota_rule_version == 'customer_category'
|
||||||
|
|
||||||
|
|
||||||
|
def test_plan_skips_archive_when_arranged_before_effective_at():
|
||||||
|
from app.services import pl_cert_quota_rule_config_service as cfg
|
||||||
|
|
||||||
|
db = MagicMock()
|
||||||
|
db.query.return_value.filter_by.return_value.first.return_value = SimpleNamespace(
|
||||||
|
effective_at=datetime(2026, 11, 14, 0, 0, 0)
|
||||||
|
)
|
||||||
|
before = SimpleNamespace(
|
||||||
|
tenant_no='t',
|
||||||
|
cert_quota_arranged_at=datetime(2026, 11, 10),
|
||||||
|
cert_quota_rule_version='legacy',
|
||||||
|
transport_id=None,
|
||||||
|
)
|
||||||
|
after = SimpleNamespace(
|
||||||
|
tenant_no='t',
|
||||||
|
cert_quota_arranged_at=datetime(2026, 11, 15),
|
||||||
|
cert_quota_rule_version='customer_category',
|
||||||
|
transport_id=None,
|
||||||
|
)
|
||||||
|
assert cfg.plan_skips_archive_cert_quota(before, db, 't') is True
|
||||||
|
assert cfg.plan_skips_archive_cert_quota(after, db, 't') is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_legacy_arranged_before_cutoff_skips_archive_cert_without_waive(monkeypatch):
|
||||||
|
"""切点前首次安排的计划:归档不校证件,无需证书齐备。"""
|
||||||
|
from app.services import pl_quota_business as biz
|
||||||
|
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
id='p1',
|
||||||
|
quota_cert_waived=0,
|
||||||
|
quota_cert_pending_fulfill=0,
|
||||||
|
cert_quota_rule_version='legacy',
|
||||||
|
cert_quota_arranged_at=datetime(2026, 11, 10),
|
||||||
|
cert_configuration={},
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_cert_quota_rule_config_service.plan_skips_archive_cert_quota',
|
||||||
|
lambda p, db=None, tenant_no=None: True,
|
||||||
|
)
|
||||||
|
result = biz.apply_plan_quota(MagicMock(), SimpleNamespace(id='u', tenant_no='t'), plan, 'settle', None)
|
||||||
|
assert result.get('waived') is True or result.get('skippedCertQuota') is True
|
||||||
|
|
||||||
|
|
||||||
def test_apply_plan_quota_new_rule_waive_skips_reserve_not_settle(monkeypatch):
|
def test_apply_plan_quota_new_rule_waive_skips_reserve_not_settle(monkeypatch):
|
||||||
@@ -663,6 +741,107 @@ def test_whole_cover_skips_once_used_purchase_with_remaining(monkeypatch):
|
|||||||
assert manuals[0].permit_id == 'buy-fresh'
|
assert manuals[0].permit_id == 'buy-fresh'
|
||||||
|
|
||||||
|
|
||||||
|
def test_whole_cover_rearrange_reuses_once_cert_reserved_by_same_plan(monkeypatch):
|
||||||
|
"""已安排计划再次选证:本单已预占的一次有效证不得误判为已使用,并归还本单预占余量。"""
|
||||||
|
from app.services import pl_quota_customer_select as sel
|
||||||
|
from app.schemas.pl.quota_usage import UsageSource
|
||||||
|
from app.models.pl_quota_models import PlPurchaseCert, PlCertQtyLog, PlPlanCertUsage
|
||||||
|
|
||||||
|
source = UsageSource(
|
||||||
|
source_stop_type='delivery',
|
||||||
|
source_stop_id='s1',
|
||||||
|
source_stop_product_id='sp1',
|
||||||
|
plan_product_id='pp1',
|
||||||
|
contract_id='c1',
|
||||||
|
contract_product_id='cp1',
|
||||||
|
product_id='prod1',
|
||||||
|
quantity=Decimal('5'),
|
||||||
|
unit='吨',
|
||||||
|
fingerprint='y' * 64,
|
||||||
|
snapshot={'customerId': 'cust1'},
|
||||||
|
requires_transport=False,
|
||||||
|
)
|
||||||
|
# 与 PO20261116021 现场一致:证面一次有效、本单已预占满额
|
||||||
|
own_cert = SimpleNamespace(
|
||||||
|
id='buy-own', cert_no='G-OWN', customer_id='cust1', category_id='cat1', status='active',
|
||||||
|
verified_by='u', verified_time=datetime.now(), valid_from=None, valid_to=date(2026, 12, 31),
|
||||||
|
total_qty=Decimal('5'), used_qty=Decimal('0'), reserved_qty=Decimal('5'),
|
||||||
|
quantity_unit='吨', opening_single_use_consumed=0, valid_use_text='一次有效',
|
||||||
|
)
|
||||||
|
own_usage = SimpleNamespace(
|
||||||
|
plan_id='plan-self', cert_id='buy-own', usage_status='reserved',
|
||||||
|
reserved_qty=Decimal('5'), confirmation_snapshot=None, del_flag=0,
|
||||||
|
)
|
||||||
|
|
||||||
|
class PurchaseQuery:
|
||||||
|
def filter(self, *a, **k):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def order_by(self, *a, **k):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
return [own_cert]
|
||||||
|
|
||||||
|
class LogQuery:
|
||||||
|
def filter_by(self, **k):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
return SimpleNamespace(id='opening')
|
||||||
|
|
||||||
|
class UsageQuery:
|
||||||
|
def __init__(self):
|
||||||
|
self._filters = {}
|
||||||
|
|
||||||
|
def filter_by(self, **k):
|
||||||
|
self._filters.update(k)
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
# is_single_use_consumed 查全部用量
|
||||||
|
return [own_usage]
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
# _plan_own_reserved 按 plan+cert 查本单预占
|
||||||
|
if self._filters.get('plan_id') == 'plan-self' and self._filters.get('cert_id') == 'buy-own':
|
||||||
|
return own_usage
|
||||||
|
return None
|
||||||
|
|
||||||
|
db = MagicMock()
|
||||||
|
|
||||||
|
def q_side(model):
|
||||||
|
if model is PlPurchaseCert:
|
||||||
|
return PurchaseQuery()
|
||||||
|
if model is PlCertQtyLog:
|
||||||
|
return LogQuery()
|
||||||
|
if model is PlPlanCertUsage:
|
||||||
|
return UsageQuery()
|
||||||
|
return MagicMock()
|
||||||
|
|
||||||
|
db.query.side_effect = q_side
|
||||||
|
user = SimpleNamespace(tenant_no='t')
|
||||||
|
monkeypatch.setattr(sel, 'category_ids_for_product', lambda db, tenant, pid: {'cat1'})
|
||||||
|
# 使用真实占用判定,验证必须传 exclude_plan_id
|
||||||
|
monkeypatch.setattr(sel, 'is_single_use_consumed', __import__(
|
||||||
|
'app.services.pl_quota_cert_service', fromlist=['is_single_use_consumed']
|
||||||
|
).is_single_use_consumed)
|
||||||
|
|
||||||
|
with pytest.raises(HTTPException) as blocked:
|
||||||
|
sel.select_whole_cover_certs(
|
||||||
|
db, user, [source], vehicle_no='皖A12345', on_date=date(2026, 11, 17),
|
||||||
|
)
|
||||||
|
assert '一次有效且已使用' in str(blocked.value.detail)
|
||||||
|
|
||||||
|
purchase_ids, transport_ids, manuals = sel.select_whole_cover_certs(
|
||||||
|
db, user, [source], vehicle_no='皖A12345', on_date=date(2026, 11, 17),
|
||||||
|
plan_id='plan-self',
|
||||||
|
)
|
||||||
|
assert purchase_ids == ['buy-own']
|
||||||
|
assert transport_ids == []
|
||||||
|
assert manuals[0].permit_quantity == Decimal('5')
|
||||||
|
|
||||||
|
|
||||||
def test_list_customers_requires_customer_cert_counts(monkeypatch):
|
def test_list_customers_requires_customer_cert_counts(monkeypatch):
|
||||||
from app.services import pl_quota_statistics as stats
|
from app.services import pl_quota_statistics as stats
|
||||||
|
|
||||||
@@ -1265,8 +1444,9 @@ def test_build_usage_request_passes_saved_manuals_to_customer_select(monkeypatch
|
|||||||
)
|
)
|
||||||
captured = {}
|
captured = {}
|
||||||
|
|
||||||
def fake_select(db, user, sources, *, vehicle_no, on_date, manual_allocations=()):
|
def fake_select(db, user, sources, *, vehicle_no, on_date, manual_allocations=(), plan_id=None):
|
||||||
captured['manual_allocations'] = list(manual_allocations)
|
captured['manual_allocations'] = list(manual_allocations)
|
||||||
|
captured['plan_id'] = plan_id
|
||||||
return ['buy1'], [], list(manual_allocations)
|
return ['buy1'], [], list(manual_allocations)
|
||||||
|
|
||||||
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
||||||
@@ -1293,5 +1473,153 @@ def test_build_usage_request_passes_saved_manuals_to_customer_select(monkeypatch
|
|||||||
)
|
)
|
||||||
assert captured['manual_allocations']
|
assert captured['manual_allocations']
|
||||||
assert captured['manual_allocations'][0].permit_id == 'buy1'
|
assert captured['manual_allocations'][0].permit_id == 'buy1'
|
||||||
|
assert captured['plan_id'] == 'p1'
|
||||||
assert config.purchase_cert_ids == ['buy1']
|
assert config.purchase_cert_ids == ['buy1']
|
||||||
assert request.manual_allocations[0].permit_quantity == Decimal('2.5')
|
assert request.manual_allocations[0].permit_quantity == Decimal('2.5')
|
||||||
|
|
||||||
|
|
||||||
|
def test_unarranged_plan_build_usage_uses_customer_rule_by_effective_at(monkeypatch):
|
||||||
|
"""尚未安排且版本为空时,按生效时间走新规则自动选证,不查合同绑证。"""
|
||||||
|
from app.services import pl_quota_planning as planning
|
||||||
|
from app.schemas.pl.quota_planning import PlanQuotaOperation
|
||||||
|
from app.schemas.pl.quota_usage import UsageSource
|
||||||
|
|
||||||
|
source = UsageSource(
|
||||||
|
source_stop_type='delivery',
|
||||||
|
source_stop_id='d1',
|
||||||
|
source_stop_product_id='sp1',
|
||||||
|
plan_product_id='pp1',
|
||||||
|
contract_id='c1',
|
||||||
|
contract_product_id='cp1',
|
||||||
|
product_id='prod1',
|
||||||
|
quantity=Decimal('33'),
|
||||||
|
unit='dun',
|
||||||
|
fingerprint='f' * 64,
|
||||||
|
snapshot={'customerId': 'cust1'},
|
||||||
|
requires_transport=True,
|
||||||
|
)
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
id='p1',
|
||||||
|
plan_date=date(2026, 11, 14),
|
||||||
|
license_plate='皖R48299',
|
||||||
|
transport_status='pending',
|
||||||
|
archive_status='unarchived',
|
||||||
|
cert_quota_rule_version=None,
|
||||||
|
cert_quota_arranged_at=None,
|
||||||
|
cert_configuration={'measurementVersion': 'per_stop_v2'},
|
||||||
|
tenant_no='t',
|
||||||
|
)
|
||||||
|
called = {'customer_select': 0, 'contract_bind': 0}
|
||||||
|
|
||||||
|
def fake_select(*args, **kwargs):
|
||||||
|
called['customer_select'] += 1
|
||||||
|
return ['buy1'], ['move1'], []
|
||||||
|
|
||||||
|
def fake_contract_bind(*args, **kwargs):
|
||||||
|
called['contract_bind'] += 1
|
||||||
|
raise AssertionError('未安排计划不应再走合同绑证')
|
||||||
|
|
||||||
|
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
||||||
|
monkeypatch.setattr(planning, 'extract_sources', lambda *a, **k: ([source], {}))
|
||||||
|
monkeypatch.setattr(planning, 'resolve_measurement_version', lambda *a, **k: 'per_stop_v2')
|
||||||
|
monkeypatch.setattr(planning, 'plan_execution_lock_reason', lambda *a, **k: None)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_cert_quota_rule_config_service.get_effective_at',
|
||||||
|
lambda *a, **k: datetime(2026, 11, 15, 20, 0, 0),
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_quota_customer_select.select_whole_cover_certs',
|
||||||
|
fake_select,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(planning, 'resolve_contract_bound_certs', fake_contract_bind)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
planning,
|
||||||
|
'_get_row',
|
||||||
|
lambda *a, **k: SimpleNamespace(id='x', revision=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
request, config = planning.build_usage_request(
|
||||||
|
MagicMock(),
|
||||||
|
SimpleNamespace(id='u', tenant_no='t', dept_id=''),
|
||||||
|
'p1',
|
||||||
|
PlanQuotaOperation(operationId='arrange-check'),
|
||||||
|
'reserve',
|
||||||
|
check_conditions=False,
|
||||||
|
)
|
||||||
|
assert called['customer_select'] == 1
|
||||||
|
assert called['contract_bind'] == 0
|
||||||
|
assert config.purchase_cert_ids == ['buy1']
|
||||||
|
assert config.transport_cert_ids == ['move1']
|
||||||
|
assert request.purchase_cert_ids == ['buy1']
|
||||||
|
|
||||||
|
|
||||||
|
def test_arranged_legacy_plan_build_usage_keeps_contract_bind(monkeypatch):
|
||||||
|
"""已首次安排并打成 legacy 的计划,安排/改派预占仍走合同绑证。"""
|
||||||
|
from app.services import pl_quota_planning as planning
|
||||||
|
from app.schemas.pl.quota_planning import PlanQuotaOperation
|
||||||
|
from app.schemas.pl.quota_usage import UsageSource
|
||||||
|
|
||||||
|
source = UsageSource(
|
||||||
|
source_stop_type='delivery',
|
||||||
|
source_stop_id='d1',
|
||||||
|
source_stop_product_id='sp1',
|
||||||
|
plan_product_id='pp1',
|
||||||
|
contract_id='c1',
|
||||||
|
contract_product_id='cp1',
|
||||||
|
product_id='prod1',
|
||||||
|
quantity=Decimal('33'),
|
||||||
|
unit='dun',
|
||||||
|
fingerprint='f' * 64,
|
||||||
|
snapshot={'customerId': 'cust1'},
|
||||||
|
requires_transport=True,
|
||||||
|
)
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
id='p1',
|
||||||
|
plan_date=date(2026, 11, 14),
|
||||||
|
license_plate='皖R48299',
|
||||||
|
transport_status='arranged',
|
||||||
|
archive_status='unarchived',
|
||||||
|
cert_quota_rule_version='legacy',
|
||||||
|
cert_quota_arranged_at=datetime(2026, 11, 14, 10, 0, 0),
|
||||||
|
cert_configuration={'measurementVersion': 'per_stop_v2'},
|
||||||
|
tenant_no='t',
|
||||||
|
)
|
||||||
|
called = {'customer_select': 0, 'contract_bind': 0}
|
||||||
|
|
||||||
|
def fake_select(*args, **kwargs):
|
||||||
|
called['customer_select'] += 1
|
||||||
|
return ['buy1'], ['move1'], []
|
||||||
|
|
||||||
|
def fake_contract_bind(*args, **kwargs):
|
||||||
|
called['contract_bind'] += 1
|
||||||
|
return ['buy1'], ['move1']
|
||||||
|
|
||||||
|
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
||||||
|
monkeypatch.setattr(planning, 'extract_sources', lambda *a, **k: ([source], {}))
|
||||||
|
monkeypatch.setattr(planning, 'resolve_measurement_version', lambda *a, **k: 'per_stop_v2')
|
||||||
|
monkeypatch.setattr(planning, 'plan_execution_lock_reason', lambda *a, **k: None)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_cert_quota_rule_config_service.get_effective_at',
|
||||||
|
lambda *a, **k: datetime(2026, 11, 15, 20, 0, 0),
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_quota_customer_select.select_whole_cover_certs',
|
||||||
|
fake_select,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(planning, 'resolve_contract_bound_certs', fake_contract_bind)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
planning,
|
||||||
|
'_get_row',
|
||||||
|
lambda *a, **k: SimpleNamespace(id='x', revision=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
planning.build_usage_request(
|
||||||
|
MagicMock(),
|
||||||
|
SimpleNamespace(id='u', tenant_no='t', dept_id=''),
|
||||||
|
'p1',
|
||||||
|
PlanQuotaOperation(operationId='arrange-check'),
|
||||||
|
'resize',
|
||||||
|
check_conditions=False,
|
||||||
|
)
|
||||||
|
assert called['contract_bind'] == 1
|
||||||
|
assert called['customer_select'] == 0
|
||||||
@@ -42,6 +42,28 @@ def test_internal_stop_skips_belongs_company_contract_check():
|
|||||||
assert links == []
|
assert links == []
|
||||||
|
|
||||||
|
|
||||||
|
def test_internal_stop_clears_product_contract_fields():
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from app.services.pl_plan_stop_service import _clear_internal_stop_product_contracts
|
||||||
|
|
||||||
|
stop = SimpleNamespace(
|
||||||
|
customer_name="安庆市山峡化工有限公司",
|
||||||
|
products=[
|
||||||
|
SimpleNamespace(contract_id="c-dongheng", contract_product_id="line-1"),
|
||||||
|
SimpleNamespace(contract_id="c-2", contract_product_id="line-2"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
_clear_internal_stop_product_contracts(stop)
|
||||||
|
assert all(p.contract_id is None and p.contract_product_id is None for p in stop.products)
|
||||||
|
|
||||||
|
external = SimpleNamespace(
|
||||||
|
customer_name="安庆市鑫富化工有限责任公司",
|
||||||
|
products=[SimpleNamespace(contract_id="keep", contract_product_id="line")],
|
||||||
|
)
|
||||||
|
_clear_internal_stop_product_contracts(external)
|
||||||
|
assert external.products[0].contract_id == "keep"
|
||||||
|
|
||||||
|
|
||||||
def test_belongs_company_contract_error_is_not_swallowed():
|
def test_belongs_company_contract_error_is_not_swallowed():
|
||||||
mismatch = HTTPException(status_code=422, detail="装货合同的交易主体与归属公司不一致")
|
mismatch = HTTPException(status_code=422, detail="装货合同的交易主体与归属公司不一致")
|
||||||
empty = HTTPException(status_code=422, detail="请先选择归属公司")
|
empty = HTTPException(status_code=422, detail="请先选择归属公司")
|
||||||
|
|||||||
@@ -353,3 +353,49 @@ def test_plan_quota_usages_include_cert_attachment_urls(case):
|
|||||||
assert usages['p1']['attachmentUrls'] == 'https://example.com/buy.jpg'
|
assert usages['p1']['attachmentUrls'] == 'https://example.com/buy.jpg'
|
||||||
assert usages['p1']['certNo'] == 'G-BUY'
|
assert usages['p1']['certNo'] == 'G-BUY'
|
||||||
assert usages['t1']['attachmentUrls'] in ('', None)
|
assert usages['t1']['attachmentUrls'] in ('', None)
|
||||||
|
|
||||||
|
|
||||||
|
def test_plan_quota_usages_hide_released_rows(case, monkeypatch):
|
||||||
|
"""详情关联证件不展示已释放用量,避免改客户后仍显示旧购买证。"""
|
||||||
|
from app.models.crm_models import CrmContract
|
||||||
|
from app.models.pl_quota_models import (
|
||||||
|
PlCertQuotaRuleConfig, PlPlanCertUsage, PlPlanCertUsageItem, PlPurchaseCert,
|
||||||
|
)
|
||||||
|
from app.services.pl_quota_planning import get_plan_quota
|
||||||
|
c = case
|
||||||
|
for model in (CrmContract, PlCertQuotaRuleConfig, PlPlanCertUsage, PlPlanCertUsageItem, PlPurchaseCert):
|
||||||
|
model.__table__.create(c.db.bind, checkfirst=True)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_cert_quota_rule_config_service.plan_applies_customer_category_rule',
|
||||||
|
lambda *a, **k: False,
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
'app.services.pl_cert_quota_rule_config_service.resolve_rule_version_for_arrange',
|
||||||
|
lambda *a, **k: 'legacy',
|
||||||
|
)
|
||||||
|
# 本用例只断言 usages 过滤;清空站点合同避免 get_plan_quota 拉合同表
|
||||||
|
c.db.get(c.m.PlPlanLoadProduct, 'lp').contract_id = None
|
||||||
|
c.db.get(c.m.PlPlanDeliveryProduct, 'dp').contract_id = None
|
||||||
|
c.db.add(PlPurchaseCert(
|
||||||
|
id='p-keep', cert_no='G-KEEP', product_name_on_cert='硫酸', valid_use_text='多次有效',
|
||||||
|
buyer_name='买方', seller_name='卖方', total_qty=33, quantity_unit='吨',
|
||||||
|
tenant_no='t', status='active',
|
||||||
|
))
|
||||||
|
c.db.add(PlPurchaseCert(
|
||||||
|
id='p-old', cert_no='G-OLD', product_name_on_cert='硫酸', valid_use_text='多次有效',
|
||||||
|
buyer_name='买方', seller_name='卖方', total_qty=33, quantity_unit='吨',
|
||||||
|
tenant_no='t', status='active',
|
||||||
|
))
|
||||||
|
c.db.add(PlPlanCertUsage(
|
||||||
|
id='u-keep', tenant_no='t', plan_id='plan', plan_no_snapshot='PLAN',
|
||||||
|
cert_type='purchase', cert_id='p-keep', cert_no_snapshot='G-KEEP', cert_revision=1,
|
||||||
|
quantity_unit='吨', reserved_qty=5, used_qty=0, usage_status='reserved', del_flag=0,
|
||||||
|
))
|
||||||
|
c.db.add(PlPlanCertUsage(
|
||||||
|
id='u-released', tenant_no='t', plan_id='plan', plan_no_snapshot='PLAN',
|
||||||
|
cert_type='purchase', cert_id='p-old', cert_no_snapshot='G-OLD', cert_revision=1,
|
||||||
|
quantity_unit='吨', reserved_qty=0, used_qty=0, usage_status='released', del_flag=0,
|
||||||
|
))
|
||||||
|
c.db.flush()
|
||||||
|
cert_nos = [u['certNo'] for u in get_plan_quota(c.db, c.user, 'plan')['usages']]
|
||||||
|
assert cert_nos == ['G-KEEP']
|
||||||
@@ -330,11 +330,16 @@ def test_no_cert_operation_is_still_idempotent(case):
|
|||||||
def test_removal_and_restore_preserve_item_id(case):
|
def test_removal_and_restore_preserve_item_id(case):
|
||||||
c=case; run(c)
|
c=case; run(c)
|
||||||
ids={i.id for i in c.db.query(c.m.PlPlanCertUsageItem).all()}
|
ids={i.id for i in c.db.query(c.m.PlPlanCertUsageItem).all()}
|
||||||
|
usage_ids={u.id for u in c.db.query(c.m.PlPlanCertUsage).all()}
|
||||||
run(c,action='resize',operation_id='clear',sources=[],purchase_cert_ids=[],transport_cert_ids=[])
|
run(c,action='resize',operation_id='clear',sources=[],purchase_cert_ids=[],transport_cert_ids=[])
|
||||||
assert all(i.del_flag==1 for i in c.db.query(c.m.PlPlanCertUsageItem).all())
|
assert all(i.del_flag==1 for i in c.db.query(c.m.PlPlanCertUsageItem).all())
|
||||||
|
# 清空分配后用量行标记 released 并软删,详情关联证件不再展示
|
||||||
|
assert all(u.usage_status=='released' and u.del_flag==1 for u in c.db.query(c.m.PlPlanCertUsage).all())
|
||||||
run(c,action='resize',operation_id='restore')
|
run(c,action='resize',operation_id='restore')
|
||||||
assert {i.id for i in c.db.query(c.m.PlPlanCertUsageItem).all()}==ids
|
assert {i.id for i in c.db.query(c.m.PlPlanCertUsageItem).all()}==ids
|
||||||
|
assert {u.id for u in c.db.query(c.m.PlPlanCertUsage).all()}==usage_ids
|
||||||
assert all(i.del_flag==0 for i in c.db.query(c.m.PlPlanCertUsageItem).all())
|
assert all(i.del_flag==0 for i in c.db.query(c.m.PlPlanCertUsageItem).all())
|
||||||
|
assert all(u.usage_status=='reserved' and u.del_flag==0 for u in c.db.query(c.m.PlPlanCertUsage).all())
|
||||||
|
|
||||||
def _second_pair(c, cross=False):
|
def _second_pair(c, cross=False):
|
||||||
for kind,model,old_id,new_id,total in [('purchase',c.m.PlPurchaseCert,'p','p2',100),('transport',c.m.PlTransportCert,'t','t2',100)]:
|
for kind,model,old_id,new_id,total in [('purchase',c.m.PlPurchaseCert,'p','p2',100),('transport',c.m.PlTransportCert,'t','t2',100)]:
|
||||||
|
|||||||
@@ -113,6 +113,9 @@ def test_mark_ready_allows_weighed_plan_until_quota_is_posted(monkeypatch):
|
|||||||
quota_cert_waived_by=None,
|
quota_cert_waived_by=None,
|
||||||
quota_cert_waived_by_name=None,
|
quota_cert_waived_by_name=None,
|
||||||
quota_cert_waived_time=None,
|
quota_cert_waived_time=None,
|
||||||
|
quota_cert_pending_fulfill=0,
|
||||||
|
cert_quota_rule_version="legacy",
|
||||||
|
cert_quota_arranged_at=__import__("datetime").datetime(2026, 11, 1, 10, 0, 0),
|
||||||
update_by=None,
|
update_by=None,
|
||||||
plan_no="PO1",
|
plan_no="PO1",
|
||||||
plan_date=None,
|
plan_date=None,
|
||||||
@@ -173,6 +176,173 @@ def test_mark_ready_allows_weighed_plan_until_quota_is_posted(monkeypatch):
|
|||||||
raise AssertionError("已入账仍允许证书齐备")
|
raise AssertionError("已入账仍允许证书齐备")
|
||||||
|
|
||||||
|
|
||||||
|
def test_mark_ready_before_arrange_uses_effective_at_for_pending(monkeypatch):
|
||||||
|
"""安排前版本未打标时,仍按生效时间走新规则并进入待完善。"""
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
from app.models.pl_quota_models import PlPlanCertUsage
|
||||||
|
from app.services.pl_quota_waiver import mark_ready
|
||||||
|
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
id="p1",
|
||||||
|
follow_status="draft",
|
||||||
|
archive_status="unarchived",
|
||||||
|
quota_cert_waived=0,
|
||||||
|
quota_cert_waived_by=None,
|
||||||
|
quota_cert_waived_by_name=None,
|
||||||
|
quota_cert_waived_time=None,
|
||||||
|
quota_cert_pending_fulfill=0,
|
||||||
|
cert_quota_rule_version=None,
|
||||||
|
cert_quota_arranged_at=None,
|
||||||
|
update_by=None,
|
||||||
|
plan_no="PO1",
|
||||||
|
plan_date=None,
|
||||||
|
license_plate=None,
|
||||||
|
supplier_name=None,
|
||||||
|
customer_name=None,
|
||||||
|
)
|
||||||
|
user = SimpleNamespace(id="u1", tenant_no="shanxia2.0", name="齐备员", dept_id="")
|
||||||
|
changes = []
|
||||||
|
|
||||||
|
class Query:
|
||||||
|
def __init__(self, rows):
|
||||||
|
self.rows = rows
|
||||||
|
|
||||||
|
def filter(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def filter_by(self, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
return list(self.rows)
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
return self.rows[0] if self.rows else None
|
||||||
|
|
||||||
|
class DB:
|
||||||
|
def query(self, model):
|
||||||
|
if model is PlPlanCertUsage:
|
||||||
|
return Query([])
|
||||||
|
return Query([plan])
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_planning._plan", lambda *args, **kwargs: plan)
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_waiver._toxic_exists", lambda *args, **kwargs: True)
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_waiver._product_names", lambda *args, **kwargs: {})
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"app.services.pl_plan_service.record_plan_change",
|
||||||
|
lambda *args, **kwargs: changes.append(kwargs),
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"app.services.pl_cert_quota_rule_config_service.get_effective_at",
|
||||||
|
lambda *args, **kwargs: datetime.now() - timedelta(hours=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
mark_ready(DB(), user, "p1")
|
||||||
|
assert plan.quota_cert_waived == 1
|
||||||
|
assert plan.quota_cert_pending_fulfill == 1
|
||||||
|
assert changes and "完善并关闭" in (changes[-1].get("change_content") or "")
|
||||||
|
|
||||||
|
|
||||||
|
def test_mark_ready_stamped_legacy_skips_pending(monkeypatch):
|
||||||
|
"""已按首次安排打成 legacy 的计划,齐备不进待完善。"""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from app.models.pl_quota_models import PlPlanCertUsage
|
||||||
|
from app.services.pl_quota_waiver import mark_ready
|
||||||
|
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
id="p1",
|
||||||
|
follow_status="arranged",
|
||||||
|
archive_status="unarchived",
|
||||||
|
quota_cert_waived=0,
|
||||||
|
quota_cert_waived_by=None,
|
||||||
|
quota_cert_waived_by_name=None,
|
||||||
|
quota_cert_waived_time=None,
|
||||||
|
quota_cert_pending_fulfill=0,
|
||||||
|
cert_quota_rule_version="legacy",
|
||||||
|
cert_quota_arranged_at=datetime(2026, 11, 1, 10, 0, 0),
|
||||||
|
update_by=None,
|
||||||
|
plan_no="PO1",
|
||||||
|
plan_date=None,
|
||||||
|
license_plate=None,
|
||||||
|
supplier_name=None,
|
||||||
|
customer_name=None,
|
||||||
|
)
|
||||||
|
user = SimpleNamespace(id="u1", tenant_no="shanxia2.0", name="齐备员", dept_id="")
|
||||||
|
changes = []
|
||||||
|
|
||||||
|
class Query:
|
||||||
|
def __init__(self, rows):
|
||||||
|
self.rows = rows
|
||||||
|
|
||||||
|
def filter(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def filter_by(self, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def all(self):
|
||||||
|
return list(self.rows)
|
||||||
|
|
||||||
|
def first(self):
|
||||||
|
return self.rows[0] if self.rows else None
|
||||||
|
|
||||||
|
class DB:
|
||||||
|
def query(self, model):
|
||||||
|
if model is PlPlanCertUsage:
|
||||||
|
return Query([])
|
||||||
|
return Query([plan])
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_planning._plan", lambda *args, **kwargs: plan)
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_waiver._toxic_exists", lambda *args, **kwargs: True)
|
||||||
|
monkeypatch.setattr("app.services.pl_quota_waiver._product_names", lambda *args, **kwargs: {})
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"app.services.pl_plan_service.record_plan_change",
|
||||||
|
lambda *args, **kwargs: changes.append(kwargs),
|
||||||
|
)
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"app.services.pl_cert_quota_rule_config_service.get_effective_at",
|
||||||
|
lambda *args, **kwargs: datetime(2026, 11, 15, 20, 0, 0),
|
||||||
|
)
|
||||||
|
|
||||||
|
mark_ready(DB(), user, "p1")
|
||||||
|
assert plan.quota_cert_waived == 1
|
||||||
|
assert plan.quota_cert_pending_fulfill == 0
|
||||||
|
assert changes and "不再校验" in (changes[-1].get("change_content") or "")
|
||||||
|
|
||||||
|
|
||||||
|
def test_stamp_arrange_backfills_pending_when_already_waived(monkeypatch):
|
||||||
|
"""安排打成新规则时,若已齐备则回补待完善。"""
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from app.services.pl_cert_quota_rule_config_service import (
|
||||||
|
VERSION_CUSTOMER_CATEGORY,
|
||||||
|
stamp_plan_rule_on_arrange,
|
||||||
|
)
|
||||||
|
|
||||||
|
plan = SimpleNamespace(
|
||||||
|
cert_quota_arranged_at=None,
|
||||||
|
cert_quota_rule_version=None,
|
||||||
|
quota_cert_waived=1,
|
||||||
|
quota_cert_pending_fulfill=0,
|
||||||
|
)
|
||||||
|
user = SimpleNamespace(tenant_no="shanxia2.0")
|
||||||
|
monkeypatch.setattr(
|
||||||
|
"app.services.pl_cert_quota_rule_config_service.resolve_rule_version_for_arrange",
|
||||||
|
lambda *args, **kwargs: VERSION_CUSTOMER_CATEGORY,
|
||||||
|
)
|
||||||
|
version = stamp_plan_rule_on_arrange(None, user, plan, arrange_time=datetime(2026, 11, 16, 14, 0, 0))
|
||||||
|
assert version == VERSION_CUSTOMER_CATEGORY
|
||||||
|
assert plan.quota_cert_pending_fulfill == 1
|
||||||
|
|
||||||
|
|
||||||
def test_waived_arrange_check_keeps_source_errors_and_skips_cert_balance(monkeypatch):
|
def test_waived_arrange_check_keeps_source_errors_and_skips_cert_balance(monkeypatch):
|
||||||
from app.services.pl_quota_planning import contract_cert_arrange_block
|
from app.services.pl_quota_planning import contract_cert_arrange_block
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
-- 证件额度切点改为首次安排时间:补 arranged_at 列,并按运输单创建时间回填已安排计划。
|
||||||
|
-- MySQL 5.7。可重复执行。
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET @schema_name = DATABASE();
|
||||||
|
|
||||||
|
SET @col = (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA=@schema_name AND TABLE_NAME='pl_plan' AND COLUMN_NAME='cert_quota_arranged_at');
|
||||||
|
SET @sql = IF(@col=0,
|
||||||
|
'ALTER TABLE pl_plan ADD COLUMN cert_quota_arranged_at datetime DEFAULT NULL COMMENT ''首次安排时间(证件额度切点用);再次安排不改'' AFTER cert_quota_rule_version',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s;
|
||||||
|
|
||||||
|
-- 已安排:回填首次安排时刻,并按「安排时刻 vs 生效时间」校正规则版本(修正历史按创建打标)。
|
||||||
|
UPDATE pl_plan p
|
||||||
|
INNER JOIN pl_transport t
|
||||||
|
ON t.id = p.transport_id AND t.tenant_no = p.tenant_no AND t.del_flag = 0
|
||||||
|
LEFT JOIN pl_cert_quota_rule_config cfg
|
||||||
|
ON cfg.tenant_no = p.tenant_no AND cfg.del_flag = 0
|
||||||
|
SET
|
||||||
|
p.cert_quota_arranged_at = COALESCE(p.cert_quota_arranged_at, t.create_time),
|
||||||
|
p.cert_quota_rule_version = CASE
|
||||||
|
WHEN cfg.effective_at IS NOT NULL
|
||||||
|
AND COALESCE(p.cert_quota_arranged_at, t.create_time) >= cfg.effective_at
|
||||||
|
THEN 'customer_category'
|
||||||
|
ELSE 'legacy'
|
||||||
|
END
|
||||||
|
WHERE p.del_flag = 0
|
||||||
|
AND p.transport_status = 'arranged';
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
-- 证件额度切点改为首次安排时间:补 arranged_at 列,并按运输单创建时间回填已安排计划。
|
||||||
|
-- MySQL 5.7。可重复执行。
|
||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET @schema_name = DATABASE();
|
||||||
|
|
||||||
|
SET @col = (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||||
|
WHERE TABLE_SCHEMA=@schema_name AND TABLE_NAME='pl_plan' AND COLUMN_NAME='cert_quota_arranged_at');
|
||||||
|
SET @sql = IF(@col=0,
|
||||||
|
'ALTER TABLE pl_plan ADD COLUMN cert_quota_arranged_at datetime DEFAULT NULL COMMENT ''首次安排时间(证件额度切点用);再次安排不改'' AFTER cert_quota_rule_version',
|
||||||
|
'SELECT 1');
|
||||||
|
PREPARE s FROM @sql; EXECUTE s; DEALLOCATE PREPARE s;
|
||||||
|
|
||||||
|
-- 已安排:回填首次安排时刻,并按「安排时刻 vs 生效时间」校正规则版本(修正历史按创建打标)。
|
||||||
|
UPDATE pl_plan p
|
||||||
|
INNER JOIN pl_transport t
|
||||||
|
ON t.id = p.transport_id AND t.tenant_no = p.tenant_no AND t.del_flag = 0
|
||||||
|
LEFT JOIN pl_cert_quota_rule_config cfg
|
||||||
|
ON cfg.tenant_no = p.tenant_no AND cfg.del_flag = 0
|
||||||
|
SET
|
||||||
|
p.cert_quota_arranged_at = COALESCE(p.cert_quota_arranged_at, t.create_time),
|
||||||
|
p.cert_quota_rule_version = CASE
|
||||||
|
WHEN cfg.effective_at IS NOT NULL
|
||||||
|
AND COALESCE(p.cert_quota_arranged_at, t.create_time) >= cfg.effective_at
|
||||||
|
THEN 'customer_category'
|
||||||
|
ELSE 'legacy'
|
||||||
|
END
|
||||||
|
WHERE p.del_flag = 0
|
||||||
|
AND p.transport_status = 'arranged';
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# 证件额度切点:按首次安排时间(设计)
|
||||||
|
|
||||||
|
工单:[#40](https://gitea.aichengyan.com/cykj/shanxia2.0/issues/40)
|
||||||
|
|
||||||
|
## 背景
|
||||||
|
|
||||||
|
原设计按计划 `create_time` 与 `effective_at` 比较打 `cert_quota_rule_version`。业务要求改为按**首次安排运输**时刻切点;切点前已安排的计划归档不再校购买证/运输证。
|
||||||
|
|
||||||
|
## 定稿规则
|
||||||
|
|
||||||
|
1. **未配置 `effective_at`**:安排仍 409 拦住(不变)。
|
||||||
|
2. **首次安排**时写入:
|
||||||
|
- `cert_quota_arranged_at = 安排时刻`
|
||||||
|
- `cert_quota_rule_version = customer_category` 若 `安排时刻 >= effective_at`,否则 `legacy`
|
||||||
|
3. **再次调整运输**:不重打 `cert_quota_arranged_at` / `cert_quota_rule_version`(冻结首次安排)。
|
||||||
|
4. **创建计划**:不再按创建时间打标(可空,待安排时写入)。
|
||||||
|
5. **归档**:
|
||||||
|
- `legacy`(切点前首次安排):不校验、不扣购买证/运输证,额度结转按跳过处理,允许直接归档。
|
||||||
|
- `customer_category`:保持现有最新业务逻辑(选证、齐备仅放行安排、归档须真证等)。
|
||||||
|
6. **历史已安排且缺 `cert_quota_arranged_at`**:归档/读规则时用关联 `pl_transport.create_time` 推断;若推断时刻 `< effective_at` 视为 `legacy` 祖父。
|
||||||
|
|
||||||
|
## 范围
|
||||||
|
|
||||||
|
- backend:切点服务、安排打标、归档跳过、迁移列
|
||||||
|
- web-admin:系统信息「运输证件规则」说明文案
|
||||||
|
|
||||||
|
## 非目标
|
||||||
|
|
||||||
|
- 不批量改历史 `quota_cert_waived`
|
||||||
|
- 不改选证算法本身
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* 顶栏侧栏收起按钮必须始终可见:
|
||||||
|
* - persist afterRestore 强制 ensureMenuButtonVisible(禁止 toggle)
|
||||||
|
* - AppLayout 挂载时再次兜底
|
||||||
|
* - 设置面板不再提供可关闭开关
|
||||||
|
*/
|
||||||
|
import test from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||||
|
|
||||||
|
test('setting store forces menu button visible on restore', () => {
|
||||||
|
const src = readFileSync(join(root, 'src/store/modules/setting.ts'), 'utf8')
|
||||||
|
assert.match(src, /ensureMenuButtonVisible\s*=\s*\(\)\s*=>\s*\{[\s\S]*?showMenuButton\.value\s*=\s*true/)
|
||||||
|
assert.match(src, /afterRestore:\s*\(ctx\)\s*=>\s*\{[\s\S]*?ensureMenuButtonVisible\(\)/)
|
||||||
|
assert.doesNotMatch(
|
||||||
|
src,
|
||||||
|
/afterRestore:[\s\S]*?if\s*\(\s*!ctx\.store\.showMenuButton\s*\)[\s\S]*?setButton\(\)/,
|
||||||
|
'afterRestore must not rely on setButton toggle'
|
||||||
|
)
|
||||||
|
assert.match(
|
||||||
|
src,
|
||||||
|
/const setButton = \(\) => \{\s*showMenuButton\.value = true/,
|
||||||
|
'setButton must assign true, not toggle'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('AppLayout mount ensures menu button visible', () => {
|
||||||
|
const src = readFileSync(join(root, 'src/views/index/index.vue'), 'utf8')
|
||||||
|
assert.match(src, /ensureMenuButtonVisible\(\)/)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('settings panel does not expose showMenuButton switch', () => {
|
||||||
|
const src = readFileSync(
|
||||||
|
join(root, 'src/components/core/layouts/art-settings-panel/composables/useSettingsConfig.ts'),
|
||||||
|
'utf8'
|
||||||
|
)
|
||||||
|
assert.doesNotMatch(
|
||||||
|
src,
|
||||||
|
/key:\s*'showMenuButton'/,
|
||||||
|
'settings UI must not allow turning off the fold control'
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -12,18 +12,36 @@ import { parse } from '@vue/compiler-sfc'
|
|||||||
|
|
||||||
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||||
|
|
||||||
test('ArtSvgIcon: el-icon branch must not use Tailwind inline class', () => {
|
test('ArtSvgIcon: icon roots must not use Tailwind inline class', () => {
|
||||||
const src = readFileSync(join(root, 'src/components/core/base/art-svg-icon/index.vue'), 'utf8')
|
const src = readFileSync(join(root, 'src/components/core/base/art-svg-icon/index.vue'), 'utf8')
|
||||||
const { descriptor } = parse(src)
|
const { descriptor } = parse(src)
|
||||||
const template = descriptor.template?.content || ''
|
const template = descriptor.template?.content || ''
|
||||||
assert.match(template, /<el-icon\b[^>]*class="[^"]*art-svg-icon/)
|
assert.match(template, /<el-icon\b[^>]*class="[^"]*art-svg-icon/)
|
||||||
assert.doesNotMatch(
|
assert.doesNotMatch(
|
||||||
template,
|
template,
|
||||||
/<el-icon\b[^>]*class="[^"]*\binline\b/,
|
/<(?:el-icon|Icon)\b[^>]*class="[^"]*\binline\b/,
|
||||||
'el-icon must not include Tailwind inline (breaks display:inline-flex in prod CSS order)'
|
'icon roots must not include Tailwind inline (breaks display in prod CSS order)'
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('header fold button uses inline SVG button (Chrome-safe)', () => {
|
||||||
|
const src = readFileSync(
|
||||||
|
join(root, 'src/components/core/layouts/art-header-bar/index.vue'),
|
||||||
|
'utf8'
|
||||||
|
)
|
||||||
|
const { descriptor } = parse(src)
|
||||||
|
const template = descriptor.template?.content || ''
|
||||||
|
assert.match(template, /class="menu-fold-btn/)
|
||||||
|
assert.match(template, /menu-fold-btn__icon/)
|
||||||
|
assert.match(template, /<svg[\s\S]*viewBox="0 0 24 24"/)
|
||||||
|
assert.doesNotMatch(
|
||||||
|
template,
|
||||||
|
/<ArtIconButton[\s\S]*menu-fold/,
|
||||||
|
'fold control must not rely on ArtIconButton/iconify in Chrome'
|
||||||
|
)
|
||||||
|
assert.match(template, /<button[\s\S]*class="menu-fold-btn/)
|
||||||
|
})
|
||||||
|
|
||||||
test('plan-archive: planNo is in column defs and table visibility gate', () => {
|
test('plan-archive: planNo is in column defs and table visibility gate', () => {
|
||||||
const src = readFileSync(join(root, 'src/views/pl/plan-archive/index.vue'), 'utf8')
|
const src = readFileSync(join(root, 'src/views/pl/plan-archive/index.vue'), 'utf8')
|
||||||
assert.match(src, /prop:\s*'planNo',\s*label:\s*'计划编号'/)
|
assert.match(src, /prop:\s*'planNo',\s*label:\s*'计划编号'/)
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/**
|
||||||
|
* #41 回归:运输归档绿色合计行须与表头列一一对应。
|
||||||
|
* planNo 可隐藏后,不得再无条件硬编码插入 planNo,否则按索引错位。
|
||||||
|
*/
|
||||||
|
import test from 'node:test'
|
||||||
|
import assert from 'node:assert/strict'
|
||||||
|
import { readFileSync } from 'node:fs'
|
||||||
|
import { dirname, join } from 'node:path'
|
||||||
|
import { fileURLToPath } from 'node:url'
|
||||||
|
import { buildStatsRowColumns } from '../src/utils/list-column-stats.ts'
|
||||||
|
|
||||||
|
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
||||||
|
|
||||||
|
const ARCHIVE_DEFS = [
|
||||||
|
{ prop: 'planNo' },
|
||||||
|
{ prop: 'planDate' },
|
||||||
|
{ prop: 'planQty' },
|
||||||
|
{ prop: 'actualQty' },
|
||||||
|
{ prop: 'amount' }
|
||||||
|
]
|
||||||
|
|
||||||
|
test('buildStatsRowColumns: hidden planNo must not leave a phantom stats cell', () => {
|
||||||
|
const visible = new Set(['planDate', 'planQty', 'actualQty', 'amount'])
|
||||||
|
const cols = buildStatsRowColumns({
|
||||||
|
leadingSpacers: 2,
|
||||||
|
optionalDefs: ARCHIVE_DEFS,
|
||||||
|
isColumnVisible: (prop) => visible.has(prop),
|
||||||
|
moneyProps: ['amount']
|
||||||
|
})
|
||||||
|
const props = cols.map((c) => c.prop || c.key)
|
||||||
|
assert.deepEqual(props, [
|
||||||
|
'__spacer_0',
|
||||||
|
'__spacer_1',
|
||||||
|
'planDate',
|
||||||
|
'planQty',
|
||||||
|
'actualQty',
|
||||||
|
'amount'
|
||||||
|
])
|
||||||
|
assert.equal(cols.filter((c) => c.prop === 'planNo').length, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('buildStatsRowColumns: visible planNo appears once after spacers', () => {
|
||||||
|
const visible = new Set(['planNo', 'planDate', 'planQty'])
|
||||||
|
const cols = buildStatsRowColumns({
|
||||||
|
leadingSpacers: 2,
|
||||||
|
optionalDefs: ARCHIVE_DEFS,
|
||||||
|
isColumnVisible: (prop) => visible.has(prop)
|
||||||
|
})
|
||||||
|
const props = cols.map((c) => c.prop || c.key)
|
||||||
|
assert.deepEqual(props, ['__spacer_0', '__spacer_1', 'planNo', 'planDate', 'planQty'])
|
||||||
|
assert.equal(cols.filter((c) => c.prop === 'planNo').length, 1)
|
||||||
|
})
|
||||||
|
|
||||||
|
test('plan-archive: stats row builds from visible columns without always-on planNo', () => {
|
||||||
|
const src = readFileSync(join(root, 'src/views/pl/plan-archive/index.vue'), 'utf8')
|
||||||
|
assert.match(
|
||||||
|
src,
|
||||||
|
/archiveStatsRowColumns[\s\S]*?buildStatsRowColumns\s*\(/,
|
||||||
|
'archive stats columns should use buildStatsRowColumns so visibility stays in sync'
|
||||||
|
)
|
||||||
|
assert.doesNotMatch(
|
||||||
|
src,
|
||||||
|
/archiveStatsRowColumns[\s\S]*?key:\s*'__index'[\s\S]*?key:\s*'planNo'[\s\S]*?for\s*\(\s*const\s+def\s+of\s+listColumnDefs/,
|
||||||
|
'must not hardcode planNo before looping listColumnDefs (causes off-by-one when hidden)'
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
<!-- 图标组件:支持 Element Plus 图标(无 : 前缀)与 Iconify 图标(含 : 前缀) -->
|
<!-- 图标组件:支持 Element Plus 图标(无 : 前缀)与 Iconify 图标(含 : 前缀) -->
|
||||||
<template>
|
<template>
|
||||||
<!-- el-icon 勿加 Tailwind `inline`:生产 CSS 中 `.inline{display:inline}` 会覆盖
|
<!-- 勿给图标根节点加 Tailwind `inline`:生产 CSS 中 `.inline{display:inline}`
|
||||||
`.el-icon{display:inline-flex}`,导致 Fold 等图标在打包后不可见 -->
|
会覆盖 flex/尺寸,部分 Chrome 下 Fold 等图标不可见 -->
|
||||||
<el-icon v-if="epIcon" v-bind="iconAttrs" class="art-svg-icon">
|
<el-icon v-if="epIcon" v-bind="iconAttrs" class="art-svg-icon">
|
||||||
<component :is="epIcon" />
|
<component :is="epIcon" />
|
||||||
</el-icon>
|
</el-icon>
|
||||||
<Icon v-else-if="icon" :icon="icon" v-bind="iconAttrs" class="art-svg-icon inline" />
|
<Icon v-else-if="icon" :icon="icon" v-bind="iconAttrs" class="art-svg-icon" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|||||||
@@ -21,17 +21,31 @@
|
|||||||
@click="toHome"
|
@click="toHome"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 菜单按钮 -->
|
<!-- 菜单按钮:内联 SVG,避开 Chrome 下 el-icon / Iconify 偶发不绘制 -->
|
||||||
<ArtIconButton
|
<button
|
||||||
v-if="isLeftMenu && shouldShowMenuButton"
|
v-if="isLeftMenu && shouldShowMenuButton"
|
||||||
icon="fold"
|
type="button"
|
||||||
class="ml-3 max-sm:ml-[7px] menu-fold-btn"
|
class="menu-fold-btn"
|
||||||
:class="{ 'is-menu-collapsed': !menuOpen }"
|
:class="{ 'is-menu-collapsed': !menuOpen }"
|
||||||
:title="menuOpen ? '收起菜单' : '展开菜单'"
|
:title="menuOpen ? '收起菜单' : '展开菜单'"
|
||||||
:aria-label="menuOpen ? '收起菜单' : '展开菜单'"
|
:aria-label="menuOpen ? '收起菜单' : '展开菜单'"
|
||||||
:aria-expanded="menuOpen"
|
:aria-expanded="menuOpen"
|
||||||
@click="visibleMenu"
|
@click="visibleMenu"
|
||||||
/>
|
>
|
||||||
|
<svg
|
||||||
|
class="menu-fold-btn__icon"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="20"
|
||||||
|
height="20"
|
||||||
|
aria-hidden="true"
|
||||||
|
focusable="false"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill="currentColor"
|
||||||
|
d="M21 18v2H3v-2zm0-5v2h-9v-2zm0-5v2h-9V8zM3 3.5v10l5-5z"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
|
||||||
<!-- 刷新按钮 - 已隐藏 -->
|
<!-- 刷新按钮 - 已隐藏 -->
|
||||||
<ArtIconButton
|
<ArtIconButton
|
||||||
@@ -388,14 +402,49 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-fold-btn :deep(.art-svg-icon) {
|
/* 顶栏折叠按钮:原生 button + 内联 SVG,保证 Chrome/Safari 一致可见 */
|
||||||
transition: transform 0.3s ease;
|
.menu-fold-btn {
|
||||||
|
box-sizing: border-box;
|
||||||
|
display: inline-flex;
|
||||||
|
flex-shrink: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
width: 34px;
|
||||||
|
height: 34px;
|
||||||
|
margin-left: 12px;
|
||||||
|
padding: 0;
|
||||||
|
color: #64748b;
|
||||||
|
cursor: pointer;
|
||||||
|
background: transparent;
|
||||||
|
border: 0;
|
||||||
|
border-radius: 8px;
|
||||||
|
appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-fold-btn.is-menu-collapsed :deep(.art-svg-icon) {
|
@media (max-width: 640px) {
|
||||||
|
.menu-fold-btn {
|
||||||
|
margin-left: 7px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-fold-btn:hover {
|
||||||
|
color: #1e293b;
|
||||||
|
background: var(--mint-row-alt, #f1f5f9);
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-fold-btn__icon {
|
||||||
|
display: block;
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
transition: transform 0.3s ease;
|
||||||
|
/* 展开态默认旋转,与收起态对调 */
|
||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu-fold-btn.is-menu-collapsed .menu-fold-btn__icon {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
/* Hover animation classes */
|
/* Hover animation classes */
|
||||||
.refresh-btn:hover :deep(.art-svg-icon) {
|
.refresh-btn:hover :deep(.art-svg-icon) {
|
||||||
animation: rotate180 0.5s;
|
animation: rotate180 0.5s;
|
||||||
|
|||||||
+1
-7
@@ -119,13 +119,7 @@ export function useSettingsConfig() {
|
|||||||
handler: 'uniqueOpened',
|
handler: 'uniqueOpened',
|
||||||
headerBarKey: null // 不依赖headerBar配置
|
headerBarKey: null // 不依赖headerBar配置
|
||||||
},
|
},
|
||||||
{
|
// showMenuButton 不提供开关:顶栏收起侧栏按钮为产品必显能力
|
||||||
key: 'showMenuButton',
|
|
||||||
label: t('setting.basics.list.collapseSidebar'),
|
|
||||||
type: 'switch' as const,
|
|
||||||
handler: 'menuButton',
|
|
||||||
headerBarKey: 'menuButton' as const
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
key: 'showFastEnter',
|
key: 'showFastEnter',
|
||||||
label: t('setting.basics.list.fastEnter'),
|
label: t('setting.basics.list.fastEnter'),
|
||||||
|
|||||||
+1
-1
@@ -67,7 +67,7 @@ export function useSettingsHandlers() {
|
|||||||
uniqueOpened: createToggleHandler(() => settingStore.setUniqueOpened()),
|
uniqueOpened: createToggleHandler(() => settingStore.setUniqueOpened()),
|
||||||
|
|
||||||
// 显示菜单按钮
|
// 显示菜单按钮
|
||||||
menuButton: createToggleHandler(() => settingStore.setButton()),
|
menuButton: createToggleHandler(() => settingStore.ensureMenuButtonVisible()),
|
||||||
|
|
||||||
// 显示快速入口
|
// 显示快速入口
|
||||||
fastEnter: createToggleHandler(() => settingStore.setFastEnter()),
|
fastEnter: createToggleHandler(() => settingStore.setFastEnter()),
|
||||||
|
|||||||
@@ -185,9 +185,8 @@
|
|||||||
settingStore.setElementTheme(config.systemThemeColor)
|
settingStore.setElementTheme(config.systemThemeColor)
|
||||||
|
|
||||||
// 界面显示(切换类方法)
|
// 界面显示(切换类方法)
|
||||||
toggleIfDifferent(settingStore.showMenuButton, config.showMenuButton, () =>
|
// 顶栏收起按钮为必显,导入配置时也强制打开
|
||||||
settingStore.setButton()
|
settingStore.ensureMenuButtonVisible()
|
||||||
)
|
|
||||||
toggleIfDifferent(settingStore.showFastEnter, config.showFastEnter, () =>
|
toggleIfDifferent(settingStore.showFastEnter, config.showFastEnter, () =>
|
||||||
settingStore.setFastEnter()
|
settingStore.setFastEnter()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -227,10 +227,15 @@ export const useSettingStore = defineStore(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 切换菜单按钮显示
|
* 切换菜单按钮显示(产品要求顶栏始终可收起侧栏,禁止关闭)
|
||||||
*/
|
*/
|
||||||
const setButton = () => {
|
const setButton = () => {
|
||||||
showMenuButton.value = !showMenuButton.value
|
showMenuButton.value = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 强制显示顶栏侧栏收起按钮,修复旧 localStorage 中 false 残留 */
|
||||||
|
const ensureMenuButtonVisible = () => {
|
||||||
|
showMenuButton.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,6 +428,7 @@ export const useSettingStore = defineStore(
|
|||||||
setContainerWidth,
|
setContainerWidth,
|
||||||
setUniqueOpened,
|
setUniqueOpened,
|
||||||
setButton,
|
setButton,
|
||||||
|
ensureMenuButtonVisible,
|
||||||
setFastEnter,
|
setFastEnter,
|
||||||
setAutoClose,
|
setAutoClose,
|
||||||
setShowRefreshButton,
|
setShowRefreshButton,
|
||||||
@@ -458,10 +464,8 @@ export const useSettingStore = defineStore(
|
|||||||
} else if (width === 290) {
|
} else if (width === 290) {
|
||||||
ctx.store.setMenuOpenWidth(270)
|
ctx.store.setMenuOpenWidth(270)
|
||||||
}
|
}
|
||||||
// 旧本地配置把收起按钮关掉了;产品需要顶栏始终能收起侧栏
|
// 旧本地配置(sys-v*-setting)可能残留 showMenuButton:false;必须赋值 true,禁止用 toggle
|
||||||
if (!ctx.store.showMenuButton) {
|
ctx.store.ensureMenuButtonVisible()
|
||||||
ctx.store.setButton()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,6 +75,8 @@
|
|||||||
if (!settingStore.showCrumbs) {
|
if (!settingStore.showCrumbs) {
|
||||||
settingStore.setCrumbs()
|
settingStore.setCrumbs()
|
||||||
}
|
}
|
||||||
|
// 纠正版本化 localStorage 中 showMenuButton:false,保证折叠钮始终可见
|
||||||
|
settingStore.ensureMenuButtonVisible()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -970,7 +970,7 @@ import {
|
|||||||
overflowExportPlaceholder
|
overflowExportPlaceholder
|
||||||
} from '@/utils/list-toolbar-overflow-items'
|
} from '@/utils/list-toolbar-overflow-items'
|
||||||
import ListColumnStatsRow from '@/components/business/list-column-stats-row/index.vue'
|
import ListColumnStatsRow from '@/components/business/list-column-stats-row/index.vue'
|
||||||
import type { StatsRowColumn } from '@/utils/list-column-stats'
|
import { buildStatsRowColumns, type StatsRowColumn } from '@/utils/list-column-stats'
|
||||||
import { useContractDetailDialog } from '@/composables/useContractDetailDialog'
|
import { useContractDetailDialog } from '@/composables/useContractDetailDialog'
|
||||||
import { usePersistedListColumns } from '@/composables/usePersistedListColumns'
|
import { usePersistedListColumns } from '@/composables/usePersistedListColumns'
|
||||||
import { useListTableViewportHeight } from '@/composables/useListTableViewportHeight'
|
import { useListTableViewportHeight } from '@/composables/useListTableViewportHeight'
|
||||||
@@ -1287,22 +1287,15 @@ const {
|
|||||||
|
|
||||||
const archiveStatsRowRef = ref<{ resync?: () => void } | null>(null)
|
const archiveStatsRowRef = ref<{ resync?: () => void } | null>(null)
|
||||||
|
|
||||||
const archiveStatsRowColumns = computed((): StatsRowColumn[] => {
|
/** 与表头可见列一一对应:勾选/序号占位 + 可见业务列(含可隐藏的 planNo) */
|
||||||
const cols: StatsRowColumn[] = [
|
const archiveStatsRowColumns = computed((): StatsRowColumn[] =>
|
||||||
{ key: '__selection', interactive: false },
|
buildStatsRowColumns({
|
||||||
{ key: '__index', interactive: false },
|
leadingSpacers: 2,
|
||||||
{ key: 'planNo', interactive: true, prop: 'planNo' }
|
optionalDefs: listColumnDefs.value,
|
||||||
]
|
isColumnVisible: isArchiveColumnVisible,
|
||||||
for (const def of listColumnDefs.value) {
|
moneyProps: PRICE_COLUMN_PROPS
|
||||||
if (!isArchiveColumnVisible(def.prop)) continue
|
})
|
||||||
cols.push({
|
)
|
||||||
key: def.prop,
|
|
||||||
interactive: true,
|
|
||||||
prop: def.prop
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return cols
|
|
||||||
})
|
|
||||||
|
|
||||||
function getArchiveStatCellValue(row: PlPlanListDisplayRow, prop: string): unknown {
|
function getArchiveStatCellValue(row: PlPlanListDisplayRow, prop: string): unknown {
|
||||||
const plan = row.plan
|
const plan = row.plan
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="p-6 max-w-xl">
|
<div class="p-6 max-w-xl">
|
||||||
<p class="text-sm text-slate-500 mb-4">
|
<p class="text-sm text-slate-500 mb-4">
|
||||||
配置「客户+品类」额度生效时间。未配置时无法安排运输。计划创建时按该时间打规则版本;修改后只影响之后新建的计划。
|
配置「客户+品类」额度生效时间。未配置时无法安排运输。以计划首次安排时刻与该时间比较:之前已安排的归档不再校验购买证/运输证;之后安排的走客户+品类最新规则。首次安排后版本冻结,改派不重打;修改生效时间只影响尚未安排的计划。
|
||||||
</p>
|
</p>
|
||||||
<el-form label-position="top" class="dialog-form-layout">
|
<el-form label-position="top" class="dialog-form-layout">
|
||||||
<el-form-item label="客户品类额度生效时间">
|
<el-form-item label="客户品类额度生效时间">
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# MinIO(bucket=ruoyi);兼容旧链接,推荐逐步切到 res.shanxiachem.com
|
# MinIO(bucket=ruoyi);兼容旧链接,推荐逐步切到 res.shanxiachem.com
|
||||||
|
# 必须 proxy_hide_header 上游 CORS,否则 MinIO 的 Origin 与 nginx 的 * 叠成非法双头
|
||||||
location ^~ /ruoyi/ {
|
location ^~ /ruoyi/ {
|
||||||
proxy_pass http://127.0.0.1:9000;
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
|
||||||
@@ -96,8 +97,15 @@ server {
|
|||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
|
|
||||||
|
proxy_hide_header Access-Control-Allow-Origin;
|
||||||
|
proxy_hide_header Access-Control-Allow-Methods;
|
||||||
|
proxy_hide_header Access-Control-Allow-Headers;
|
||||||
|
proxy_hide_header Access-Control-Expose-Headers;
|
||||||
|
proxy_hide_header Access-Control-Allow-Credentials;
|
||||||
|
|
||||||
add_header Access-Control-Allow-Origin * always;
|
add_header Access-Control-Allow-Origin * always;
|
||||||
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
||||||
|
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
return 204;
|
return 204;
|
||||||
@@ -224,6 +232,7 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 必须 proxy_hide_header 上游 CORS,否则 MinIO 的 Origin 与 nginx 的 * 叠成非法双头
|
||||||
location ^~ /ruoyi/ {
|
location ^~ /ruoyi/ {
|
||||||
proxy_pass http://127.0.0.1:9000;
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
|
||||||
@@ -236,8 +245,15 @@ server {
|
|||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
|
|
||||||
|
proxy_hide_header Access-Control-Allow-Origin;
|
||||||
|
proxy_hide_header Access-Control-Allow-Methods;
|
||||||
|
proxy_hide_header Access-Control-Allow-Headers;
|
||||||
|
proxy_hide_header Access-Control-Expose-Headers;
|
||||||
|
proxy_hide_header Access-Control-Allow-Credentials;
|
||||||
|
|
||||||
add_header Access-Control-Allow-Origin * always;
|
add_header Access-Control-Allow-Origin * always;
|
||||||
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
||||||
|
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
return 204;
|
return 204;
|
||||||
@@ -364,6 +380,7 @@ server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 必须 proxy_hide_header 上游 CORS,否则 MinIO 的 Origin 与 nginx 的 * 叠成非法双头
|
||||||
location ^~ /ruoyi/ {
|
location ^~ /ruoyi/ {
|
||||||
proxy_pass http://127.0.0.1:9000;
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
|
||||||
@@ -376,8 +393,15 @@ server {
|
|||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
|
|
||||||
|
proxy_hide_header Access-Control-Allow-Origin;
|
||||||
|
proxy_hide_header Access-Control-Allow-Methods;
|
||||||
|
proxy_hide_header Access-Control-Allow-Headers;
|
||||||
|
proxy_hide_header Access-Control-Expose-Headers;
|
||||||
|
proxy_hide_header Access-Control-Allow-Credentials;
|
||||||
|
|
||||||
add_header Access-Control-Allow-Origin * always;
|
add_header Access-Control-Allow-Origin * always;
|
||||||
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
||||||
|
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||||
|
|
||||||
if ($request_method = 'OPTIONS') {
|
if ($request_method = 'OPTIONS') {
|
||||||
return 204;
|
return 204;
|
||||||
@@ -477,6 +501,7 @@ server {
|
|||||||
|
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
|
||||||
|
# 必须 proxy_hide_header 上游 CORS,否则 MinIO 的 Origin 与 nginx 的 * 叠成非法双头
|
||||||
location ^~ /ruoyi/ {
|
location ^~ /ruoyi/ {
|
||||||
proxy_pass http://127.0.0.1:9000;
|
proxy_pass http://127.0.0.1:9000;
|
||||||
|
|
||||||
@@ -489,6 +514,12 @@ server {
|
|||||||
proxy_send_timeout 60s;
|
proxy_send_timeout 60s;
|
||||||
proxy_read_timeout 60s;
|
proxy_read_timeout 60s;
|
||||||
|
|
||||||
|
proxy_hide_header Access-Control-Allow-Origin;
|
||||||
|
proxy_hide_header Access-Control-Allow-Methods;
|
||||||
|
proxy_hide_header Access-Control-Allow-Headers;
|
||||||
|
proxy_hide_header Access-Control-Expose-Headers;
|
||||||
|
proxy_hide_header Access-Control-Allow-Credentials;
|
||||||
|
|
||||||
add_header Access-Control-Allow-Origin * always;
|
add_header Access-Control-Allow-Origin * always;
|
||||||
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS' always;
|
||||||
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always;
|
||||||
|
|||||||
Reference in new issue
Block a user