提交
This commit is contained in:
1 parent
299609706c
commit
e46c0480d4
87 files changed
+11975
-15543
No files matched your search
@@ -11,9 +11,8 @@ from sqlalchemy.orm import Session
|
||||
from app.core.database import get_db
|
||||
from app.core.db_auth import DbUserContext, get_db_current_user, get_db_current_user_optional
|
||||
from app.core.tenant_context import get_tenant_no
|
||||
from app.core.utils import generate_uuid
|
||||
from app.services.db.inventory_id import next_inbound_outbound_id
|
||||
from app.models.db_models import DbInboundOutbound, DbPurchasePlan, DbVehicle, DbWeighingSlip
|
||||
from app.models.db_models import DbInboundOutbound, DbPurchasePlan, DbWeighingSlip
|
||||
from app.schemas.db.inventory import (
|
||||
CreateLinkForPlanPayload,
|
||||
InboundOutboundCreate,
|
||||
@@ -114,40 +113,6 @@ def _get_inventory(db: Session, tenant_no: str, inventory_id: str) -> DbInboundO
|
||||
return row
|
||||
|
||||
|
||||
def _ensure_vehicle_exists(
|
||||
db: Session,
|
||||
tenant_no: str,
|
||||
vehicle_no: str,
|
||||
*,
|
||||
create_by: Optional[str] = None,
|
||||
create_dept_id: Optional[str] = None,
|
||||
) -> None:
|
||||
if not (vehicle_no and vehicle_no.strip()):
|
||||
return
|
||||
normalized = vehicle_no.strip().lower()
|
||||
exists = (
|
||||
db.query(DbVehicle)
|
||||
.filter(
|
||||
DbVehicle.tenant_no == tenant_no,
|
||||
DbVehicle.del_flag == 0,
|
||||
func.lower(DbVehicle.vehicle_no) == normalized,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if exists:
|
||||
return
|
||||
db.add(
|
||||
DbVehicle(
|
||||
id=generate_uuid(),
|
||||
tenant_no=tenant_no,
|
||||
vehicle_no=vehicle_no.strip(),
|
||||
remark=None,
|
||||
create_by=create_by,
|
||||
create_dept_id=create_dept_id or "",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def _apply_inventory_product_update(
|
||||
db: Session, tenant_no: str, row: DbInboundOutbound, payload_dict: dict
|
||||
) -> None:
|
||||
@@ -423,10 +388,6 @@ def update_inventory(
|
||||
row = _get_inventory_by_id(db, id)
|
||||
payload_dict = payload.model_dump(exclude_unset=True)
|
||||
|
||||
vehicle_no_updated = payload_dict.get("vehicle_no")
|
||||
if vehicle_no_updated is not None and str(vehicle_no_updated).strip():
|
||||
_ensure_vehicle_exists(db, row.tenant_no, str(vehicle_no_updated).strip())
|
||||
|
||||
_apply_inventory_product_update(db, row.tenant_no, row, payload_dict)
|
||||
_apply_inventory_update(row, payload_dict)
|
||||
_maybe_promote_third_party_status(row)
|
||||
|
||||
Reference in new issue
Block a user