mirror of
https://github.com/lnbits/lnbits-legend.git
synced 2025-02-25 23:21:21 +01:00
* initial commit * add docs * black & prettier * mobile styles * add print view * prettier * make format * initial migrations un-messed * make migrations work for sqlite * add invoices table * clean migrations * add migration to conv * fix card size * hopefully fix test migration * add missing status * timestamp * init testing * remove draft invoice by default on create * what should i test * make format * raise if not invoice * new test and renaming * fix issue reported by @talvasconcelos which prevented users from setting status on creation * readme * run black * trying to make tests work * make it work again * send paid amount * partial pay flow * good coding * can't get these test to work * clean up and commenting * make format * validation for 2 decimals Co-authored-by: ben <ben@arc.wales> Co-authored-by: Tiago vasconcelos <talvasconcelos@gmail.com>
104 lines
2.1 KiB
Python
104 lines
2.1 KiB
Python
from enum import Enum
|
|
from sqlite3 import Row
|
|
from typing import List, Optional
|
|
|
|
from fastapi.param_functions import Query
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class InvoiceStatusEnum(str, Enum):
|
|
draft = "draft"
|
|
open = "open"
|
|
paid = "paid"
|
|
canceled = "canceled"
|
|
|
|
|
|
class CreateInvoiceItemData(BaseModel):
|
|
description: str
|
|
amount: float = Query(..., ge=0.01)
|
|
|
|
|
|
class CreateInvoiceData(BaseModel):
|
|
status: InvoiceStatusEnum = InvoiceStatusEnum.draft
|
|
currency: str
|
|
company_name: Optional[str]
|
|
first_name: Optional[str]
|
|
last_name: Optional[str]
|
|
email: Optional[str]
|
|
phone: Optional[str]
|
|
address: Optional[str]
|
|
items: List[CreateInvoiceItemData]
|
|
|
|
class Config:
|
|
use_enum_values = True
|
|
|
|
|
|
class UpdateInvoiceItemData(BaseModel):
|
|
id: Optional[str]
|
|
description: str
|
|
amount: float = Query(..., ge=0.01)
|
|
|
|
|
|
class UpdateInvoiceData(BaseModel):
|
|
id: str
|
|
wallet: str
|
|
status: InvoiceStatusEnum = InvoiceStatusEnum.draft
|
|
currency: str
|
|
company_name: Optional[str]
|
|
first_name: Optional[str]
|
|
last_name: Optional[str]
|
|
email: Optional[str]
|
|
phone: Optional[str]
|
|
address: Optional[str]
|
|
items: List[UpdateInvoiceItemData]
|
|
|
|
|
|
class Invoice(BaseModel):
|
|
id: str
|
|
wallet: str
|
|
status: InvoiceStatusEnum = InvoiceStatusEnum.draft
|
|
currency: str
|
|
company_name: Optional[str]
|
|
first_name: Optional[str]
|
|
last_name: Optional[str]
|
|
email: Optional[str]
|
|
phone: Optional[str]
|
|
address: Optional[str]
|
|
time: int
|
|
|
|
class Config:
|
|
use_enum_values = True
|
|
|
|
@classmethod
|
|
def from_row(cls, row: Row) -> "Invoice":
|
|
return cls(**dict(row))
|
|
|
|
|
|
class InvoiceItem(BaseModel):
|
|
id: str
|
|
invoice_id: str
|
|
description: str
|
|
amount: int
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
|
|
@classmethod
|
|
def from_row(cls, row: Row) -> "InvoiceItem":
|
|
return cls(**dict(row))
|
|
|
|
|
|
class Payment(BaseModel):
|
|
id: str
|
|
invoice_id: str
|
|
amount: int
|
|
time: int
|
|
|
|
@classmethod
|
|
def from_row(cls, row: Row) -> "Payment":
|
|
return cls(**dict(row))
|
|
|
|
|
|
class CreatePaymentData(BaseModel):
|
|
invoice_id: str
|
|
amount: int
|