diff --git a/shopinvader_api_address/routers/address_service.py b/shopinvader_api_address/routers/address_service.py index 937ee5039b..661f68b72e 100644 --- a/shopinvader_api_address/routers/address_service.py +++ b/shopinvader_api_address/routers/address_service.py @@ -60,7 +60,7 @@ def create_invoicing_address( Create invoicing address Raise error since invoicing address is the authenticated partner """ - vals = data.to_res_partner_vals() + vals = data.to_res_partner_vals(partner.env) address = partner._create_shopinvader_invoicing_address(vals) return InvoicingAddress.from_res_partner(address) @@ -77,7 +77,7 @@ def update_invoicing_address( Update invoicing address of authenticated user invoicing address corresponds to authenticated partner """ - vals = data.to_res_partner_vals() + vals = data.to_res_partner_vals(partner, address_id) # sudo() is needed because some addons override the write # function of res.partner to do some checks before writing. # These checks need more rights than what we are giving to @@ -125,7 +125,7 @@ def create_delivery_address( """ Create delivery address of authenticated user """ - vals = data.to_res_partner_vals() + vals = data.to_res_partner_vals(partner.env) address = partner._create_shopinvader_delivery_address(vals) return DeliveryAddress.from_res_partner(address) @@ -140,7 +140,7 @@ def update_delivery_address( """ Update delivery address of authenticated user """ - vals = data.to_res_partner_vals() + vals = data.to_res_partner_vals(partner, address_id) # sudo() is needed because some addons override the write # function of res.partner to do some checks before writing. # These checks need more rights than what we are giving to diff --git a/shopinvader_api_address/schemas.py b/shopinvader_api_address/schemas.py index ba7d13cbfd..52873e229d 100644 --- a/shopinvader_api_address/schemas.py +++ b/shopinvader_api_address/schemas.py @@ -3,6 +3,10 @@ from extendable_pydantic import StrictExtendableBaseModel +from odoo.api import Environment + +from odoo.addons.base.models.res_partner import Partner as ResPartner + class AddressCreate(StrictExtendableBaseModel, extra="ignore"): """ @@ -21,7 +25,7 @@ class AddressCreate(StrictExtendableBaseModel, extra="ignore"): state_id: int | None = None country_id: int | None = None - def to_res_partner_vals(self) -> dict: + def to_res_partner_vals(self, env: Environment) -> dict: vals = { "name": self.name, "street": self.street, @@ -55,7 +59,7 @@ class AddressUpdate(StrictExtendableBaseModel, extra="ignore"): state_id: int | None = None country_id: int | None = None - def to_res_partner_vals(self) -> dict: + def to_res_partner_vals(self, rec: ResPartner, address_id: int) -> dict: fields = [ "name", "street", @@ -84,8 +88,8 @@ class InvoicingAddressCreate(AddressCreate): vat: str | None = None - def to_res_partner_vals(self) -> dict: - vals = super().to_res_partner_vals() + def to_res_partner_vals(self, env: Environment) -> dict: + vals = super().to_res_partner_vals(env) vals["vat"] = self.vat @@ -99,8 +103,8 @@ class InvoicingAddressUpdate(AddressUpdate): vat: str | None = None - def to_res_partner_vals(self) -> dict: - vals = super().to_res_partner_vals() + def to_res_partner_vals(self, rec: ResPartner, address_id: int) -> dict: + vals = super().to_res_partner_vals(rec, address_id) vals["vat"] = self.vat