Skip to content

Commit

Permalink
[WIP][FIX] instantiating inherited class SaleLineAmount
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Jul 31, 2023
1 parent b20a334 commit 04aac45
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions shopinvader_api_cart/schemas/amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,25 @@ def from_sale_order(cls, sale_order):
)

@classmethod
def from_sale_order_line(cls, order_line):
def from_sale_order_line(cls, order_line, **kwargs):
precision = order_line.order_id.currency_id.decimal_places
res = cls.model_construct()
res.discount_total = float_round(order_line.discount_total, precision)
res.total_without_discount = float_round(
order_line.price_total_no_discount, precision
return cls(
discount_total=float_round(order_line.discount_total, precision),
total_without_discount=float_round(
order_line.price_total_no_discount, precision
),
tax=float_round(order_line.price_tax, precision),
untaxed=float_round(order_line.price_subtotal, precision),
total=float_round(order_line.price_total, precision),
**kwargs
)
res.tax = float_round(order_line.price_tax, precision)
res.untaxed = float_round(order_line.price_subtotal, precision)
res.total = float_round(order_line.price_total, precision)
return res
# FIXME: cannot use cls(...) when Pydantic model is extended.
# return cls(
# discount_total=float_round(order_line.discount_total, precision),
# total_without_discount=float_round(
# order_line.price_total_no_discount, precision
# ),
# tax=float_round(order_line.price_tax, precision),
# untaxed=float_round(order_line.price_subtotal, precision),
# total=float_round(order_line.price_total, precision),
# )


class SaleLineAmount(SaleAmount):
price: float = Field(description="Unit price")

@classmethod
def from_sale_order_line(cls, order_line):
res = super().from_sale_order_line(order_line)
res.price = order_line.price_unit
def from_sale_order_line(cls, order_line, **kwargs):
kwargs["price"] = order_line.price_unit
res = super().from_sale_order_line(order_line, **kwargs)
return res

0 comments on commit 04aac45

Please sign in to comment.