1 parent
96468f3c48
commit
bd669ea77e
2 files changed
+170
-5
No files matched your search
@@ -259,3 +259,129 @@ def test_admin_and_market_bodies_accept_sf_without_amount():
|
||||
})
|
||||
assert draft.waybill_no == "SF100"
|
||||
MarketFreightUpdateBody.model_validate({"waybillNo": "SF100"})
|
||||
|
||||
|
||||
def _protocol_freight_db():
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
|
||||
from app.models.base import Base
|
||||
from app.models.models import (
|
||||
BizCellSampleType,
|
||||
BizCollectionProtocol,
|
||||
BizProtocolPartyCustomer,
|
||||
BizProtocolSample,
|
||||
BizSampleFreight,
|
||||
BizSampleFreightItem,
|
||||
SysDictData,
|
||||
)
|
||||
|
||||
engine = create_engine("sqlite:///:memory:")
|
||||
Base.metadata.create_all(
|
||||
engine,
|
||||
tables=[
|
||||
BizSampleFreight.__table__,
|
||||
BizSampleFreightItem.__table__,
|
||||
BizProtocolSample.__table__,
|
||||
BizCollectionProtocol.__table__,
|
||||
BizCellSampleType.__table__,
|
||||
BizProtocolPartyCustomer.__table__,
|
||||
SysDictData.__table__,
|
||||
],
|
||||
)
|
||||
return sessionmaker(bind=engine)()
|
||||
|
||||
|
||||
def _seed_settled_protocol_freight(db, sample_id="s-old"):
|
||||
from app.models.models import BizSampleFreight, BizSampleFreightItem
|
||||
|
||||
now = datetime(2026, 10, 21, 9, 0, 0)
|
||||
freight = BizSampleFreight(
|
||||
id="f-yjs",
|
||||
freight_no="YF1",
|
||||
transport_mode="sfkd",
|
||||
freight_amount=None,
|
||||
waybill_no="SF001",
|
||||
settle_status="yjs",
|
||||
tenant_no="tenant-a",
|
||||
create_dept_id="",
|
||||
create_time=now,
|
||||
update_time=now,
|
||||
del_flag=0,
|
||||
)
|
||||
item = BizSampleFreightItem(
|
||||
id="fi-1",
|
||||
freight_id=freight.id,
|
||||
sample_source="cell_storage",
|
||||
sample_id=sample_id,
|
||||
sample_code="C1",
|
||||
protocol_id="p1",
|
||||
tenant_no="tenant-a",
|
||||
create_dept_id="",
|
||||
create_time=now,
|
||||
update_time=now,
|
||||
del_flag=0,
|
||||
)
|
||||
db.add_all([freight, item])
|
||||
db.commit()
|
||||
return freight, item
|
||||
|
||||
|
||||
def test_settled_protocol_save_without_freight_id_keeps_links():
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.crud.sample_freight import apply_freight_on_protocol_save
|
||||
from app.models.models import BizSampleFreight, BizSampleFreightItem
|
||||
|
||||
db = _protocol_freight_db()
|
||||
freight, item = _seed_settled_protocol_freight(db)
|
||||
try:
|
||||
with pytest.raises(ValueError, match="已结算的运费不能调整样本"):
|
||||
apply_freight_on_protocol_save(
|
||||
db,
|
||||
tenant_no="tenant-a",
|
||||
user_id="u1",
|
||||
sample_source="cell_storage",
|
||||
protocol_id="p1",
|
||||
saved_samples=[SimpleNamespace(id="s-new", sample_code="C2")],
|
||||
input_samples=[{}],
|
||||
)
|
||||
db.expire_all()
|
||||
item = db.query(BizSampleFreightItem).filter_by(id=item.id).one()
|
||||
freight = db.query(BizSampleFreight).filter_by(id=freight.id).one()
|
||||
assert item.del_flag == 0
|
||||
assert freight.del_flag == 0
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_settled_protocol_save_relinks_same_count_to_new_sample():
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.crud.sample_freight import apply_freight_on_protocol_save
|
||||
from app.models.models import BizSampleFreight, BizSampleFreightItem
|
||||
|
||||
db = _protocol_freight_db()
|
||||
freight, _item = _seed_settled_protocol_freight(db)
|
||||
try:
|
||||
apply_freight_on_protocol_save(
|
||||
db,
|
||||
tenant_no="tenant-a",
|
||||
user_id="u1",
|
||||
sample_source="cell_storage",
|
||||
protocol_id="p1",
|
||||
saved_samples=[SimpleNamespace(id="s-new", sample_code="C2")],
|
||||
input_samples=[{"freightId": freight.id}],
|
||||
)
|
||||
db.expire_all()
|
||||
freight = db.query(BizSampleFreight).filter_by(id=freight.id).one()
|
||||
assert freight.del_flag == 0
|
||||
assert freight.settle_status == "yjs"
|
||||
live = (
|
||||
db.query(BizSampleFreightItem)
|
||||
.filter_by(freight_id=freight.id, sample_id="s-new", del_flag=0)
|
||||
.one()
|
||||
)
|
||||
assert live.protocol_id == "p1"
|
||||
finally:
|
||||
db.close()
|
||||
Reference in new issue
Block a user