finance.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. from datetime import datetime
  2. from typing import Literal
  3. from pydantic import BaseModel, Field
  4. from backend.app.schemas.not_null import IgnoresNullForRequiredColumns
  5. class WalletBalanceResponse(BaseModel):
  6. user_id: int
  7. balance: float
  8. currency: str
  9. updated_at: datetime | None = None
  10. class WalletTransactionResponse(BaseModel):
  11. id: int
  12. user_id: int | None # None once the user is deleted
  13. cost_center_id: int | None = None
  14. transaction_type: Literal["print_charge", "deposit", "withdraw", "manual_adjustment"]
  15. amount: float
  16. balance_after: float | None = None
  17. description: str | None = None
  18. created_by_user_id: int | None = None
  19. print_run_id: str | None = None
  20. print_archive_id: int | None = None
  21. print_queue_id: int | None = None
  22. created_at: datetime
  23. class Config:
  24. from_attributes = True
  25. class WalletTransactionListResponse(BaseModel):
  26. items: list[WalletTransactionResponse]
  27. total: int
  28. limit: int
  29. offset: int
  30. class CostCenterSummaryResponse(BaseModel):
  31. id: int
  32. name: str
  33. is_private: bool
  34. owner_user_id: int | None = None
  35. is_active: bool
  36. total_balance: float = 0.0
  37. total_budget: float | None = None
  38. monthly_budget: float | None = None
  39. budget_mode: str = "none"
  40. budget_limit: float | None = None
  41. budget_used: float | None = None
  42. budget_available: float | None = None
  43. can_print: bool = True
  44. class Config:
  45. from_attributes = True
  46. class WalletAdjustmentRequest(BaseModel):
  47. amount: float = Field(..., gt=0)
  48. description: str | None = None
  49. cost_center_id: int | None = None
  50. class WalletAdjustmentResponse(BaseModel):
  51. transaction: WalletTransactionResponse
  52. balance: WalletBalanceResponse
  53. class TransactionEditRequest(IgnoresNullForRequiredColumns):
  54. __orm_table__ = "wallet_transactions"
  55. user_id: int | None = None
  56. cost_center_id: int | None = None
  57. amount: float | None = None
  58. description: str | None = None
  59. class ManualPrintRequest(BaseModel):
  60. user_id: int
  61. cost_center_id: int
  62. amount: float = Field(..., gt=0)
  63. description: str | None = None
  64. created_at: datetime | None = None
  65. class CostCenterCreateRequest(BaseModel):
  66. name: str = Field(..., min_length=1, max_length=150)
  67. total_budget: float | None = Field(default=None, ge=0)
  68. monthly_budget: float | None = Field(default=None, ge=0)
  69. is_active: bool = True
  70. class CostCenterUpdateRequest(IgnoresNullForRequiredColumns):
  71. __orm_table__ = "cost_centers"
  72. name: str | None = Field(default=None, min_length=1, max_length=150)
  73. is_active: bool | None = None
  74. class CostCenterBudgetUpdateRequest(BaseModel):
  75. total_budget: float | None = Field(default=None, ge=0)
  76. monthly_budget: float | None = Field(default=None, ge=0)
  77. class CostCenterMemberRequest(BaseModel):
  78. user_id: int
  79. can_print: bool = True
  80. class CostCenterMemberResponse(BaseModel):
  81. id: int
  82. cost_center_id: int
  83. user_id: int
  84. can_print: bool
  85. created_at: datetime
  86. class Config:
  87. from_attributes = True
  88. class CostCenterDetailResponse(CostCenterSummaryResponse):
  89. members: list[CostCenterMemberResponse] = []