diff --git a/shopinvader_api_cart/schemas/amount.py b/shopinvader_api_cart/schemas/amount.py index e47d74a9a0..6a964d527b 100644 --- a/shopinvader_api_cart/schemas/amount.py +++ b/shopinvader_api_cart/schemas/amount.py @@ -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