From 1535c16263cf7dbbe7290d03efc4e0ed17d2a1c7 Mon Sep 17 00:00:00 2001 From: mle Date: Mon, 31 Jul 2023 11:25:35 +0200 Subject: [PATCH] [IMP] Use StrictExtendableBaseModel in schemas --- requirements.txt | 3 ++- shopinvader_api_cart/__manifest__.py | 2 +- shopinvader_api_cart/schemas/amount.py | 7 ++++--- shopinvader_api_cart/schemas/cart.py | 10 ++++------ shopinvader_api_cart/schemas/sale_order_line.py | 5 ++--- test-requirements.txt | 7 +------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8240b571eb..f85f6a5823 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ # generated from manifests external_dependencies -extendable-pydantic>=1.0.0 +extendable-pydantic>=1.1.0 +extendable_pydantic>=1.0.0 fastapi openupgradelib pydantic>=2.0.0 diff --git a/shopinvader_api_cart/__manifest__.py b/shopinvader_api_cart/__manifest__.py index 7e12c3e8ef..6b1c7f3a80 100644 --- a/shopinvader_api_cart/__manifest__.py +++ b/shopinvader_api_cart/__manifest__.py @@ -36,7 +36,7 @@ "python": [ "fastapi", "pydantic>=2.0.0", - "extendable-pydantic>=1.0.0", + "extendable-pydantic>=1.1.0", ] }, "pre_init_hook": "pre_init_hook", diff --git a/shopinvader_api_cart/schemas/amount.py b/shopinvader_api_cart/schemas/amount.py index e402eb2ec6..5b65e543df 100644 --- a/shopinvader_api_cart/schemas/amount.py +++ b/shopinvader_api_cart/schemas/amount.py @@ -1,13 +1,14 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel, Field +from pydantic import Field from odoo.tools.float_utils import float_round +from odoo.addons.extendable_fastapi import StrictExtendableModelMeta -class SaleAmount(BaseModel, metaclass=ExtendableModelMeta): + +class SaleAmount(StrictExtendableModelMeta): tax: float = Field(description="Tax amount") untaxed: float = Field(description="Amount untaxed") total: float = Field(description="Total amount") diff --git a/shopinvader_api_cart/schemas/cart.py b/shopinvader_api_cart/schemas/cart.py index 303b3d8ae8..43e86bb8fb 100644 --- a/shopinvader_api_cart/schemas/cart.py +++ b/shopinvader_api_cart/schemas/cart.py @@ -4,9 +4,7 @@ from datetime import datetime from typing import List -from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel - +from odoo.addons.extendable_fastapi import StrictExtendableBaseModel from odoo.addons.shopinvader_schema_address.schemas import ( BillingAddress, ShippingAddress, @@ -16,17 +14,17 @@ from .sale_order_line import SaleOrderLine -class CartTransaction(BaseModel, metaclass=ExtendableModelMeta): +class CartTransaction(StrictExtendableBaseModel): uuid: str | None = None qty: float product_id: int -class CartSyncInput(BaseModel, metaclass=ExtendableModelMeta): +class CartSyncInput(StrictExtendableBaseModel): transactions: List[CartTransaction] -class CartResponse(BaseModel, metaclass=ExtendableModelMeta): +class CartResponse(StrictExtendableBaseModel): uuid: str | None = None id: int state: str diff --git a/shopinvader_api_cart/schemas/sale_order_line.py b/shopinvader_api_cart/schemas/sale_order_line.py index c0a1be98fb..3c0bb9b229 100644 --- a/shopinvader_api_cart/schemas/sale_order_line.py +++ b/shopinvader_api_cart/schemas/sale_order_line.py @@ -1,13 +1,12 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel +from odoo.addons.extendable_fastapi import StrictExtendableBaseModel from .amount import SaleLineAmount -class SaleOrderLine(BaseModel, metaclass=ExtendableModelMeta): +class SaleOrderLine(StrictExtendableBaseModel): id: int product_id: int name: str diff --git a/test-requirements.txt b/test-requirements.txt index 73957b9ef8..bac16ac1ac 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,9 +8,4 @@ vcrpy-unittest unittest2 # For shopinvader test_controller, which inherits component odoo-test-helper httpx # For FastAPI tests -odoo-addon-shopinvader-schema-address @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1361/head#subdirectory=setup/shopinvader_schema_address -odoo-addon-shopinvader-api-address @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1361/head#subdirectory=setup/shopinvader_api_address -odoo-addon-shopinvader-address @ git+https://github.com/shopinvader/odoo-shopinvader@refs/pull/1361/head#subdirectory=setup/shopinvader_address -odoo-addon-extendable @ git+https://github.com/oca/rest-framework@refs/pull/348/head#subdirectory=setup/extendable -odoo-addon-fastapi @ git+https://github.com/oca/rest-framework@refs/pull/348/head#subdirectory=setup/fastapi -odoo-addon-extendable-fastapi @ git+https://github.com/oca/rest-framework@refs/pull/348/head#subdirectory=setup/extendable_fastapi +odoo-addon-extendable-fastapi @ git+https://github.com/oca/rest-framework@refs/pull/364/head#subdirectory=setup/extendable_fastapi