Asset-side printer save, status CRUD, real printer types, network fix

- Printers save through the asset blueprint (PUT /printers) instead of the
  legacy machines API; restrict supply-model picker to printer models.
- Asset statuses get full CRUD (PUT/DELETE with in-use guard); canonical set.
- Printer types reseeded to a real classification set + list filter.
- Equipment accepts gauge/maintenance references.
- Fix network list emitting network_device instead of networkdevice (View 404).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
cproudlock
2026-06-26 08:35:32 -04:00
parent 4626280dc4
commit 0436e8b0af
8 changed files with 451 additions and 39 deletions

View File

@@ -153,6 +153,56 @@ def create_asset_status():
return success_response(s.to_dict(), message='Asset status created', http_code=201)
@assets_bp.route('/statuses/<int:status_id>', methods=['PUT'])
@jwt_required()
def update_asset_status(status_id: int):
"""Update an asset status."""
s = AssetStatus.query.get(status_id)
if not s:
return error_response(ErrorCodes.NOT_FOUND, 'Asset status not found',
http_code=404)
data = request.get_json() or {}
# Conflict check on rename
if 'status' in data and data['status'] != s.status:
if AssetStatus.query.filter_by(status=data['status']).first():
return error_response(
ErrorCodes.CONFLICT,
f"Asset status '{data['status']}' already exists",
http_code=409
)
for key in ('status', 'description', 'color', 'isactive'):
if key in data:
setattr(s, key, data[key])
db.session.commit()
return success_response(s.to_dict(), message='Asset status updated')
@assets_bp.route('/statuses/<int:status_id>', methods=['DELETE'])
@jwt_required()
def delete_asset_status(status_id: int):
"""Delete an asset status. Refused if any asset still uses it."""
s = AssetStatus.query.get(status_id)
if not s:
return error_response(ErrorCodes.NOT_FOUND, 'Asset status not found',
http_code=404)
inuse = Asset.query.filter_by(statusid=status_id).count()
if inuse:
return error_response(
ErrorCodes.CONFLICT,
f"Cannot delete: {inuse} asset(s) still use this status",
http_code=409
)
db.session.delete(s)
db.session.commit()
return success_response(message='Asset status deleted')
# =============================================================================
# Assets
# =============================================================================