feature: Added Transactions and major Order System Overhaul
This commit is contained in:
@@ -5,7 +5,7 @@ from typing import Optional
|
||||
|
||||
from auth.models import TokenPayload
|
||||
from auth.dependencies import require_permission
|
||||
from crm.models import CustomerCreate, CustomerUpdate, CustomerInDB, CustomerListResponse
|
||||
from crm.models import CustomerCreate, CustomerUpdate, CustomerInDB, CustomerListResponse, TransactionEntry
|
||||
from crm import service, nextcloud
|
||||
from config import settings
|
||||
|
||||
@@ -105,26 +105,141 @@ async def delete_customer(
|
||||
logger.warning("Could not rename NC folder for customer %s: %s", customer_id, e)
|
||||
|
||||
|
||||
@router.post("/{customer_id}/toggle-negotiating", response_model=CustomerInDB)
|
||||
async def toggle_negotiating(
|
||||
customer_id: str,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return await service.toggle_negotiating(customer_id)
|
||||
|
||||
|
||||
@router.post("/{customer_id}/toggle-problem", response_model=CustomerInDB)
|
||||
async def toggle_problem(
|
||||
customer_id: str,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return await service.toggle_problem(customer_id)
|
||||
|
||||
|
||||
@router.get("/{customer_id}/last-comm-direction")
|
||||
async def get_last_comm_direction(
|
||||
customer_id: str,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "view")),
|
||||
):
|
||||
direction = await service.get_last_comm_direction(customer_id)
|
||||
return {"direction": direction}
|
||||
result = await service.get_last_comm_direction(customer_id)
|
||||
return result
|
||||
|
||||
|
||||
# ── Relationship Status ───────────────────────────────────────────────────────
|
||||
|
||||
@router.patch("/{customer_id}/relationship-status", response_model=CustomerInDB)
|
||||
def update_relationship_status(
|
||||
customer_id: str,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.update_relationship_status(customer_id, body.get("status", ""))
|
||||
|
||||
|
||||
# ── Technical Issues ──────────────────────────────────────────────────────────
|
||||
|
||||
@router.post("/{customer_id}/technical-issues", response_model=CustomerInDB)
|
||||
def add_technical_issue(
|
||||
customer_id: str,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.add_technical_issue(
|
||||
customer_id,
|
||||
note=body.get("note", ""),
|
||||
opened_by=body.get("opened_by", ""),
|
||||
date=body.get("date"),
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/{customer_id}/technical-issues/{index}/resolve", response_model=CustomerInDB)
|
||||
def resolve_technical_issue(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.resolve_technical_issue(customer_id, index, body.get("resolved_by", ""))
|
||||
|
||||
|
||||
@router.patch("/{customer_id}/technical-issues/{index}", response_model=CustomerInDB)
|
||||
def edit_technical_issue(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.edit_technical_issue(customer_id, index, body.get("note", ""), body.get("opened_date"))
|
||||
|
||||
|
||||
@router.delete("/{customer_id}/technical-issues/{index}", response_model=CustomerInDB)
|
||||
def delete_technical_issue(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.delete_technical_issue(customer_id, index)
|
||||
|
||||
|
||||
# ── Install Support ───────────────────────────────────────────────────────────
|
||||
|
||||
@router.post("/{customer_id}/install-support", response_model=CustomerInDB)
|
||||
def add_install_support(
|
||||
customer_id: str,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.add_install_support(
|
||||
customer_id,
|
||||
note=body.get("note", ""),
|
||||
opened_by=body.get("opened_by", ""),
|
||||
date=body.get("date"),
|
||||
)
|
||||
|
||||
|
||||
@router.patch("/{customer_id}/install-support/{index}/resolve", response_model=CustomerInDB)
|
||||
def resolve_install_support(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.resolve_install_support(customer_id, index, body.get("resolved_by", ""))
|
||||
|
||||
|
||||
@router.patch("/{customer_id}/install-support/{index}", response_model=CustomerInDB)
|
||||
def edit_install_support(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
body: dict = Body(...),
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.edit_install_support(customer_id, index, body.get("note", ""), body.get("opened_date"))
|
||||
|
||||
|
||||
@router.delete("/{customer_id}/install-support/{index}", response_model=CustomerInDB)
|
||||
def delete_install_support(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.delete_install_support(customer_id, index)
|
||||
|
||||
|
||||
# ── Transactions ──────────────────────────────────────────────────────────────
|
||||
|
||||
@router.post("/{customer_id}/transactions", response_model=CustomerInDB)
|
||||
def add_transaction(
|
||||
customer_id: str,
|
||||
body: TransactionEntry,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.add_transaction(customer_id, body)
|
||||
|
||||
|
||||
@router.patch("/{customer_id}/transactions/{index}", response_model=CustomerInDB)
|
||||
def update_transaction(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
body: TransactionEntry,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.update_transaction(customer_id, index, body)
|
||||
|
||||
|
||||
@router.delete("/{customer_id}/transactions/{index}", response_model=CustomerInDB)
|
||||
def delete_transaction(
|
||||
customer_id: str,
|
||||
index: int,
|
||||
_user: TokenPayload = Depends(require_permission("crm", "edit")),
|
||||
):
|
||||
return service.delete_transaction(customer_id, index)
|
||||
|
||||
Reference in New Issue
Block a user