Coverage for polar/models/wallet_transaction.py: 88%

31 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 16:17 +0000

1from datetime import datetime 1ab

2from typing import TYPE_CHECKING 1ab

3from uuid import UUID 1ab

4 

5from sqlalchemy import TIMESTAMP, ForeignKey, String, Uuid 1ab

6from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab

7from sqlalchemy.sql.sqltypes import BigInteger 1ab

8 

9from polar.kit.db.models import IDModel 1ab

10from polar.kit.utils import utc_now 1ab

11 

12if TYPE_CHECKING: 12 ↛ 13line 12 didn't jump to line 13 because the condition on line 12 was never true1ab

13 from .order import Order 

14 from .refund import Refund 

15 from .wallet import Wallet 

16 

17 

18class WalletTransaction(IDModel): 1ab

19 __tablename__ = "wallet_transactions" 1ab

20 

21 timestamp: Mapped[datetime] = mapped_column( 1ab

22 TIMESTAMP(timezone=True), nullable=False, default=utc_now, index=True 

23 ) 

24 currency: Mapped[str] = mapped_column(String(3)) 1ab

25 amount: Mapped[int] = mapped_column(BigInteger) 1ab

26 wallet_id: Mapped[UUID] = mapped_column( 1ab

27 Uuid, ForeignKey("wallets.id", ondelete="restrict"), index=True 

28 ) 

29 

30 tax_amount: Mapped[int | None] = mapped_column( 1ab

31 BigInteger, nullable=True, default=None 

32 ) 

33 tax_calculation_processor_id: Mapped[str | None] = mapped_column( 1ab

34 String, nullable=True, default=None 

35 ) 

36 

37 order_id: Mapped[UUID | None] = mapped_column( 1ab

38 "order_id", 

39 Uuid, 

40 ForeignKey("orders.id", ondelete="restrict"), 

41 index=True, 

42 nullable=True, 

43 ) 

44 

45 refund_id: Mapped[UUID | None] = mapped_column( 1ab

46 "refund_id", 

47 Uuid, 

48 ForeignKey("refunds.id", ondelete="restrict"), 

49 index=True, 

50 nullable=True, 

51 ) 

52 

53 @declared_attr 1ab

54 def wallet(cls) -> Mapped["Wallet"]: 1ab

55 return relationship("Wallet", lazy="raise_on_sql") 1ab

56 

57 @declared_attr 1ab

58 def order(cls) -> Mapped["Order | None"]: 1ab

59 return relationship("Order", lazy="raise_on_sql") 1ab

60 

61 @declared_attr 1ab

62 def refund(cls) -> Mapped["Refund | None"]: 1ab

63 return relationship("Refund", lazy="raise_on_sql") 1ab