Added custom serializer to Decimal for all Models to output as number and not string.
This should mitigate all hacks earlier and reverted the earlier hacks.
This commit is contained in:
@@ -1,3 +1,13 @@
|
|||||||
|
from decimal import Decimal
|
||||||
|
from typing import Annotated
|
||||||
|
|
||||||
|
from pydantic import PlainSerializer
|
||||||
|
|
||||||
|
|
||||||
def to_camel(string: str) -> str:
|
def to_camel(string: str) -> str:
|
||||||
first, *others = string.split("_")
|
first, *others = string.split("_")
|
||||||
return "".join([first] + [word.capitalize() for word in others])
|
return "".join([first] + [word.capitalize() for word in others])
|
||||||
|
|
||||||
|
|
||||||
|
# Custom serializer to serialize decimal as float and not as string as is the default behaviour in Pydantic V2
|
||||||
|
Daf = Annotated[Decimal, PlainSerializer(lambda x: float(x), return_type=float, when_used="unless-none")]
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class AttendanceType(BaseModel):
|
class AttendanceType(BaseModel):
|
||||||
id_: int
|
id_: int
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
value: Decimal | None = None
|
value: Daf | None = None
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
# TODO: Add config
|
# TODO: Add config
|
||||||
class AccountBalance(BaseModel):
|
class AccountBalance(BaseModel):
|
||||||
date_: Decimal
|
date_: Daf
|
||||||
total: Decimal
|
total: Daf
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,14 +8,14 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class BalanceSheetItem(BaseModel):
|
class BalanceSheetItem(BaseModel):
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
group: str | None = None
|
group: str | None = None
|
||||||
amount: Decimal | None = None
|
amount: Daf | None = None
|
||||||
sub_amount: Decimal | None = None
|
sub_amount: Daf | None = None
|
||||||
order: int
|
order: int
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.product import ProductLink
|
from brewman.schemas.product import ProductLink
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class Batch(BaseModel):
|
class Batch(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
name: str
|
name: str
|
||||||
sku: ProductLink
|
sku: ProductLink
|
||||||
quantity_remaining: Decimal
|
quantity_remaining: Daf
|
||||||
rate: Decimal
|
rate: Daf
|
||||||
tax: Decimal
|
tax: Daf
|
||||||
discount: Decimal
|
discount: Daf
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,15 +10,15 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class BatchIntegrityItem(BaseModel):
|
class BatchIntegrityItem(BaseModel):
|
||||||
date_: date
|
date_: date
|
||||||
type_: str
|
type_: str
|
||||||
url: list[str]
|
url: list[str]
|
||||||
quantity: Decimal
|
quantity: Daf
|
||||||
price: Decimal
|
price: Daf
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
@field_validator("date_", mode="before")
|
@field_validator("date_", mode="before")
|
||||||
@@ -38,9 +37,9 @@ class BatchIntegrity(BaseModel):
|
|||||||
id_: uuid.UUID
|
id_: uuid.UUID
|
||||||
product: str
|
product: str
|
||||||
date_: date
|
date_: date
|
||||||
price: Decimal
|
price: Daf
|
||||||
showing: Decimal
|
showing: Daf
|
||||||
actual: Decimal
|
actual: Daf
|
||||||
details: list[BatchIntegrityItem]
|
details: list[BatchIntegrityItem]
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,13 +8,13 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class CashFlowItem(BaseModel):
|
class CashFlowItem(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
url: list[str] | None = None
|
url: list[str] | None = None
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .cost_centre import CostCentreLink
|
from .cost_centre import CostCentreLink
|
||||||
from .product import ProductLink
|
from .product import ProductLink
|
||||||
from .user_link import UserLink
|
from .user_link import UserLink
|
||||||
@@ -21,29 +21,29 @@ class ClosingStockItem(BaseModel):
|
|||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
product: ProductLink
|
product: ProductLink
|
||||||
group: str
|
group: str
|
||||||
quantity: Decimal
|
quantity: Daf
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
physical: Decimal
|
physical: Daf
|
||||||
cost_centre: CostCentreLink | None = None
|
cost_centre: CostCentreLink | None = None
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
@field_validator("quantity", mode="before")
|
@field_validator("quantity", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_quantity(cls, value: Decimal | float) -> Decimal:
|
def parse_quantity(cls, value: Daf | float) -> Daf:
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
return Decimal(round(value, 2))
|
return Decimal(round(value, 2))
|
||||||
return round(value, 2)
|
return round(value, 2)
|
||||||
|
|
||||||
@field_validator("amount", mode="before")
|
@field_validator("amount", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_amount(cls, value: Decimal | float) -> Decimal:
|
def parse_amount(cls, value: Daf | float) -> Daf:
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
return Decimal(round(value, 2))
|
return Decimal(round(value, 2))
|
||||||
return round(value, 2)
|
return round(value, 2)
|
||||||
|
|
||||||
@field_validator("physical", mode="before")
|
@field_validator("physical", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
def parse_physical(cls, value: Decimal | float) -> Decimal:
|
def parse_physical(cls, value: Daf | float) -> Daf:
|
||||||
if isinstance(value, float):
|
if isinstance(value, float):
|
||||||
return Decimal(round(value, 2))
|
return Decimal(round(value, 2))
|
||||||
return round(value, 2)
|
return round(value, 2)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class DaybookItem(BaseModel):
|
class DaybookItem(BaseModel):
|
||||||
@@ -21,9 +20,9 @@ class DaybookItem(BaseModel):
|
|||||||
type_: str
|
type_: str
|
||||||
narration: str
|
narration: str
|
||||||
debit_text: str | None = None
|
debit_text: str | None = None
|
||||||
debit_amount: Decimal | None = None
|
debit_amount: Daf | None = None
|
||||||
credit_text: str | None = None
|
credit_text: str | None = None
|
||||||
credit_amount: Decimal | None = None
|
credit_amount: Daf | None = None
|
||||||
posted: bool
|
posted: bool
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -13,7 +12,7 @@ from pydantic import (
|
|||||||
model_validator,
|
model_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .account import AccountBase
|
from .account import AccountBase
|
||||||
from .cost_centre import CostCentreLink
|
from .cost_centre import CostCentreLink
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ from .cost_centre import CostCentreLink
|
|||||||
class EmployeeIn(AccountBase):
|
class EmployeeIn(AccountBase):
|
||||||
designation: str
|
designation: str
|
||||||
salary: int = Field(ge=0)
|
salary: int = Field(ge=0)
|
||||||
points: Decimal = Field(ge=0, lt=1000)
|
points: Daf = Field(ge=0, lt=1000)
|
||||||
joining_date: date
|
joining_date: date
|
||||||
leaving_date: date | None = None
|
leaving_date: date | None = None
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .user_link import UserLink
|
from .user_link import UserLink
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +23,7 @@ class Entries(BaseModel):
|
|||||||
narration: str
|
narration: str
|
||||||
debit_names: list[str]
|
debit_names: list[str]
|
||||||
credit_names: list[str]
|
credit_names: list[str]
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
creation_date: datetime
|
creation_date: datetime
|
||||||
last_edit_date: datetime
|
last_edit_date: datetime
|
||||||
user: UserLink
|
user: UserLink
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class Incentive(BaseModel):
|
class Incentive(BaseModel):
|
||||||
employee_id: uuid.UUID
|
employee_id: uuid.UUID
|
||||||
name: str
|
name: str
|
||||||
designation: str
|
designation: str
|
||||||
department: str
|
department: str
|
||||||
days_worked: Decimal = Field(ge=0)
|
days_worked: Daf = Field(ge=0)
|
||||||
points: Decimal = Field(ge=0)
|
points: Daf = Field(ge=0)
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .account import AccountLink
|
from .account import AccountLink
|
||||||
from .cost_centre import CostCentreLink
|
from .cost_centre import CostCentreLink
|
||||||
from .employee_benefit import EmployeeBenefit
|
from .employee_benefit import EmployeeBenefit
|
||||||
@@ -109,5 +108,5 @@ class IncentiveEmployee(BaseModel):
|
|||||||
employee_id: uuid.UUID
|
employee_id: uuid.UUID
|
||||||
cost_centre_id: uuid.UUID
|
cost_centre_id: uuid.UUID
|
||||||
journal: Journal | None = None
|
journal: Journal | None = None
|
||||||
days_worked: Decimal = Field(ge=0)
|
days_worked: Daf = Field(ge=0)
|
||||||
points: Decimal = Field(ge=0)
|
points: Daf = Field(ge=0)
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.batch import Batch
|
from brewman.schemas.batch import Batch
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class Inventory(BaseModel):
|
class Inventory(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
batch: Batch
|
batch: Batch
|
||||||
quantity: Decimal = Field(ge=0)
|
quantity: Daf = Field(ge=0)
|
||||||
rate: Decimal = Field(ge=0)
|
rate: Daf = Field(ge=0)
|
||||||
tax: Decimal = Field(ge=0, le=5)
|
tax: Daf = Field(ge=0, le=5)
|
||||||
discount: Decimal = Field(ge=0, le=1)
|
discount: Daf = Field(ge=0, le=1)
|
||||||
amount: Decimal | None = None
|
amount: Daf | None = None
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class IssueGridItem(BaseModel):
|
class IssueGridItem(BaseModel):
|
||||||
id_: uuid.UUID
|
id_: uuid.UUID
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
source: str
|
source: str
|
||||||
destination: str
|
destination: str
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.account import AccountLink
|
from brewman.schemas.account import AccountLink
|
||||||
from brewman.schemas.cost_centre import CostCentreLink
|
from brewman.schemas.cost_centre import CostCentreLink
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class Journal(BaseModel):
|
class Journal(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
debit: int = Field(ge=-1, le=1)
|
debit: int = Field(ge=-1, le=1)
|
||||||
amount: Decimal = Field(ge=0)
|
amount: Daf = Field(ge=0)
|
||||||
account: AccountLink
|
account: AccountLink
|
||||||
cost_centre: CostCentreLink | None = None
|
cost_centre: CostCentreLink | None = None
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .account import AccountLink
|
from .account import AccountLink
|
||||||
|
|
||||||
|
|
||||||
@@ -22,8 +21,8 @@ class LedgerItem(BaseModel):
|
|||||||
url: list[str]
|
url: list[str]
|
||||||
type_: str
|
type_: str
|
||||||
narration: str
|
narration: str
|
||||||
debit: Decimal
|
debit: Daf
|
||||||
credit: Decimal
|
credit: Daf
|
||||||
posted: bool
|
posted: bool
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,14 +8,14 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class NetTransactionsItem(BaseModel):
|
class NetTransactionsItem(BaseModel):
|
||||||
type_: str
|
type_: str
|
||||||
name: str
|
name: str
|
||||||
debit: Decimal | None = None
|
debit: Daf | None = None
|
||||||
credit: Decimal | None = None
|
credit: Daf | None = None
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,7 +8,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class NonContractPurchase(BaseModel):
|
class NonContractPurchase(BaseModel):
|
||||||
@@ -17,8 +16,8 @@ class NonContractPurchase(BaseModel):
|
|||||||
vendor: str
|
vendor: str
|
||||||
product: str
|
product: str
|
||||||
url: list[str]
|
url: list[str]
|
||||||
contract_price: Decimal
|
contract_price: Daf
|
||||||
purchase_price: Decimal
|
purchase_price: Daf
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
@field_validator("date_", mode="before")
|
@field_validator("date_", mode="before")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .product import ProductLink
|
from .product import ProductLink
|
||||||
|
|
||||||
|
|
||||||
@@ -22,14 +21,14 @@ class ProductLedgerItem(BaseModel):
|
|||||||
url: list[str]
|
url: list[str]
|
||||||
type_: str
|
type_: str
|
||||||
narration: str
|
narration: str
|
||||||
debit_quantity: Decimal | None = None
|
debit_quantity: Daf | None = None
|
||||||
debit_amount: Decimal | None = None
|
debit_amount: Daf | None = None
|
||||||
debit_unit: str | None = None
|
debit_unit: str | None = None
|
||||||
credit_quantity: Decimal | None = None
|
credit_quantity: Daf | None = None
|
||||||
credit_amount: Decimal | None = None
|
credit_amount: Daf | None = None
|
||||||
credit_unit: str | None = None
|
credit_unit: str | None = None
|
||||||
running_quantity: Decimal
|
running_quantity: Daf
|
||||||
running_amount: Decimal
|
running_amount: Daf
|
||||||
posted: bool
|
posted: bool
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class ProductSku(BaseModel):
|
class ProductSku(BaseModel):
|
||||||
id_: uuid.UUID = Field(...)
|
id_: uuid.UUID = Field(...)
|
||||||
name: str
|
name: str
|
||||||
fraction_units: str
|
fraction_units: str
|
||||||
cost_price: Decimal
|
cost_price: Daf
|
||||||
sale_price: Decimal
|
sale_price: Daf
|
||||||
is_rate_contracted: bool
|
is_rate_contracted: bool
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,14 +8,14 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class ProfitLossItem(BaseModel):
|
class ProfitLossItem(BaseModel):
|
||||||
group: str | None = None
|
group: str | None = None
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
amount: Decimal | None = None
|
amount: Daf | None = None
|
||||||
total: Decimal | None = None
|
total: Daf | None = None
|
||||||
order: int
|
order: int
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,7 +8,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class PurchaseEntriesItem(BaseModel):
|
class PurchaseEntriesItem(BaseModel):
|
||||||
@@ -17,11 +16,11 @@ class PurchaseEntriesItem(BaseModel):
|
|||||||
url: list[str]
|
url: list[str]
|
||||||
supplier: str
|
supplier: str
|
||||||
product: str
|
product: str
|
||||||
quantity: Decimal
|
quantity: Daf
|
||||||
rate: Decimal
|
rate: Daf
|
||||||
tax: Decimal
|
tax: Daf
|
||||||
discount: Decimal
|
discount: Daf
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
|
|
||||||
@field_validator("date_", mode="before")
|
@field_validator("date_", mode="before")
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,14 +8,14 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class PurchasesItem(BaseModel):
|
class PurchasesItem(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
quantity: Decimal
|
quantity: Daf
|
||||||
rate: Decimal
|
rate: Daf
|
||||||
amount: Decimal
|
amount: Daf
|
||||||
url: list[str]
|
url: list[str]
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.product import ProductLink
|
from brewman.schemas.product import ProductLink
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class RateContractItem(BaseModel):
|
class RateContractItem(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
sku: ProductLink
|
sku: ProductLink
|
||||||
price: Decimal = Field(ge=0)
|
price: Daf = Field(ge=0)
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,20 +10,20 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class RawMaterialCostItem(BaseModel):
|
class RawMaterialCostItem(BaseModel):
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
issue: Decimal | None = None
|
issue: Daf | None = None
|
||||||
sale: Decimal | None = None
|
sale: Daf | None = None
|
||||||
rmc: Decimal | None = None
|
rmc: Daf | None = None
|
||||||
url: list[str] | None = None
|
url: list[str] | None = None
|
||||||
|
|
||||||
group: str | None = None
|
group: str | None = None
|
||||||
quantity: Decimal | None = None
|
quantity: Daf | None = None
|
||||||
net: Decimal | None = None
|
net: Daf | None = None
|
||||||
gross: Decimal | None = None
|
gross: Daf | None = None
|
||||||
order: int
|
order: int
|
||||||
|
|
||||||
heading: bool | None = None
|
heading: bool | None = None
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .product import ProductLink
|
from .product import ProductLink
|
||||||
from .recipe_item import RecipeItem
|
from .recipe_item import RecipeItem
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ class RecipeIn(BaseModel):
|
|||||||
instructions: str
|
instructions: str
|
||||||
garnishing: str
|
garnishing: str
|
||||||
plating: str
|
plating: str
|
||||||
recipe_yield: Decimal
|
recipe_yield: Daf
|
||||||
notes: str
|
notes: str
|
||||||
|
|
||||||
items: list[RecipeItem]
|
items: list[RecipeItem]
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from brewman.schemas import to_camel
|
from brewman.schemas import to_camel
|
||||||
from brewman.schemas.product import ProductLink
|
from brewman.schemas.product import ProductLink
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
from . import Daf
|
||||||
|
|
||||||
|
|
||||||
class RecipeItem(BaseModel):
|
class RecipeItem(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
product: ProductLink
|
product: ProductLink
|
||||||
quantity: Decimal
|
quantity: Daf
|
||||||
description: str
|
description: str
|
||||||
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,7 +10,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .account import AccountLink
|
from .account import AccountLink
|
||||||
|
|
||||||
|
|
||||||
@@ -22,8 +21,8 @@ class ReconcileItem(BaseModel):
|
|||||||
url: list[str]
|
url: list[str]
|
||||||
type_: str
|
type_: str
|
||||||
narration: str
|
narration: str
|
||||||
debit: Decimal
|
debit: Daf
|
||||||
credit: Decimal
|
credit: Daf
|
||||||
posted: bool
|
posted: bool
|
||||||
is_reconciled: bool
|
is_reconciled: bool
|
||||||
reconcile_date: date | None = None
|
reconcile_date: date | None = None
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict, Field
|
from pydantic import BaseModel, ConfigDict, Field
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class StockKeepingUnit(BaseModel):
|
class StockKeepingUnit(BaseModel):
|
||||||
id_: uuid.UUID | None = None
|
id_: uuid.UUID | None = None
|
||||||
units: str = Field(..., min_length=1)
|
units: str = Field(..., min_length=1)
|
||||||
fraction: Decimal = Field(ge=1, default=1)
|
fraction: Daf = Field(ge=1, default=1)
|
||||||
product_yield: Decimal = Field(gt=0, le=1, default=1)
|
product_yield: Daf = Field(gt=0, le=1, default=1)
|
||||||
cost_price: Decimal = Field(ge=0, default=0)
|
cost_price: Daf = Field(ge=0, default=0)
|
||||||
sale_price: Decimal = Field(ge=0, default=0)
|
sale_price: Daf = Field(ge=0, default=0)
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -11,17 +10,17 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class StockMovementItem(BaseModel):
|
class StockMovementItem(BaseModel):
|
||||||
id_: uuid.UUID
|
id_: uuid.UUID
|
||||||
group: str
|
group: str
|
||||||
name: str
|
name: str
|
||||||
opening: Decimal
|
opening: Daf
|
||||||
purchase: Decimal
|
purchase: Daf
|
||||||
issue: Decimal
|
issue: Daf
|
||||||
closing: Decimal
|
closing: Daf
|
||||||
url: list[str]
|
url: list[str]
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
BaseModel,
|
BaseModel,
|
||||||
@@ -9,14 +8,14 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
|
|
||||||
|
|
||||||
class TrialBalanceItem(BaseModel):
|
class TrialBalanceItem(BaseModel):
|
||||||
type_: str | None = None
|
type_: str | None = None
|
||||||
name: str | None = None
|
name: str | None = None
|
||||||
debit: Decimal | None = None
|
debit: Daf | None = None
|
||||||
credit: Decimal | None = None
|
credit: Daf | None = None
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
from decimal import Decimal
|
|
||||||
|
|
||||||
from fastapi import Form
|
from fastapi import Form
|
||||||
from pydantic import (
|
from pydantic import (
|
||||||
@@ -13,7 +12,7 @@ from pydantic import (
|
|||||||
field_validator,
|
field_validator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import to_camel
|
from . import Daf, to_camel
|
||||||
from .account import AccountLink
|
from .account import AccountLink
|
||||||
from .batch import Batch # noqa: F401
|
from .batch import Batch # noqa: F401
|
||||||
from .cost_centre import CostCentreLink
|
from .cost_centre import CostCentreLink
|
||||||
@@ -66,7 +65,7 @@ class Voucher(VoucherIn):
|
|||||||
source: CostCentreLink | None = None
|
source: CostCentreLink | None = None
|
||||||
destination: CostCentreLink | None = None
|
destination: CostCentreLink | None = None
|
||||||
incentives: list[Incentive]
|
incentives: list[Incentive]
|
||||||
incentive: Decimal | None = None
|
incentive: Daf | None = None
|
||||||
employee_benefits: list[EmployeeBenefit]
|
employee_benefits: list[EmployeeBenefit]
|
||||||
files: list[ImageUpload]
|
files: list[ImageUpload]
|
||||||
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
model_config = ConfigDict(str_strip_whitespace=True, alias_generator=to_camel, populate_by_name=True)
|
||||||
|
|||||||
@@ -193,10 +193,10 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
|
|||||||
this.voucher.inventories.push(
|
this.voucher.inventories.push(
|
||||||
new Inventory({
|
new Inventory({
|
||||||
quantity,
|
quantity,
|
||||||
rate: +this.batch.rate,
|
rate: this.batch.rate,
|
||||||
tax: +this.batch.tax,
|
tax: this.batch.tax,
|
||||||
discount: +this.batch.discount,
|
discount: this.batch.discount,
|
||||||
amount: quantity * +this.batch.rate * (1 + +this.batch.tax) * (1 - +this.batch.discount),
|
amount: quantity * this.batch.rate * (1 + this.batch.tax) * (1 - this.batch.discount),
|
||||||
batch: this.batch,
|
batch: this.batch,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -95,13 +95,13 @@ export class LedgerComponent implements OnInit, AfterViewInit {
|
|||||||
this.running = 0;
|
this.running = 0;
|
||||||
this.info.body.forEach((item) => {
|
this.info.body.forEach((item) => {
|
||||||
if (item.type !== 'Opening Balance') {
|
if (item.type !== 'Opening Balance') {
|
||||||
this.debit += +item.debit;
|
this.debit += item.debit;
|
||||||
this.credit += +item.credit;
|
this.credit += item.credit;
|
||||||
if (item.posted) {
|
if (item.posted) {
|
||||||
this.running += +item.debit - +item.credit;
|
this.running += item.debit - item.credit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.running += +item.debit - +item.credit;
|
this.running += item.debit - item.credit;
|
||||||
}
|
}
|
||||||
item.running = this.running;
|
item.running = this.running;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user