finance.py 2.9 KB

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