diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py index ec45a926fd..efce8ffa68 100644 --- a/shopinvader_api_address/schemas.py +++ b/shopinvader_api_address/schemas.py @@ -53,19 +53,7 @@ class AddressUpdate(StrictExtendableBaseModel): country_id: int | None = None def to_res_partner_vals(self) -> dict: - vals = { - "name": self.name, - "street": self.street, - "street2": self.street2, - "zip": self.zip, - "city": self.city, - "phone": self.phone, - "email": self.email, - "state_id": self.state_id, - "country_id": self.country_id, - } - - return vals + return self.model_dump(exclude_unset=True) class AddressSearch(StrictExtendableBaseModel): diff --git a/shopinvader_api_address/tests/test_shopinvader_address_api.py b/shopinvader_api_address/tests/test_shopinvader_address_api.py index 2b3bed6197..4f07a09929 100644 --- a/shopinvader_api_address/tests/test_shopinvader_address_api.py +++ b/shopinvader_api_address/tests/test_shopinvader_address_api.py @@ -326,3 +326,36 @@ def test_update_shipping_address(self): ) self.assertEqual(new_address.name, data.get("name")) self.assertEqual(new_address.street, data.get("street")) + + def test_update_partial_shipping_address(self): + """ + Test to update shipping address + """ + new_address = self.env["res.partner"].create( + { + "name": "test New Addr", + "street": "test Street", + "zip": "5000", + "city": "Namur", + "country_id": self.env.ref("base.be").id, + "parent_id": self.test_partner.id, + "type": "delivery", + } + ) + + data = { + "name": "test Addr2 Changed", + } + + with self._create_test_client(router=address_router) as test_client: + response: Response = test_client.post( + f"/addresses/shipping/{new_address.id}", content=json.dumps(data) + ) + + self.assertEqual( + response.status_code, + status.HTTP_200_OK, + msg=f"error message: {response.text}", + ) + self.assertEqual(new_address.name, "test Addr2 Changed") + self.assertEqual(new_address.street, "test Street")