Skip to content

Commit

Permalink
[IMP] address schemas inherit from StrictExtendableBaseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
marielejeune committed Jul 31, 2023
1 parent b9da4d8 commit 63c5545
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions shopinvader_api_address/schemas.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions shopinvader_api_address/tests/test_shopinvader_address_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_schema_address/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
8 changes: 3 additions & 5 deletions shopinvader_schema_address/schemas.py
Original file line number Diff line number Diff line change
@@ -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, from_attributes=True):
id: int
name: str | None = None
street: str | None = None
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 63c5545

Please sign in to comment.