Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] Add partner title in address api schemas #1569

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading