|
@@ -2,6 +2,7 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
|
|
|
+from decimal import Decimal
|
|
|
from typing import List, Optional, Tuple
|
|
from typing import List, Optional, Tuple
|
|
|
|
|
|
|
|
from fastapi import HTTPException
|
|
from fastapi import HTTPException
|
|
@@ -29,6 +30,70 @@ from app.services.market_field_scope import (
|
|
|
from app.services.market_support import validate_attachment_refs
|
|
from app.services.market_support import validate_attachment_refs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+_MONEY_QUANTUM = Decimal('0.01')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _money_text(value: Optional[Decimal]) -> Optional[str]:
|
|
|
|
|
+ if value is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return format(Decimal(str(value)).quantize(_MONEY_QUANTUM), 'f')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _mobile_transfer_to_dict(
|
|
|
|
|
+ db: Session, row: BizPresignTransfer, tenant_no: str
|
|
|
|
|
+) -> dict:
|
|
|
|
|
+ data = presign_crud._transfer_to_dict(db, row, tenant_no)
|
|
|
|
|
+ data['transferAmount'] = _money_text(row.transfer_amount)
|
|
|
|
|
+ return data
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def _mobile_order_to_dict(
|
|
|
|
|
+ db: Session,
|
|
|
|
|
+ row: BizPresignOrder,
|
|
|
|
|
+ tenant_no: str,
|
|
|
|
|
+ *,
|
|
|
|
|
+ with_children: bool,
|
|
|
|
|
+ deposit_amount: Optional[Decimal] = None,
|
|
|
|
|
+ user_name_map: Optional[dict] = None,
|
|
|
|
|
+) -> dict:
|
|
|
|
|
+ deposit = (
|
|
|
|
|
+ deposit_amount
|
|
|
|
|
+ if deposit_amount is not None
|
|
|
|
|
+ else presign_crud.confirmed_deposit_amount(
|
|
|
|
|
+ db, presign_order_id=row.id, tenant_no=tenant_no
|
|
|
|
|
+ )
|
|
|
|
|
+ )
|
|
|
|
|
+ data = presign_crud.order_to_dict(
|
|
|
|
|
+ db,
|
|
|
|
|
+ row,
|
|
|
|
|
+ tenant_no,
|
|
|
|
|
+ with_children=False,
|
|
|
|
|
+ deposit_amount=deposit,
|
|
|
|
|
+ user_name_map=user_name_map,
|
|
|
|
|
+ )
|
|
|
|
|
+ data['contractAmount'] = _money_text(row.contract_amount)
|
|
|
|
|
+ data['confirmedDepositAmount'] = _money_text(deposit)
|
|
|
|
|
+ if with_children:
|
|
|
|
|
+ data['sampleTypeIds'] = presign_crud.list_sample_type_ids(
|
|
|
|
|
+ db, presign_order_id=row.id, tenant_no=tenant_no
|
|
|
|
|
+ )
|
|
|
|
|
+ transfer_rows = (
|
|
|
|
|
+ db.query(BizPresignTransfer)
|
|
|
|
|
+ .filter(
|
|
|
|
|
+ BizPresignTransfer.presign_order_id == row.id,
|
|
|
|
|
+ BizPresignTransfer.tenant_no == tenant_no,
|
|
|
|
|
+ BizPresignTransfer.del_flag == 0,
|
|
|
|
|
+ )
|
|
|
|
|
+ .order_by(BizPresignTransfer.create_time.asc())
|
|
|
|
|
+ .all()
|
|
|
|
|
+ )
|
|
|
|
|
+ data['transfers'] = [
|
|
|
|
|
+ _mobile_transfer_to_dict(db, transfer, tenant_no)
|
|
|
|
|
+ for transfer in transfer_rows
|
|
|
|
|
+ ]
|
|
|
|
|
+ return data
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def _dump_body(body: MarketPresignOrderBody) -> dict:
|
|
def _dump_body(body: MarketPresignOrderBody) -> dict:
|
|
|
return body.model_dump(by_alias=False, exclude_unset=True)
|
|
return body.model_dump(by_alias=False, exclude_unset=True)
|
|
|
|
|
|
|
@@ -236,7 +301,7 @@ def list_presign_orders(
|
|
|
db, person_ids, ctx.tenant_no
|
|
db, person_ids, ctx.tenant_no
|
|
|
)
|
|
)
|
|
|
return [
|
|
return [
|
|
|
- presign_crud.order_to_dict(
|
|
|
|
|
|
|
+ _mobile_order_to_dict(
|
|
|
db,
|
|
db,
|
|
|
row,
|
|
row,
|
|
|
ctx.tenant_no,
|
|
ctx.tenant_no,
|
|
@@ -258,7 +323,7 @@ def get_presign_order(
|
|
|
row = assert_presign_access(
|
|
row = assert_presign_access(
|
|
|
db, order_id, ctx, user_info=user_info
|
|
db, order_id, ctx, user_info=user_info
|
|
|
)
|
|
)
|
|
|
- return presign_crud.order_to_dict(
|
|
|
|
|
|
|
+ return _mobile_order_to_dict(
|
|
|
db, row, ctx.tenant_no, with_children=True
|
|
db, row, ctx.tenant_no, with_children=True
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -347,7 +412,7 @@ def create_presign_order(
|
|
|
except Exception:
|
|
except Exception:
|
|
|
db.rollback()
|
|
db.rollback()
|
|
|
raise
|
|
raise
|
|
|
- return presign_crud.order_to_dict(
|
|
|
|
|
|
|
+ return _mobile_order_to_dict(
|
|
|
db, row, ctx.tenant_no, with_children=True
|
|
db, row, ctx.tenant_no, with_children=True
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -414,7 +479,7 @@ def update_presign_order(
|
|
|
row = assert_presign_access(
|
|
row = assert_presign_access(
|
|
|
db, row.id, ctx, user_info=user_info
|
|
db, row.id, ctx, user_info=user_info
|
|
|
)
|
|
)
|
|
|
- result = presign_crud.order_to_dict(
|
|
|
|
|
|
|
+ result = _mobile_order_to_dict(
|
|
|
db, row, ctx.tenant_no, with_children=True
|
|
db, row, ctx.tenant_no, with_children=True
|
|
|
)
|
|
)
|
|
|
db.commit()
|
|
db.commit()
|
|
@@ -538,7 +603,7 @@ def create_presign_transfer(
|
|
|
create_dept_id=_current_dept_id(user_info),
|
|
create_dept_id=_current_dept_id(user_info),
|
|
|
commit=False,
|
|
commit=False,
|
|
|
)
|
|
)
|
|
|
- result = presign_crud._transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
|
|
|
|
+ result = _mobile_transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return result
|
|
return result
|
|
|
except Exception:
|
|
except Exception:
|
|
@@ -576,7 +641,7 @@ def update_presign_transfer(
|
|
|
fields=fields,
|
|
fields=fields,
|
|
|
commit=False,
|
|
commit=False,
|
|
|
)
|
|
)
|
|
|
- result = presign_crud._transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
|
|
|
|
+ result = _mobile_transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return result
|
|
return result
|
|
|
except Exception:
|
|
except Exception:
|
|
@@ -626,7 +691,7 @@ def submit_presign_transfer(
|
|
|
user_id=ctx.user_id,
|
|
user_id=ctx.user_id,
|
|
|
commit=False,
|
|
commit=False,
|
|
|
)
|
|
)
|
|
|
- result = presign_crud._transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
|
|
|
|
+ result = _mobile_transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return result
|
|
return result
|
|
|
except Exception:
|
|
except Exception:
|
|
@@ -649,7 +714,7 @@ def withdraw_presign_transfer(
|
|
|
user_id=ctx.user_id,
|
|
user_id=ctx.user_id,
|
|
|
commit=False,
|
|
commit=False,
|
|
|
)
|
|
)
|
|
|
- result = presign_crud._transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
|
|
|
|
+ result = _mobile_transfer_to_dict(db, row, ctx.tenant_no)
|
|
|
db.commit()
|
|
db.commit()
|
|
|
return result
|
|
return result
|
|
|
except Exception:
|
|
except Exception:
|