From 8fccaf1656c19442f17ddf05eec74642ab9d9fee Mon Sep 17 00:00:00 2001 From: mle Date: Mon, 31 Jul 2023 09:25:37 +0200 Subject: [PATCH] [IMP] address schemas inherit from StrictExtendableBaseModel --- requirements.txt | 1 + shopinvader_api_address/schemas.py | 7 +++---- .../tests/test_shopinvader_address_api.py | 5 +++-- shopinvader_schema_address/__manifest__.py | 2 +- shopinvader_schema_address/schemas.py | 8 +++----- test-requirements.txt | 1 + 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/requirements.txt b/requirements.txt index a0f722a6d1..f450b38b75 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 fastapi openupgradelib pydantic>=2.0.0 diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py index 7d08c22a69..3e6acc2c67 100644 --- a/shopinvader_api_address/schemas.py +++ b/shopinvader_api_address/schemas.py @@ -1,11 +1,10 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel +from odoo.addons.extendable_fastapi import StrictExtendableBaseModel -class AddressCreate(BaseModel, metaclass=ExtendableModelMeta): +class AddressCreate(StrictExtendableBaseModel): """ used to create new address (res.partner) state and country can be name or code @@ -37,7 +36,7 @@ def to_res_partner_vals(self) -> dict: return vals -class AddressUpdate(BaseModel, metaclass=ExtendableModelMeta): +class AddressUpdate(StrictExtendableBaseModel): """ used to update address (res.partner) state and country can be name or code diff --git a/shopinvader_api_address/tests/test_shopinvader_address_api.py b/shopinvader_api_address/tests/test_shopinvader_address_api.py index b898366e38..4df5841643 100644 --- a/shopinvader_api_address/tests/test_shopinvader_address_api.py +++ b/shopinvader_api_address/tests/test_shopinvader_address_api.py @@ -267,6 +267,9 @@ def test_create_shipping_address(self): self.assertEqual(address.get("street"), "test Street") self.assertNotEqual(address.get("street"), self.test_partner.street) + address_odoo = self.env["res.partner"].browse(address.get("id")) + self.assertEqual(address_odoo.type, "delivery") + def test_delete_shipping_address(self): """ Test to delete shipping address @@ -318,8 +321,6 @@ def test_update_shipping_address(self): "zip": "5000", "city": "Namur", "country_id": self.env.ref("base.be").id, - "parent_id": self.test_partner.id, - "type": "delivery", } with self._create_test_client(router=address_router) as test_client: diff --git a/shopinvader_schema_address/__manifest__.py b/shopinvader_schema_address/__manifest__.py index a46dfe2639..6bf114f4e8 100644 --- a/shopinvader_schema_address/__manifest__.py +++ b/shopinvader_schema_address/__manifest__.py @@ -15,7 +15,7 @@ "extendable_fastapi", ], "external_dependencies": { - "python": ["extendable_pydantic>=1.0.0", "pydantic>=2.0.0"] + "python": ["extendable_pydantic>=1.1.0", "pydantic>=2.0.0"] }, "data": [], "demo": [], diff --git a/shopinvader_schema_address/schemas.py b/shopinvader_schema_address/schemas.py index f5fe51d90c..c6d4bee328 100644 --- a/shopinvader_schema_address/schemas.py +++ b/shopinvader_schema_address/schemas.py @@ -1,11 +1,10 @@ # Copyright 2023 ACSONE SA/NV # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel, ConfigDict +from odoo.addons.extendable_fastapi import StrictExtendableBaseModel -class Address(BaseModel, metaclass=ExtendableModelMeta): +class Address(StrictExtendableBaseModel): id: int name: str | None = None street: str | None = None @@ -16,11 +15,10 @@ class Address(BaseModel, metaclass=ExtendableModelMeta): email: str | None = None state_id: int | None = None country_id: int | None = None - model_config: ConfigDict = ConfigDict(from_attributes=True) @classmethod def from_res_partner(cls, odoo_rec): - return cls( + return cls.model_construct( id=odoo_rec.id, name=odoo_rec.name or None, street=odoo_rec.street or None, diff --git a/test-requirements.txt b/test-requirements.txt index 268eb05ad2..7418a5f31d 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -8,3 +8,4 @@ vcrpy-unittest unittest2 # For shopinvader test_controller, which inherits component odoo-test-helper httpx # For FastAPI tests +odoo-addon-extendable-fastapi @ git+https://github.com/OCA/rest-framework@refs/pull/364/head#subdirectory=setup/extendable_fastapi