Skip to content

Commit

Permalink
Migration to Pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Jul 26, 2023
1 parent 0bef327 commit 3b55bd4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# generated from manifests external_dependencies
extendable_pydantic
extendable_pydantic>=1.0.0
fastapi
openupgradelib
pydantic
pydantic>=2.0.0
4 changes: 3 additions & 1 deletion shopinvader_api_address/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
40 changes: 20 additions & 20 deletions shopinvader_api_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion shopinvader_schema_address/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 12 additions & 17 deletions shopinvader_schema_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -44,7 +39,7 @@ class BillingAddress(Address):
Billing Address
"""

vat: str | None
vat: str | None = None

@classmethod
def from_res_partner(cls, odoo_rec):
Expand Down

0 comments on commit 3b55bd4

Please sign in to comment.