qq1023's picture
Update categories/random_/model.py
ab90a7d
raw
history blame
2.84 kB
# generated by datamodel-codegen:
# filename: schema.json
# timestamp: 2023-07-28T11:36:16+00:00
from __future__ import annotations
from datetime import date
from typing import Dict, Optional, Union
import iso4217
from pydantic import BaseModel, Field, constr, validator, ValidationError
class TaxItem(BaseModel):
gst: str = Field(
...,
title="The total GST tax amount (IGST + CGST + SGST + etc) as a single number",
)
class TaxItem1(BaseModel):
vat: str = Field(..., title="The total VAT present in the invoice")
class TaxNumberItem(BaseModel):
gst_number: constr(min_length=15) = Field(
..., title="The alphanumeric GSTIN/GST number code"
)
class TaxNumberItem1(BaseModel):
vat_number: str = Field(..., title="The VAT/TIN number present in older invoices")
class TaxNumberItem2(BaseModel):
ui_number: str = Field(..., title="The tax UIN issued to foreign entities")
class SellerDetails(BaseModel):
name: Optional[str] = None
address: Optional[str] = None
contact: Optional[str] = None
tax_number: Union[TaxNumberItem, TaxNumberItem1, TaxNumberItem2] = Field(
..., title="Tax information"
)
pan_number: constr(min_length=10, max_length=10) = Field(
..., title="The 10-character alphanumeric PAN code"
)
class UIDDict(BaseModel):
invoice_number: str = Field(..., title="The invoice number")
# other_uids: Dict[str, str] = Field(
# ...,
# title="Key-value pairs of uniquely identifying numbers (UIDs) like order number, bill number, payment ID, etc but not the invoice number",
# )
class InformationExtractedFromABillReceipt(BaseModel):
uids: str = Field(..., title="The bill number/invoice number")
#uids: UIDDict = Field(..., title="Invoice number and other UIDs")
total: float = Field(..., title="Total amount or price converted from the given currency to INR")
tax: Union[TaxItem, TaxItem1] = Field(..., title="The total tax amount")
name: str = Field(
...,
title="Name of the person/entity that the invoice item was charged or delivered to",
)
currency: str = Field(
default="INR",
title="The ISO 4217 code for the currency in which the prices in the invoice are (inferred from symbols, names, addresses, etc)",
)
issue_date: date = Field(
..., title="The date the invoice was issued"
)
seller_details: SellerDetails = Field(..., title="Information about the seller")
summary: str = Field(..., title="5-6 words short summary of purchased good(s)")
@validator("currency")
@classmethod
def check_currency(cls, v: str) -> str:
if not iso4217.Currency.__members__.get(v.lower()):
raise ValidationError(f"{v} is not a valid ISO 4217 currency code")
return v.upper()