Fix: Rounding being done manually to prevent floating point errors
This commit is contained in:
parent
80a8de5fea
commit
4685fa2528
brewman
@ -33,13 +33,13 @@ def save(
|
||||
item = Product(
|
||||
name=data.name,
|
||||
units=data.units,
|
||||
fraction=data.fraction,
|
||||
fraction=round(data.fraction, 5),
|
||||
fraction_units=data.fraction_units,
|
||||
product_yield=data.product_yield,
|
||||
product_yield=round(data.product_yield, 5),
|
||||
product_group_id=data.product_group.id_,
|
||||
account_id=Account.all_purchases(),
|
||||
price=data.price,
|
||||
sale_price=data.sale_price,
|
||||
price=round(data.price, 2),
|
||||
sale_price=round(data.sale_price, 2),
|
||||
is_active=data.is_active,
|
||||
is_purchased=data.is_purchased,
|
||||
is_sold=data.is_sold,
|
||||
@ -71,13 +71,13 @@ def update(
|
||||
)
|
||||
item.name = data.name
|
||||
item.units = data.units
|
||||
item.fraction = data.fraction
|
||||
item.fraction = round(data.fraction, 5)
|
||||
item.fraction_units = data.fraction_units
|
||||
item.product_yield = data.product_yield
|
||||
item.product_yield = round(data.product_yield, 5)
|
||||
item.product_group_id = data.product_group.id_
|
||||
item.account_id = Account.all_purchases()
|
||||
item.price = data.price
|
||||
item.sale_price = data.sale_price
|
||||
item.price = round(data.price, 2)
|
||||
item.sale_price = round(data.sale_price, 2)
|
||||
item.is_active = data.is_active
|
||||
item.is_purchased = data.is_purchased
|
||||
item.is_sold = data.is_sold
|
||||
|
@ -66,9 +66,9 @@ class ProductLink(BaseModel):
|
||||
class ProductIn(BaseModel):
|
||||
name: str = Field(..., min_length=1)
|
||||
units: str
|
||||
fraction: Decimal = Field(ge=0, multiple_of=0.00001, default=0)
|
||||
fraction: Decimal = Field(ge=1, default=1)
|
||||
fraction_units: str
|
||||
product_yield: Decimal = Field(ge=0, le=1, multiple_of=0.00001, default=1)
|
||||
product_yield: Decimal = Field(gt=0, le=1, default=1)
|
||||
product_group: ProductGroupLink = Field(...)
|
||||
price: Decimal = Field(ge=0, multiple_of=0.01, default=0)
|
||||
sale_price: Decimal = Field(ge=0, multiple_of=0.01, default=0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user