Skip to content

Commit

Permalink
shopinvader_api_address: improve schema data conv
Browse files Browse the repository at this point in the history
Always pass an env or a record.

On the same vein of shopinvader#1534
  • Loading branch information
simahawk committed Apr 23, 2024
1 parent 0f73c49 commit 3083041
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions shopinvader_api_address/routers/address_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 10 additions & 6 deletions shopinvader_api_address/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
"""
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 3083041

Please sign in to comment.