From 3b55bd476b54dbaeb65f441857f91b740a04624e Mon Sep 17 00:00:00 2001 From: mle Date: Wed, 26 Jul 2023 08:18:51 +0200 Subject: [PATCH] Migration to Pydantic v2 --- requirements.txt | 4 +-- shopinvader_api_address/__manifest__.py | 4 ++- shopinvader_api_address/schemas.py | 40 +++++++++++----------- shopinvader_schema_address/__manifest__.py | 4 ++- shopinvader_schema_address/schemas.py | 29 +++++++--------- 5 files changed, 40 insertions(+), 41 deletions(-) diff --git a/requirements.txt b/requirements.txt index 893abd9d60..a0f722a6d1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # generated from manifests external_dependencies -extendable_pydantic +extendable_pydantic>=1.0.0 fastapi openupgradelib -pydantic +pydantic>=2.0.0 diff --git a/shopinvader_api_address/__manifest__.py b/shopinvader_api_address/__manifest__.py index 6d0ebf2da8..47c5fee51a 100644 --- a/shopinvader_api_address/__manifest__.py +++ b/shopinvader_api_address/__manifest__.py @@ -20,6 +20,8 @@ "security/res_groups.xml", "security/res_partner.xml", ], - "external_dependencies": {"python": ["fastapi", "extendable_pydantic", "pydantic"]}, + "external_dependencies": { + "python": ["fastapi", "extendable_pydantic>=1.0.0", "pydantic>=2.0.0"] + }, "installable": True, } diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py index c70ed751ec..7d08c22a69 100644 --- a/shopinvader_api_address/schemas.py +++ b/shopinvader_api_address/schemas.py @@ -11,15 +11,15 @@ class AddressCreate(BaseModel, metaclass=ExtendableModelMeta): state and country can be name or code """ - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + email: str | None = None + state_id: int | None = None + country_id: int | None = None def to_res_partner_vals(self) -> dict: vals = { @@ -43,15 +43,15 @@ class AddressUpdate(BaseModel, metaclass=ExtendableModelMeta): state and country can be name or code """ - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + email: str | None = None + state_id: int | None = None + country_id: int | None = None def to_res_partner_vals(self) -> dict: vals = { @@ -79,7 +79,7 @@ class BillingAddressCreate(AddressUpdate): partner's address """ - vat: str | None + vat: str | None = None def to_res_partner_vals(self) -> dict: vals = super().to_res_partner_vals() @@ -94,7 +94,7 @@ class BillingAddressUpdate(AddressUpdate): Update of Billing Address """ - vat: str | None + vat: str | None = None def to_res_partner_vals(self) -> dict: vals = super().to_res_partner_vals() diff --git a/shopinvader_schema_address/__manifest__.py b/shopinvader_schema_address/__manifest__.py index 36203a772b..a46dfe2639 100644 --- a/shopinvader_schema_address/__manifest__.py +++ b/shopinvader_schema_address/__manifest__.py @@ -14,7 +14,9 @@ "extendable", "extendable_fastapi", ], - "external_dependencies": {"python": ["extendable_pydantic", "pydantic"]}, + "external_dependencies": { + "python": ["extendable_pydantic>=1.0.0", "pydantic>=2.0.0"] + }, "data": [], "demo": [], "installable": True, diff --git a/shopinvader_schema_address/schemas.py b/shopinvader_schema_address/schemas.py index e3c5def77b..f5fe51d90c 100644 --- a/shopinvader_schema_address/schemas.py +++ b/shopinvader_schema_address/schemas.py @@ -2,26 +2,21 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from extendable_pydantic import ExtendableModelMeta -from pydantic import BaseModel - -from odoo.addons.pydantic import utils +from pydantic import BaseModel, ConfigDict class Address(BaseModel, metaclass=ExtendableModelMeta): id: int - name: str | None - street: str | None - street2: str | None - zip: str | None - city: str | None - phone: str | None - email: str | None - state_id: int | None - country_id: int | None - - class Config: - orm_mode = True - getter_dict = utils.GenericOdooGetter + name: str | None = None + street: str | None = None + street2: str | None = None + zip: str | None = None + city: str | None = None + phone: str | None = None + 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): @@ -44,7 +39,7 @@ class BillingAddress(Address): Billing Address """ - vat: str | None + vat: str | None = None @classmethod def from_res_partner(cls, odoo_rec):