feat(pl): 展示各装送段用证配置与独立占用明细并保留历史计量口径。
This commit is contained in:
1 parent
706260ff7a
commit
b764eb02a7
10 files changed
+497
-40
No files matched your search
@@ -156,34 +156,55 @@ def save_configuration(db, user, plan_id, config):
|
||||
def get_plan_quota(db, user, plan_id):
|
||||
with db.no_autoflush:
|
||||
plan, products, rows, stops = source_context(db, user, plan_id)
|
||||
from app.services.pl_quota_contract_service import _contract
|
||||
contract_numbers = {}
|
||||
from app.services.pl_quota_contract_service import _contract, get_contract_bindings
|
||||
contract_numbers, contract_bindings = {}, {}
|
||||
for cid in {r.contract_id for values in rows.values() for r in values.values() if r.contract_id}:
|
||||
try:
|
||||
contract_numbers[cid] = _contract(db, user, cid).contract_no
|
||||
bindings = get_contract_bindings(db, user, cid)
|
||||
contract_bindings[cid] = []
|
||||
for binding in bindings:
|
||||
if binding['linkStatus'] != 'active':
|
||||
continue
|
||||
cert = _get_row(db, user, binding['certType'], binding['certId'])
|
||||
contract_bindings[cid].append({
|
||||
'certId': cert.id, 'certType': binding['certType'],
|
||||
'certNo': cert.cert_no, 'quantityUnit': cert.quantity_unit,
|
||||
'productIds': [p['contractProductId'] for p in binding['products']
|
||||
if p['scopeStatus'] == 'active']})
|
||||
except HTTPException as exc:
|
||||
if exc.status_code not in (403, 404):
|
||||
raise
|
||||
contract_numbers[cid] = None
|
||||
options = []
|
||||
contract_bindings.pop(cid, None)
|
||||
options, stop_products = [], []
|
||||
for side, values in rows.items():
|
||||
for row in values.values():
|
||||
if products[row.plan_product_id].is_toxic == 1:
|
||||
stop = stops[side][getattr(row, 'load_id' if side == 'load' else 'delivery_id')]
|
||||
options.append({'sourceStopId': stop.id, 'stopId': stop.id,
|
||||
'stopOrder': getattr(stop, 'seq', None) or stop.order_num or 1,
|
||||
'productId': row.product_id, 'productNo': row.product_no,
|
||||
'sourceStopType': side, 'sourceStopProductId': row.id,
|
||||
'planProductId': row.plan_product_id, 'productName': row.product_name,
|
||||
'model': row.model, 'quantity': row.plan_qty, 'unit': row.unit,
|
||||
'contractId': row.contract_id, 'contractNo': contract_numbers.get(row.contract_id),
|
||||
'contractProductId': row.contract_product_id,
|
||||
'partyName': stop.customer_name})
|
||||
product = products[row.plan_product_id]
|
||||
stop = stops[side][getattr(row, 'load_id' if side == 'load' else 'delivery_id')]
|
||||
item = {'sourceStopId': stop.id, 'stopId': stop.id,
|
||||
'stopOrder': getattr(stop, 'seq', None) or stop.order_num or 1,
|
||||
'productId': row.product_id, 'productNo': row.product_no,
|
||||
'sourceStopType': side, 'sourceStopProductId': row.id,
|
||||
'planProductId': row.plan_product_id, 'productName': row.product_name,
|
||||
'model': row.model, 'quantity': row.plan_qty, 'unit': row.unit,
|
||||
'contractId': row.contract_id, 'contractNo': contract_numbers.get(row.contract_id),
|
||||
'contractProductId': row.contract_product_id,
|
||||
'partyName': stop.customer_name}
|
||||
stop_products.append({**item, 'isToxic': product.is_toxic == 1,
|
||||
'isExplosive': product.is_explosive == 1,
|
||||
'bindingsReadable': row.contract_id in contract_bindings,
|
||||
'certificates': [{k: v for k, v in cert.items() if k != 'productIds'}
|
||||
for cert in contract_bindings.get(row.contract_id, [])
|
||||
if row.contract_product_id in cert['productIds']]})
|
||||
if product.is_toxic == 1:
|
||||
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()
|
||||
version = resolve_measurement_version(db, user, plan)
|
||||
result = {'planId': plan.id, 'planNo': plan.plan_no, 'licensePlate': plan.license_plate,
|
||||
'measurementVersion': version,
|
||||
'configuration': {**(plan.cert_configuration or {}), 'measurementVersion': version}, 'sourceOptions': options,
|
||||
'stopProducts': stop_products,
|
||||
'canSaveConfiguration': plan.transport_status != 'arranged' and plan.archive_status != 'archived',
|
||||
'usages': []}
|
||||
for usage in usages:
|
||||
|
||||
Reference in new issue
Block a user