Prepare Specs UI for Windows review

This commit is contained in:
Alex
2026-10-10 11:30:27 +00:00
parent 6e6035c789
commit 25511870ff
68 changed files with 1931 additions and 1070 deletions
+2
View File
@@ -101,6 +101,7 @@ class SystemModule(Base, TimestampMixin):
guardian_id = Column(Integer, ForeignKey('guardians.id', ondelete='CASCADE'), nullable=True)
module_id = Column(Integer, ForeignKey('modules.id', ondelete='CASCADE'), nullable=False)
quantity = Column(Integer, nullable=False)
module = relationship("Module")
__table_args__ = (
UniqueConstraint('system_id', 'guardian_id', 'module_id', name='uq_system_module_guardian'),
CheckConstraint('quantity > 0', name='check_module_quantity_positive'),
@@ -196,6 +197,7 @@ class SpecificationItem(Base, TimestampMixin):
module_id = Column(Integer, ForeignKey('modules.id', ondelete='RESTRICT'), nullable=False)
quantity = Column(Integer, nullable=False)
description = Column(Text)
module = relationship("Module")
class Vendor(Base, TimestampMixin):
Binary file not shown.
Binary file not shown.
+34 -34
View File
@@ -1,35 +1,35 @@
"""
Repository for PoolResource operations
"""
from sqlalchemy.orm import Session
from app.models import PoolResource, PoolReceipt, PoolAllocation
class PoolResourceRepository:
def __init__(self, db: Session):
self.db = db
def get_current_balance(self, pool_resource_id: int) -> int:
"""Calculate current balance from receipts and allocations"""
# Get all receipts for this resource
receipts = self.db.query(PoolReceipt).filter(
PoolReceipt.pool_resource_id == pool_resource_id
).all()
# Get all allocations for this resource
allocations = self.db.query(PoolAllocation).filter(
PoolAllocation.pool_resource_id == pool_resource_id
).all()
# Calculate total receipt quantity
total_receipts = sum(r.quantity for r in receipts)
# Calculate total allocation quantity
total_allocations = sum(a.quantity for a in allocations)
# Return balance
return total_receipts - total_allocations
def can_allocate(self, pool_resource_id: int, quantity: int) -> bool:
"""Check if allocation of specified quantity is possible"""
current_balance = self.get_current_balance(pool_resource_id)
"""
Repository for PoolResource operations
"""
from sqlalchemy.orm import Session
from app.models import PoolResource, PoolReceipt, PoolAllocation
class PoolResourceRepository:
def __init__(self, db: Session):
self.db = db
def get_current_balance(self, pool_resource_id: int) -> int:
"""Calculate current balance from receipts and allocations"""
# Get all receipts for this resource
receipts = self.db.query(PoolReceipt).filter(
PoolReceipt.pool_resource_id == pool_resource_id
).all()
# Get all allocations for this resource
allocations = self.db.query(PoolAllocation).filter(
PoolAllocation.pool_resource_id == pool_resource_id
).all()
# Calculate total receipt quantity
total_receipts = sum(r.quantity for r in receipts)
# Calculate total allocation quantity
total_allocations = sum(a.quantity for a in allocations)
# Return balance
return total_receipts - total_allocations
def can_allocate(self, pool_resource_id: int, quantity: int) -> bool:
"""Check if allocation of specified quantity is possible"""
current_balance = self.get_current_balance(pool_resource_id)
return quantity <= current_balance
Executable → Regular
+17
View File
@@ -0,0 +1,17 @@
from app.routers.projects import router as projects
from app.routers.customers import router as customers
from app.routers.systems import router as systems
from app.routers.contracts import router as contracts
from app.routers.purchases import router as purchases
from app.routers.documents import router as documents
from app.routers.ui import router as ui
__all__ = [
"projects",
"customers",
"systems",
"contracts",
"purchases",
"documents",
"ui",
]
Binary file not shown.
Regular → Executable
+138 -138
View File
@@ -1,139 +1,139 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import License, LicenseType, Product
from app.schemas import LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate
router = APIRouter()
# License routes
@router.get("/licenses")
async def get_licenses(db: Session = Depends(get_db)):
licenses = db.query(License).all()
return licenses
@router.get("/licenses/{license_id}")
async def get_license(license_id: int, db: Session = Depends(get_db)):
license = db.query(License).filter(License.id == license_id).first()
if not license:
raise HTTPException(status_code=404, detail="License not found")
return license
@router.post("/licenses")
async def create_license(license: LicenseCreate, db: Session = Depends(get_db)):
db_license = License(**license.dict())
db.add(db_license)
db.commit()
db.refresh(db_license)
return db_license
@router.put("/licenses/{license_id}")
async def update_license(license_id: int, license: LicenseUpdate, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
for key, value in license.dict(exclude_unset=True).items():
setattr(db_license, key, value)
db.commit()
db.refresh(db_license)
return db_license
@router.delete("/licenses/{license_id}")
async def delete_license(license_id: int, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
db.delete(db_license)
db.commit()
return {"message": "License deleted successfully"}
# LicenseType routes
@router.get("/license_types")
async def get_license_types(db: Session = Depends(get_db)):
license_types = db.query(LicenseType).all()
return license_types
@router.get("/license_types/{license_type_id}")
async def get_license_type(license_type_id: int, db: Session = Depends(get_db)):
license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not license_type:
raise HTTPException(status_code=404, detail="License type not found")
return license_type
@router.post("/license_types")
async def create_license_type(license_type: LicenseTypeCreate, db: Session = Depends(get_db)):
db_license_type = LicenseType(**license_type.dict())
db.add(db_license_type)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.put("/license_types/{license_type_id}")
async def update_license_type(license_type_id: int, license_type: LicenseTypeUpdate, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
for key, value in license_type.dict(exclude_unset=True).items():
setattr(db_license_type, key, value)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.delete("/license_types/{license_type_id}")
async def delete_license_type(license_type_id: int, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
db.delete(db_license_type)
db.commit()
return {"message": "License type deleted successfully"}
# Product routes
@router.get("/products")
async def get_products(db: Session = Depends(get_db)):
products = db.query(Product).all()
return products
@router.get("/products/{product_id}")
async def get_product(product_id: int, db: Session = Depends(get_db)):
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
return product
@router.post("/products")
async def create_product(product: ProductCreate, db: Session = Depends(get_db)):
db_product = Product(**product.dict())
db.add(db_product)
db.commit()
db.refresh(db_product)
return db_product
@router.put("/products/{product_id}")
async def update_product(product_id: int, product: ProductUpdate, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
for key, value in product.dict(exclude_unset=True).items():
setattr(db_product, key, value)
db.commit()
db.refresh(db_product)
return db_product
@router.delete("/products/{product_id}")
async def delete_product(product_id: int, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
db.delete(db_product)
db.commit()
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import License, LicenseType, Product
from app.schemas import LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate
router = APIRouter()
# License routes
@router.get("/licenses")
async def get_licenses(db: Session = Depends(get_db)):
licenses = db.query(License).all()
return licenses
@router.get("/licenses/{license_id}")
async def get_license(license_id: int, db: Session = Depends(get_db)):
license = db.query(License).filter(License.id == license_id).first()
if not license:
raise HTTPException(status_code=404, detail="License not found")
return license
@router.post("/licenses")
async def create_license(license: LicenseCreate, db: Session = Depends(get_db)):
db_license = License(**license.dict())
db.add(db_license)
db.commit()
db.refresh(db_license)
return db_license
@router.put("/licenses/{license_id}")
async def update_license(license_id: int, license: LicenseUpdate, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
for key, value in license.dict(exclude_unset=True).items():
setattr(db_license, key, value)
db.commit()
db.refresh(db_license)
return db_license
@router.delete("/licenses/{license_id}")
async def delete_license(license_id: int, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
db.delete(db_license)
db.commit()
return {"message": "License deleted successfully"}
# LicenseType routes
@router.get("/license_types")
async def get_license_types(db: Session = Depends(get_db)):
license_types = db.query(LicenseType).all()
return license_types
@router.get("/license_types/{license_type_id}")
async def get_license_type(license_type_id: int, db: Session = Depends(get_db)):
license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not license_type:
raise HTTPException(status_code=404, detail="License type not found")
return license_type
@router.post("/license_types")
async def create_license_type(license_type: LicenseTypeCreate, db: Session = Depends(get_db)):
db_license_type = LicenseType(**license_type.dict())
db.add(db_license_type)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.put("/license_types/{license_type_id}")
async def update_license_type(license_type_id: int, license_type: LicenseTypeUpdate, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
for key, value in license_type.dict(exclude_unset=True).items():
setattr(db_license_type, key, value)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.delete("/license_types/{license_type_id}")
async def delete_license_type(license_type_id: int, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
db.delete(db_license_type)
db.commit()
return {"message": "License type deleted successfully"}
# Product routes
@router.get("/products")
async def get_products(db: Session = Depends(get_db)):
products = db.query(Product).all()
return products
@router.get("/products/{product_id}")
async def get_product(product_id: int, db: Session = Depends(get_db)):
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
return product
@router.post("/products")
async def create_product(product: ProductCreate, db: Session = Depends(get_db)):
db_product = Product(**product.dict())
db.add(db_product)
db.commit()
db.refresh(db_product)
return db_product
@router.put("/products/{product_id}")
async def update_product(product_id: int, product: ProductUpdate, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
for key, value in product.dict(exclude_unset=True).items():
setattr(db_product, key, value)
db.commit()
db.refresh(db_product)
return db_product
@router.delete("/products/{product_id}")
async def delete_product(product_id: int, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
db.delete(db_product)
db.commit()
return {"message": "Product deleted successfully"}
Regular → Executable
+182 -182
View File
@@ -1,183 +1,183 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
router = APIRouter()
# ResourcePool routes
@router.get("/resource_pools")
async def get_resource_pools(db: Session = Depends(get_db)):
pools = db.query(ResourcePool).all()
return pools
@router.get("/resource_pools/{pool_id}")
async def get_resource_pool(pool_id: int, db: Session = Depends(get_db)):
pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
return pool
@router.post("/resource_pools")
async def create_resource_pool(pool: ResourcePoolCreate, db: Session = Depends(get_db)):
db_pool = ResourcePool(**pool.dict())
db.add(db_pool)
db.commit()
db.refresh(db_pool)
return db_pool
@router.put("/resource_pools/{pool_id}")
async def update_resource_pool(pool_id: int, pool: ResourcePoolUpdate, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
for key, value in pool.dict(exclude_unset=True).items():
setattr(db_pool, key, value)
db.commit()
db.refresh(db_pool)
return db_pool
@router.delete("/resource_pools/{pool_id}")
async def delete_resource_pool(pool_id: int, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
db.delete(db_pool)
db.commit()
return {"message": "Resource pool deleted successfully"}
# PoolResource routes
@router.get("/pool_resources")
async def get_pool_resources(db: Session = Depends(get_db)):
resources = db.query(PoolResource).all()
return resources
@router.get("/pool_resources/{resource_id}")
async def get_pool_resource(resource_id: int, db: Session = Depends(get_db)):
resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
return resource
@router.post("/pool_resources")
async def create_pool_resource(resource: PoolResourceCreate, db: Session = Depends(get_db)):
db_resource = PoolResource(**resource.dict())
db.add(db_resource)
db.commit()
db.refresh(db_resource)
return db_resource
@router.put("/pool_resources/{resource_id}")
async def update_pool_resource(resource_id: int, resource: PoolResourceUpdate, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
for key, value in resource.dict(exclude_unset=True).items():
setattr(db_resource, key, value)
db.commit()
db.refresh(db_resource)
return db_resource
@router.delete("/pool_resources/{resource_id}")
async def delete_pool_resource(resource_id: int, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
db.delete(db_resource)
db.commit()
return {"message": "Pool resource deleted successfully"}
# PoolReceipt routes
@router.get("/pool_receipts")
async def get_pool_receipts(db: Session = Depends(get_db)):
receipts = db.query(PoolReceipt).all()
return receipts
@router.get("/pool_receipts/{receipt_id}")
async def get_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
return receipt
@router.post("/pool_receipts")
async def create_pool_receipt(receipt: PoolReceiptCreate, db: Session = Depends(get_db)):
db_receipt = PoolReceipt(**receipt.dict())
db.add(db_receipt)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.put("/pool_receipts/{receipt_id}")
async def update_pool_receipt(receipt_id: int, receipt: PoolReceiptUpdate, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
for key, value in receipt.dict(exclude_unset=True).items():
setattr(db_receipt, key, value)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.delete("/pool_receipts/{receipt_id}")
async def delete_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
db.delete(db_receipt)
db.commit()
return {"message": "Pool receipt deleted successfully"}
# PoolAllocation routes
@router.get("/pool_allocations")
async def get_pool_allocations(db: Session = Depends(get_db)):
allocations = db.query(PoolAllocation).all()
return allocations
@router.get("/pool_allocations/{allocation_id}")
async def get_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
return allocation
@router.post("/pool_allocations")
async def create_pool_allocation(allocation: PoolAllocationCreate, db: Session = Depends(get_db)):
db_allocation = PoolAllocation(**allocation.dict())
db.add(db_allocation)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.put("/pool_allocations/{allocation_id}")
async def update_pool_allocation(allocation_id: int, allocation: PoolAllocationUpdate, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
for key, value in allocation.dict(exclude_unset=True).items():
setattr(db_allocation, key, value)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.delete("/pool_allocations/{allocation_id}")
async def delete_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
db.delete(db_allocation)
db.commit()
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
router = APIRouter()
# ResourcePool routes
@router.get("/resource_pools")
async def get_resource_pools(db: Session = Depends(get_db)):
pools = db.query(ResourcePool).all()
return pools
@router.get("/resource_pools/{pool_id}")
async def get_resource_pool(pool_id: int, db: Session = Depends(get_db)):
pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
return pool
@router.post("/resource_pools")
async def create_resource_pool(pool: ResourcePoolCreate, db: Session = Depends(get_db)):
db_pool = ResourcePool(**pool.dict())
db.add(db_pool)
db.commit()
db.refresh(db_pool)
return db_pool
@router.put("/resource_pools/{pool_id}")
async def update_resource_pool(pool_id: int, pool: ResourcePoolUpdate, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
for key, value in pool.dict(exclude_unset=True).items():
setattr(db_pool, key, value)
db.commit()
db.refresh(db_pool)
return db_pool
@router.delete("/resource_pools/{pool_id}")
async def delete_resource_pool(pool_id: int, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
db.delete(db_pool)
db.commit()
return {"message": "Resource pool deleted successfully"}
# PoolResource routes
@router.get("/pool_resources")
async def get_pool_resources(db: Session = Depends(get_db)):
resources = db.query(PoolResource).all()
return resources
@router.get("/pool_resources/{resource_id}")
async def get_pool_resource(resource_id: int, db: Session = Depends(get_db)):
resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
return resource
@router.post("/pool_resources")
async def create_pool_resource(resource: PoolResourceCreate, db: Session = Depends(get_db)):
db_resource = PoolResource(**resource.dict())
db.add(db_resource)
db.commit()
db.refresh(db_resource)
return db_resource
@router.put("/pool_resources/{resource_id}")
async def update_pool_resource(resource_id: int, resource: PoolResourceUpdate, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
for key, value in resource.dict(exclude_unset=True).items():
setattr(db_resource, key, value)
db.commit()
db.refresh(db_resource)
return db_resource
@router.delete("/pool_resources/{resource_id}")
async def delete_pool_resource(resource_id: int, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
db.delete(db_resource)
db.commit()
return {"message": "Pool resource deleted successfully"}
# PoolReceipt routes
@router.get("/pool_receipts")
async def get_pool_receipts(db: Session = Depends(get_db)):
receipts = db.query(PoolReceipt).all()
return receipts
@router.get("/pool_receipts/{receipt_id}")
async def get_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
return receipt
@router.post("/pool_receipts")
async def create_pool_receipt(receipt: PoolReceiptCreate, db: Session = Depends(get_db)):
db_receipt = PoolReceipt(**receipt.dict())
db.add(db_receipt)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.put("/pool_receipts/{receipt_id}")
async def update_pool_receipt(receipt_id: int, receipt: PoolReceiptUpdate, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
for key, value in receipt.dict(exclude_unset=True).items():
setattr(db_receipt, key, value)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.delete("/pool_receipts/{receipt_id}")
async def delete_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
db.delete(db_receipt)
db.commit()
return {"message": "Pool receipt deleted successfully"}
# PoolAllocation routes
@router.get("/pool_allocations")
async def get_pool_allocations(db: Session = Depends(get_db)):
allocations = db.query(PoolAllocation).all()
return allocations
@router.get("/pool_allocations/{allocation_id}")
async def get_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
return allocation
@router.post("/pool_allocations")
async def create_pool_allocation(allocation: PoolAllocationCreate, db: Session = Depends(get_db)):
db_allocation = PoolAllocation(**allocation.dict())
db.add(db_allocation)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.put("/pool_allocations/{allocation_id}")
async def update_pool_allocation(allocation_id: int, allocation: PoolAllocationUpdate, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
for key, value in allocation.dict(exclude_unset=True).items():
setattr(db_allocation, key, value)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.delete("/pool_allocations/{allocation_id}")
async def delete_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
db.delete(db_allocation)
db.commit()
return {"message": "Pool allocation deleted successfully"}
+51
View File
@@ -0,0 +1,51 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import Project, System, Guardian, Module, SystemModule
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, GuardianCreate, GuardianUpdate
router = APIRouter()
# Project routes
@router.get("/projects")
async def get_projects(db: Session = Depends(get_db)):
projects = db.query(Project).all()
return projects
@router.get("/projects/{project_id}")
async def get_project(project_id: int, db: Session = Depends(get_db)):
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
return project
@router.post("/projects")
async def create_project(project: ProjectCreate, db: Session = Depends(get_db)):
db_project = Project(**project.dict())
db.add(db_project)
db.commit()
db.refresh(db_project)
return db_project
@router.put("/projects/{project_id}")
async def update_project(project_id: int, project: ProjectUpdate, db: Session = Depends(get_db)):
db_project = db.query(Project).filter(Project.id == project_id).first()
if not db_project:
raise HTTPException(status_code=404, detail="Project not found")
for key, value in project.dict(exclude_unset=True).items():
setattr(db_project, key, value)
db.commit()
db.refresh(db_project)
return db_project
@router.delete("/projects/{project_id}")
async def delete_project(project_id: int, db: Session = Depends(get_db)):
db_project = db.query(Project).filter(Project.id == project_id).first()
if not db_project:
raise HTTPException(status_code=404, detail="Project not found")
db.delete(db_project)
db.commit()
return {"message": "Project deleted successfully"}
+2 -354
View File
@@ -1,8 +1,8 @@
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from app.database import get_db
from app.models import Project, System, Key, Guardian, License, LicenseType, Product, ResourcePool, PoolResource, PoolReceipt, PoolAllocation
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, KeyCreate, KeyUpdate, GuardianCreate, GuardianUpdate, LicenseCreate, LicenseUpdate, LicenseTypeCreate, LicenseTypeUpdate, ProductCreate, ProductUpdate, ResourcePoolCreate, ResourcePoolUpdate, PoolResourceCreate, PoolResourceUpdate, PoolReceiptCreate, PoolReceiptUpdate, PoolAllocationCreate, PoolAllocationUpdate
from app.models import Project, System, Guardian, Module, SystemModule
from app.schemas import ProjectCreate, ProjectUpdate, SystemCreate, SystemUpdate, GuardianCreate, GuardianUpdate
router = APIRouter()
@@ -94,50 +94,6 @@ async def delete_system(system_id: int, db: Session = Depends(get_db)):
db.commit()
return {"message": "System deleted successfully"}
# Key routes
@router.get("/keys")
async def get_keys(db: Session = Depends(get_db)):
keys = db.query(Key).all()
return keys
@router.get("/keys/{key_id}")
async def get_key(key_id: int, db: Session = Depends(get_db)):
key = db.query(Key).filter(Key.id == key_id).first()
if not key:
raise HTTPException(status_code=404, detail="Key not found")
return key
@router.post("/keys")
async def create_key(key: KeyCreate, db: Session = Depends(get_db)):
db_key = Key(**key.dict())
db.add(db_key)
db.commit()
db.refresh(db_key)
return db_key
@router.put("/keys/{key_id}")
async def update_key(key_id: int, key: KeyUpdate, db: Session = Depends(get_db)):
db_key = db.query(Key).filter(Key.id == key_id).first()
if not db_key:
raise HTTPException(status_code=404, detail="Key not found")
for key, value in key.dict(exclude_unset=True).items():
setattr(db_key, key, value)
db.commit()
db.refresh(db_key)
return db_key
@router.delete("/keys/{key_id}")
async def delete_key(key_id: int, db: Session = Depends(get_db)):
db_key = db.query(Key).filter(Key.id == key_id).first()
if not db_key:
raise HTTPException(status_code=404, detail="Key not found")
db.delete(db_key)
db.commit()
return {"message": "Key deleted successfully"}
# Guardian routes
@router.get("/guardians")
async def get_guardians(db: Session = Depends(get_db)):
@@ -181,311 +137,3 @@ async def delete_guardian(guardian_id: int, db: Session = Depends(get_db)):
db.delete(db_guardian)
db.commit()
return {"message": "Guardian deleted successfully"}
# License routes
@router.get("/licenses")
async def get_licenses(db: Session = Depends(get_db)):
licenses = db.query(License).all()
return licenses
@router.get("/licenses/{license_id}")
async def get_license(license_id: int, db: Session = Depends(get_db)):
license = db.query(License).filter(License.id == license_id).first()
if not license:
raise HTTPException(status_code=404, detail="License not found")
return license
@router.post("/licenses")
async def create_license(license: LicenseCreate, db: Session = Depends(get_db)):
db_license = License(**license.dict())
db.add(db_license)
db.commit()
db.refresh(db_license)
return db_license
@router.put("/licenses/{license_id}")
async def update_license(license_id: int, license: LicenseUpdate, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
for key, value in license.dict(exclude_unset=True).items():
setattr(db_license, key, value)
db.commit()
db.refresh(db_license)
return db_license
@router.delete("/licenses/{license_id}")
async def delete_license(license_id: int, db: Session = Depends(get_db)):
db_license = db.query(License).filter(License.id == license_id).first()
if not db_license:
raise HTTPException(status_code=404, detail="License not found")
db.delete(db_license)
db.commit()
return {"message": "License deleted successfully"}
# LicenseType routes
@router.get("/license_types")
async def get_license_types(db: Session = Depends(get_db)):
license_types = db.query(LicenseType).all()
return license_types
@router.get("/license_types/{license_type_id}")
async def get_license_type(license_type_id: int, db: Session = Depends(get_db)):
license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not license_type:
raise HTTPException(status_code=404, detail="License type not found")
return license_type
@router.post("/license_types")
async def create_license_type(license_type: LicenseTypeCreate, db: Session = Depends(get_db)):
db_license_type = LicenseType(**license_type.dict())
db.add(db_license_type)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.put("/license_types/{license_type_id}")
async def update_license_type(license_type_id: int, license_type: LicenseTypeUpdate, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
for key, value in license_type.dict(exclude_unset=True).items():
setattr(db_license_type, key, value)
db.commit()
db.refresh(db_license_type)
return db_license_type
@router.delete("/license_types/{license_type_id}")
async def delete_license_type(license_type_id: int, db: Session = Depends(get_db)):
db_license_type = db.query(LicenseType).filter(LicenseType.id == license_type_id).first()
if not db_license_type:
raise HTTPException(status_code=404, detail="License type not found")
db.delete(db_license_type)
db.commit()
return {"message": "License type deleted successfully"}
# Product routes
@router.get("/products")
async def get_products(db: Session = Depends(get_db)):
products = db.query(Product).all()
return products
@router.get("/products/{product_id}")
async def get_product(product_id: int, db: Session = Depends(get_db)):
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
raise HTTPException(status_code=404, detail="Product not found")
return product
@router.post("/products")
async def create_product(product: ProductCreate, db: Session = Depends(get_db)):
db_product = Product(**product.dict())
db.add(db_product)
db.commit()
db.refresh(db_product)
return db_product
@router.put("/products/{product_id}")
async def update_product(product_id: int, product: ProductUpdate, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
for key, value in product.dict(exclude_unset=True).items():
setattr(db_product, key, value)
db.commit()
db.refresh(db_product)
return db_product
@router.delete("/products/{product_id}")
async def delete_product(product_id: int, db: Session = Depends(get_db)):
db_product = db.query(Product).filter(Product.id == product_id).first()
if not db_product:
raise HTTPException(status_code=404, detail="Product not found")
db.delete(db_product)
db.commit()
return {"message": "Product deleted successfully"}
# ResourcePool routes
@router.get("/resource_pools")
async def get_resource_pools(db: Session = Depends(get_db)):
pools = db.query(ResourcePool).all()
return pools
@router.get("/resource_pools/{pool_id}")
async def get_resource_pool(pool_id: int, db: Session = Depends(get_db)):
pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
return pool
@router.post("/resource_pools")
async def create_resource_pool(pool: ResourcePoolCreate, db: Session = Depends(get_db)):
db_pool = ResourcePool(**pool.dict())
db.add(db_pool)
db.commit()
db.refresh(db_pool)
return db_pool
@router.put("/resource_pools/{pool_id}")
async def update_resource_pool(pool_id: int, pool: ResourcePoolUpdate, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
for key, value in pool.dict(exclude_unset=True).items():
setattr(db_pool, key, value)
db.commit()
db.refresh(db_pool)
return db_pool
@router.delete("/resource_pools/{pool_id}")
async def delete_resource_pool(pool_id: int, db: Session = Depends(get_db)):
db_pool = db.query(ResourcePool).filter(ResourcePool.id == pool_id).first()
if not db_pool:
raise HTTPException(status_code=404, detail="Resource pool not found")
db.delete(db_pool)
db.commit()
return {"message": "Resource pool deleted successfully"}
# PoolResource routes
@router.get("/pool_resources")
async def get_pool_resources(db: Session = Depends(get_db)):
resources = db.query(PoolResource).all()
return resources
@router.get("/pool_resources/{resource_id}")
async def get_pool_resource(resource_id: int, db: Session = Depends(get_db)):
resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
return resource
@router.post("/pool_resources")
async def create_pool_resource(resource: PoolResourceCreate, db: Session = Depends(get_db)):
db_resource = PoolResource(**resource.dict())
db.add(db_resource)
db.commit()
db.refresh(db_resource)
return db_resource
@router.put("/pool_resources/{resource_id}")
async def update_pool_resource(resource_id: int, resource: PoolResourceUpdate, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
for key, value in resource.dict(exclude_unset=True).items():
setattr(db_resource, key, value)
db.commit()
db.refresh(db_resource)
return db_resource
@router.delete("/pool_resources/{resource_id}")
async def delete_pool_resource(resource_id: int, db: Session = Depends(get_db)):
db_resource = db.query(PoolResource).filter(PoolResource.id == resource_id).first()
if not db_resource:
raise HTTPException(status_code=404, detail="Pool resource not found")
db.delete(db_resource)
db.commit()
return {"message": "Pool resource deleted successfully"}
# PoolReceipt routes
@router.get("/pool_receipts")
async def get_pool_receipts(db: Session = Depends(get_db)):
receipts = db.query(PoolReceipt).all()
return receipts
@router.get("/pool_receipts/{receipt_id}")
async def get_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
return receipt
@router.post("/pool_receipts")
async def create_pool_receipt(receipt: PoolReceiptCreate, db: Session = Depends(get_db)):
db_receipt = PoolReceipt(**receipt.dict())
db.add(db_receipt)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.put("/pool_receipts/{receipt_id}")
async def update_pool_receipt(receipt_id: int, receipt: PoolReceiptUpdate, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
for key, value in receipt.dict(exclude_unset=True).items():
setattr(db_receipt, key, value)
db.commit()
db.refresh(db_receipt)
return db_receipt
@router.delete("/pool_receipts/{receipt_id}")
async def delete_pool_receipt(receipt_id: int, db: Session = Depends(get_db)):
db_receipt = db.query(PoolReceipt).filter(PoolReceipt.id == receipt_id).first()
if not db_receipt:
raise HTTPException(status_code=404, detail="Pool receipt not found")
db.delete(db_receipt)
db.commit()
return {"message": "Pool receipt deleted successfully"}
# PoolAllocation routes
@router.get("/pool_allocations")
async def get_pool_allocations(db: Session = Depends(get_db)):
allocations = db.query(PoolAllocation).all()
return allocations
@router.get("/pool_allocations/{allocation_id}")
async def get_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
return allocation
@router.post("/pool_allocations")
async def create_pool_allocation(allocation: PoolAllocationCreate, db: Session = Depends(get_db)):
db_allocation = PoolAllocation(**allocation.dict())
db.add(db_allocation)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.put("/pool_allocations/{allocation_id}")
async def update_pool_allocation(allocation_id: int, allocation: PoolAllocationUpdate, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
for key, value in allocation.dict(exclude_unset=True).items():
setattr(db_allocation, key, value)
db.commit()
db.refresh(db_allocation)
return db_allocation
@router.delete("/pool_allocations/{allocation_id}")
async def delete_pool_allocation(allocation_id: int, db: Session = Depends(get_db)):
db_allocation = db.query(PoolAllocation).filter(PoolAllocation.id == allocation_id).first()
if not db_allocation:
raise HTTPException(status_code=404, detail="Pool allocation not found")
db.delete(db_allocation)
db.commit()
return {"message": "Pool allocation deleted successfully"}
+110 -12
View File
@@ -11,7 +11,7 @@ from typing import Optional
from app.database import get_db
from app.services.resource_allocation_service import ResourceAllocationService
from app.services.procurement_flow_service import ProcurementFlowService
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase
from app.models import Project, System, Guardian, Module, Resource, ResourceAllocation, Specification, Purchase, SystemModule, SpecificationItem, PurchaseItem, Contract, PurchaseSpecification
router = APIRouter(prefix="/ui", tags=["UI"])
templates = Jinja2Templates(directory="app/templates")
@@ -75,9 +75,9 @@ async def project_detail(request: Request, project_id: int, db: Session = Depend
if not project:
raise HTTPException(status_code=404, detail="Project not found")
customers = db.query(Project).filter(Project.id == project_id).first().customers
customers = project.customers
systems = db.query(System).filter(System.project_id == project_id).all()
contracts = db.query(Project).filter(Project.id == project_id).first().contracts
contracts = db.query(Contract).filter(Contract.project_id == project_id).all()
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
@@ -118,8 +118,8 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
if not system:
raise HTTPException(status_code=404, detail="System not found")
# Get Common part (guardian_id = NULL)
common_modules = db.query(SystemModule).filter(
# Get Common part (guardian_id = NULL) with joined loading
common_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == None
).all()
@@ -129,13 +129,13 @@ async def system_detail(request: Request, system_id: int, db: Session = Depends(
guardian_data = []
for guardian in guardians:
core = db.query(SystemModule).filter(
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == guardian.id,
Module.name == "Core"
).first()
other_modules = db.query(SystemModule).filter(
other_modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.system_id == system_id,
SystemModule.guardian_id == guardian.id
).all()
@@ -164,12 +164,12 @@ async def guardian_detail(request: Request, guardian_id: int, db: Session = Depe
if not guardian:
raise HTTPException(status_code=404, detail="Guardian not found")
core = db.query(SystemModule).filter(
core = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.guardian_id == guardian_id,
Module.name == "Core"
).first()
modules = db.query(SystemModule).filter(
modules = db.query(SystemModule).join(Module, SystemModule.module_id == Module.id).filter(
SystemModule.guardian_id == guardian_id
).all()
@@ -205,6 +205,9 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
if not resource:
raise HTTPException(status_code=404, detail="Resource not found")
# Get systems for this project
systems = db.query(System).filter(System.project_id == resource.project_id).all()
# Get allocations for this resource
allocations = db.query(ResourceAllocation).filter(
ResourceAllocation.resource_id == resource_id
@@ -233,7 +236,8 @@ async def resource_detail(request: Request, resource_id: int, db: Session = Depe
"request": request,
"resource": resource,
"allocations": allocation_details,
"remaining": remaining
"remaining": remaining,
"systems": systems
}
)
@@ -297,7 +301,7 @@ async def specification_detail(request: Request, specification_id: int, db: Sess
if not specification:
raise HTTPException(status_code=404, detail="Specification not found")
items = db.query(SpecificationItem).filter(
items = db.query(SpecificationItem).join(Module, SpecificationItem.module_id == Module.id).filter(
SpecificationItem.specification_id == specification_id
).all()
@@ -327,7 +331,7 @@ async def purchases_list(request: Request, project_id: Optional[int] = None, db:
@router.get("/purchases/{purchase_id}")
async def purchase_detail(request: Request, purchase_id: int, db: Session = Depends(get_db)):
"""Purchase detail page."""
"Purchase detail page."
purchase = db.query(Purchase).filter(Purchase.id == purchase_id).first()
if not purchase:
raise HTTPException(status_code=404, detail="Purchase not found")
@@ -355,9 +359,103 @@ async def purchase_detail(request: Request, purchase_id: int, db: Session = Depe
)
@router.get("/projects")
async def projects_list(request: Request, db: Session = Depends(get_db)):
"""List all projects."""
projects = db.query(Project).all()
return templates.TemplateResponse(
"projects/list.html",
{"request": request, "projects": projects}
)
async def project_systems_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Systems list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
systems = db.query(System).filter(System.project_id == project_id).all()
return templates.TemplateResponse(
"systems/list.html",
{"request": request, "systems": systems, "project_id": project_id}
)
@router.get("/projects/{project_id}/resources")
async def project_resources_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Resources list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
resources = db.query(Resource).filter(Resource.project_id == project_id).all()
return templates.TemplateResponse(
"resources/list.html",
{"request": request, "resources": resources, "project_id": project_id}
)
@router.get("/projects/{project_id}/specifications")
async def project_specifications_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Specifications list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
specifications = db.query(Specification).filter(Specification.project_id == project_id).all()
return templates.TemplateResponse(
"specifications/list.html",
{"request": request, "specifications": specifications, "project_id": project_id}
)
@router.get("/projects/{project_id}/purchases")
async def project_purchases_list(request: Request, project_id: int, db: Session = Depends(get_db)):
"""Purchases list for project."""
project = db.query(Project).filter(Project.id == project_id).first()
if not project:
raise HTTPException(status_code=404, detail="Project not found")
purchases = db.query(Purchase).filter(Purchase.project_id == project_id).all()
return templates.TemplateResponse(
"purchases/list.html",
{"request": request, "purchases": purchases, "project_id": project_id}
)
@router.get("/seed")
async def seed_demo_data(db: Session = Depends(get_db)):
"""Seed demo data endpoint."""
from app.utils.seed_data import seed_demo_data
seed_demo_data(db)
return {"message": "Demo data seeded successfully"}
@router.get("/resources/{resource_id}/allocate")
async def allocate_resource(request: Request, resource_id: int, system_id: int = Query(...), guardian_id: Optional[int] = Query(None), quantity: int = Query(...), db: Session = Depends(get_db)):
"""Allocate resource to system/guardian."""
# Use ResourceAllocationService for business logic
service = ResourceAllocationService(db)
result = service.allocate_resource(resource_id, system_id, guardian_id, quantity)
if result['success']:
return templates.TemplateResponse(
"resources/allocated.html",
{
"request": request,
"allocation": result['allocation'],
"resource": result['resource'],
"system": result['system'],
"guardian": result.get('guardian')
}
)
else:
return templates.TemplateResponse(
"resources/allocate_error.html",
{
"request": request,
"error": result['error'],
"resource": result.get('resource'),
"resource_id": resource_id
}
)
-145
View File
@@ -83,25 +83,6 @@ class System(SystemBase):
class Config:
from_attributes = True
# Key schemas
class KeyBase(TimestampMixin):
name: str
description: Optional[str] = None
system_id: int
guardian_id: int
class KeyCreate(KeyBase):
pass
class KeyUpdate(KeyBase):
pass
class Key(KeyBase):
id: int
class Config:
from_attributes = True
# Guardian schemas
class GuardianBase(TimestampMixin):
name: str
@@ -121,132 +102,6 @@ class Guardian(GuardianBase):
class Config:
from_attributes = True
# LicenseType schemas
class LicenseTypeBase(TimestampMixin):
name: str
description: Optional[str] = None
class LicenseTypeCreate(LicenseTypeBase):
pass
class LicenseTypeUpdate(LicenseTypeBase):
pass
class LicenseType(LicenseTypeBase):
id: int
class Config:
from_attributes = True
# Product schemas
class ProductBase(TimestampMixin):
name: str
description: Optional[str] = None
class ProductCreate(ProductBase):
pass
class ProductUpdate(ProductBase):
pass
class Product(ProductBase):
id: int
class Config:
from_attributes = True
# ResourcePool schemas
class ResourcePoolBase(TimestampMixin):
name: str
description: Optional[str] = None
class ResourcePoolCreate(ResourcePoolBase):
pass
class ResourcePoolUpdate(ResourcePoolBase):
pass
class ResourcePool(ResourcePoolBase):
id: int
class Config:
from_attributes = True
# PoolResource schemas
class PoolResourceBase(TimestampMixin):
resource_pool_id: int
product_id: int
license_type_id: int
class PoolResourceCreate(PoolResourceBase):
pass
class PoolResourceUpdate(PoolResourceBase):
pass
class PoolResource(PoolResourceBase):
id: int
class Config:
from_attributes = True
# PoolReceipt schemas
class PoolReceiptBase(TimestampMixin):
pool_resource_id: int
quantity: int
receipt_date: datetime
description: Optional[str] = None
class PoolReceiptCreate(PoolReceiptBase):
pass
class PoolReceiptUpdate(PoolReceiptBase):
pass
class PoolReceipt(PoolReceiptBase):
id: int
class Config:
from_attributes = True
# PoolAllocation schemas
class PoolAllocationBase(TimestampMixin):
pool_resource_id: int
quantity: int
allocation_date: datetime
description: Optional[str] = None
class PoolAllocationCreate(PoolAllocationBase):
pass
class PoolAllocationUpdate(PoolAllocationBase):
pass
class PoolAllocation(PoolAllocationBase):
id: int
class Config:
from_attributes = True
# License schemas
class LicenseBase(TimestampMixin):
system_id: int
key_id: Optional[int] = None
product_id: int
license_type_id: int
class LicenseCreate(LicenseBase):
pass
class LicenseUpdate(LicenseBase):
pass
class License(LicenseBase):
id: int
class Config:
from_attributes = True
# Contract schemas
class ContractBase(TimestampMixin):
project_id: int
Binary file not shown.
Regular → Executable
+54 -54
View File
@@ -1,55 +1,55 @@
"""
Pool resource service for handling resource operations
"""
from sqlalchemy.orm import Session
from app.models import PoolResource, PoolReceipt, PoolAllocation
from typing import Optional
class PoolResourceService:
def __init__(self, db: Session):
self.db = db
def get_current_balance(self, pool_resource_id: int) -> int:
"""Calculate current balance from receipts and allocations"""
# Get all receipts for this resource
receipts = self.db.query(PoolReceipt).filter(
PoolReceipt.pool_resource_id == pool_resource_id
).all()
# Get all allocations for this resource
allocations = self.db.query(PoolAllocation).filter(
PoolAllocation.pool_resource_id == pool_resource_id
).all()
# Calculate total receipt quantity
total_receipts = sum(r.quantity for r in receipts)
# Calculate total allocation quantity
total_allocations = sum(a.quantity for a in allocations)
# Return balance
return total_receipts - total_allocations
def can_allocate(self, pool_resource_id: int, quantity: int) -> bool:
"""Check if allocation of specified quantity is possible"""
current_balance = self.get_current_balance(pool_resource_id)
return quantity <= current_balance
def allocate_resource(self, pool_resource_id: int, quantity: int,
description: Optional[str] = None) -> bool:
"""Allocate resource to a pool"""
# Check if allocation is possible
if not self.can_allocate(pool_resource_id, quantity):
return False
# Create allocation record
allocation = PoolAllocation(
pool_resource_id=pool_resource_id,
quantity=quantity,
description=description
)
self.db.add(allocation)
self.db.commit()
self.db.refresh(allocation)
"""
Pool resource service for handling resource operations
"""
from sqlalchemy.orm import Session
from app.models import PoolResource, PoolReceipt, PoolAllocation
from typing import Optional
class PoolResourceService:
def __init__(self, db: Session):
self.db = db
def get_current_balance(self, pool_resource_id: int) -> int:
"""Calculate current balance from receipts and allocations"""
# Get all receipts for this resource
receipts = self.db.query(PoolReceipt).filter(
PoolReceipt.pool_resource_id == pool_resource_id
).all()
# Get all allocations for this resource
allocations = self.db.query(PoolAllocation).filter(
PoolAllocation.pool_resource_id == pool_resource_id
).all()
# Calculate total receipt quantity
total_receipts = sum(r.quantity for r in receipts)
# Calculate total allocation quantity
total_allocations = sum(a.quantity for a in allocations)
# Return balance
return total_receipts - total_allocations
def can_allocate(self, pool_resource_id: int, quantity: int) -> bool:
"""Check if allocation of specified quantity is possible"""
current_balance = self.get_current_balance(pool_resource_id)
return quantity <= current_balance
def allocate_resource(self, pool_resource_id: int, quantity: int,
description: Optional[str] = None) -> bool:
"""Allocate resource to a pool"""
# Check if allocation is possible
if not self.can_allocate(pool_resource_id, quantity):
return False
# Create allocation record
allocation = PoolAllocation(
pool_resource_id=pool_resource_id,
quantity=quantity,
description=description
)
self.db.add(allocation)
self.db.commit()
self.db.refresh(allocation)
return True
+3 -3
View File
@@ -24,10 +24,10 @@
<strong>Структура Guardian:</strong>
<pre class="mb-0" style="background: #e9ecef; padding: 10px;">Guardian {{ guardian.name }}
├── Core: 1
└── Modules: {{ modules|length }}
└── Modules: {{ modules|length }}</pre>
{% for m in modules %}
- {{ m.module.name }} × {{ m.quantity }}
{% endfor %}</pre>
{{ '-' }} {{ m.module.name }} × {{ m.quantity }}
{% endfor %}
</div>
<div class="section-title">Core</div>
+22
View File
@@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block title %}Projects - Specs UI{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="page-header">
<h1>Проекты</h1>
</div>
<div class="row">
{% for project in projects %}
<div class="col-md-4">
<div class="stat-card">
<h3>{{ project.name }}</h3>
<p>{{ project.description or "Нет описания" }}</p>
<a href="/ui/projects/{{ project.id }}" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
+1 -1
View File
@@ -90,7 +90,7 @@
<p class="text-muted">Закупки связаны со спецификациями через PurchaseSpecification. Invoice относится к Purchase.</p>
<div class="mt-4">
<a href="{{ url_for('purchases_list', project_id=purchase.project_id) }}" class="btn btn-secondary">
<a href="{{ url_for('project_detail', project_id=purchase.project_id) }}" class="btn btn-secondary">
К списку закупок
</a>
<a href="{{ url_for('project_detail', project_id=purchase.project_id) }}" class="btn btn-secondary">
+3 -3
View File
@@ -107,7 +107,7 @@
<label class="form-label" for="system_id">Система:</label>
<select class="form-select" name="system_id" id="system_id" required>
<option value="">-- Выберите систему --</option>
{% for system in resource.project.systems %}
{% for system in systems %}
<option value="{{ system.id }}">{{ system.name }} ({{ system.customer.name if system.customer else 'N/A' }})</option>
{% else %}
<option disabled>Нет систем в проекте</option>
@@ -119,7 +119,7 @@
<label class="form-label" for="guardian_id">Guardian (опционально):</label>
<select class="form-select" name="guardian_id" id="guardian_id">
<option value="">Общая часть (NULL)</option>
{% for system in resource.project.systems %}
{% for system in systems %}
{% for guardian in system.guardians %}
<option value="{{ guardian.id }}">{{ guardian.name }}</option>
{% endfor %}
@@ -146,7 +146,7 @@
{% endif %}
<div class="mt-4">
<a href="{{ url_for('resources_list', project_id=resource.project_id) }}" class="btn btn-secondary">
<a href="{{ url_for('project_detail', project_id=resource.project_id) }}" class="btn btn-secondary">
К пулу ресурсов
</a>
</div>
+8 -2
View File
@@ -42,11 +42,17 @@
<td>{{ resource.module.name if resource.module else 'N/A' }}</td>
<td>{{ resource.quantity }}</td>
<td>
{% set allocated = resource.resource_allocations|sum(attribute='quantity', default=0) %}
{% set allocated = 0 %}
{% for allocation in resource.resource_allocations %}
{% set allocated = allocated + allocation.quantity %}
{% endfor %}
{{ allocated }}
</td>
<td>
{% set allocated = resource.resource_allocations|sum(attribute='quantity', default=0) %}
{% set allocated = 0 %}
{% for allocation in resource.resource_allocations %}
{% set allocated = allocated + allocation.quantity %}
{% endfor %}
{% set remaining = resource.quantity - allocated %}
<span class="badge {% if remaining <= 0 %}bg-danger{% elif remaining < 100 %}bg-warning{% else %}bg-success{% endif %}">
{{ remaining }}
+1 -1
View File
@@ -78,7 +78,7 @@
</div>
<div class="mt-4">
<a href="{{ url_for('specifications_list', project_id=specification.project_id) }}" class="btn btn-secondary">
<a href="{{ url_for('project_detail', project_id=specification.project_id) }}" class="btn btn-secondary">
К списку спецификаций
</a>
<a href="{{ url_for('project_detail', project_id=specification.project_id) }}" class="btn btn-secondary">
-3
View File
@@ -111,9 +111,6 @@
</div>
<div class="mt-4">
<a href="{{ url_for('resources_list', project_id=system.project_id) }}" class="btn btn-secondary">
Ресурсы проекта
</a>
<a href="{{ url_for('project_detail', project_id=system.project_id) }}" class="btn btn-secondary">
К проекту
</a>
+22
View File
@@ -0,0 +1,22 @@
{% extends "base.html" %}
{% block title %}Systems - Specs UI{% endblock %}
{% block content %}
<div class="container-fluid">
<div class="page-header">
<h1>Системы</h1>
</div>
<div class="row">
{% for system in systems %}
<div class="col-md-4">
<div class="stat-card">
<h3>{{ system.name }}</h3>
<p>{{ system.description or "Нет описания" }}</p>
<a href="/ui/systems/{{ system.id }}" class="btn btn-sm btn-primary">Подробнее</a>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}