Skip to content

Commit

Permalink
[16.0][IMP] Add partner title in address api schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
bguillot committed Dec 12, 2024
1 parent e1b0f79 commit f03e721
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion shopinvader_api_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AddressCreate(StrictExtendableBaseModel, extra="ignore"):
email: str | None = None
state_id: int | None = None
country_id: int | None = None
title_id: int | None = None

def to_res_partner_vals(self) -> dict:
vals = {
Expand All @@ -33,6 +34,7 @@ def to_res_partner_vals(self) -> dict:
"email": self.email,
"state_id": self.state_id,
"country_id": self.country_id,
"title": self.title_id,
}

return vals
Expand All @@ -54,6 +56,7 @@ class AddressUpdate(StrictExtendableBaseModel, extra="ignore"):
email: str | None = None
state_id: int | None = None
country_id: int | None = None
title_id: int | None = None

def to_res_partner_vals(self) -> dict:
fields = [
Expand All @@ -69,7 +72,10 @@ def to_res_partner_vals(self) -> dict:
"country_id",
]
values = self.model_dump(exclude_unset=True)
return {f: values[f] for f in fields if f in values}
result = {f: values[f] for f in fields if f in values}
if "title_id" in values:
result["title"] = values["title_id"]
return result


# --- Invoicing Address ---
Expand Down
4 changes: 4 additions & 0 deletions shopinvader_api_address/tests/test_shopinvader_address_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def setUpClass(cls) -> None:
"zip": "1410",
"city": "Waterloo",
"country_id": cls.env.ref("base.be").id,
"title": cls.env.ref("base.res_partner_title_madam").id,
}
)

Expand Down Expand Up @@ -75,6 +76,7 @@ def test_get_invoicing_address(self):
self.assertEqual(address.get("city"), self.test_partner.city)
self.assertEqual(address.get("country_id"), self.test_partner.country_id.id)
self.assertEqual(address.get("id"), self.test_partner.id)
self.assertEqual(address.get("title_id"), self.test_partner.title.id)

with self._create_test_client(router=address_router) as test_client:
response: Response = test_client.get(
Expand All @@ -98,6 +100,7 @@ def test_get_invoicing_address(self):
self.assertEqual(address.get("city"), self.test_partner.city)
self.assertEqual(address.get("country_id"), self.test_partner.country_id.id)
self.assertEqual(address.get("id"), self.test_partner.id)
self.assertEqual(address.get("title_id"), self.test_partner.title.id)

def test_get_delivery_address(self):
"""
Expand Down Expand Up @@ -186,6 +189,7 @@ def test_update_invoicing_address(self):
"city": "Waterloo",
"country_id": self.env.ref("base.be").id,
"street": "test Street",
"title_id": self.env.ref("base.res_partner_title_madam").id,
}

with self._create_test_client(router=address_router) as test_client:
Expand Down
2 changes: 2 additions & 0 deletions shopinvader_schema_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Address(StrictExtendableBaseModel):
email: str | None = None
state_id: int | None = None
country_id: int | None = None
title_id: int | None = None

@classmethod
def from_res_partner(cls, odoo_rec):
Expand All @@ -31,6 +32,7 @@ def from_res_partner(cls, odoo_rec):
email=odoo_rec.email or None,
state_id=odoo_rec.state_id.id or None,
country_id=odoo_rec.country_id.id or None,
title_id=odoo_rec.title.id or None,
)


Expand Down

0 comments on commit f03e721

Please sign in to comment.