shipcloud: make build_sc_addr() a 'free' function

It doesn't need anything from the 'self' object, so let's make
it a function free to use by anyone
This commit is contained in:
Harald Welte 2021-03-15 21:15:00 +01:00
parent 95160dd623
commit 8a448e41e2
1 changed files with 41 additions and 41 deletions

View File

@ -28,11 +28,7 @@ def split_first_lastname(name):
return ("", name)
return (r[0], r[1])
class SCDeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
def build_sc_addr(self, partner):
def build_sc_addr(partner):
"""Convert an Odoo partner object into a shipcloud address."""
addr = {}
(street, house) = split_street_house(partner.street)
@ -70,6 +66,10 @@ class SCDeliveryCarrier(models.Model):
return addr
class SCDeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
@staticmethod
def estimate_dimensions(weight_kg, density_kg_per_dm3):
"""Estimate the dimensions of a given package, given its weight and mass density,
@ -184,8 +184,8 @@ class SCDeliveryCarrier(models.Model):
carrier_service = self.sudo().sc_carrier_service
# build individual sub-objects of the shipment
from_addr = self.build_sc_addr(warehouse)
to_addr = self.build_sc_addr(recipient)
from_addr = build_sc_addr(warehouse)
to_addr = build_sc_addr(recipient)
pkg = self.build_sc_pkg(order=order)
# build the actual shipment object
shp = shipcloud.gen_shipment(from_addr, to_addr, pkg, order.name,
@ -218,8 +218,8 @@ class SCDeliveryCarrier(models.Model):
carrier_service = self.sudo().sc_carrier_service
# build individual sub-objects of the shipment
from_addr = self.build_sc_addr(warehouse)
to_addr = self.build_sc_addr(recipient)
from_addr = build_sc_addr(warehouse)
to_addr = build_sc_addr(recipient)
pkg = self.build_sc_pkg(picking=pickings)
if warehouse.country_id.code != recipient.country_id.code and self._is_outside_eu(recipient.country_id) and carrier_service.carrier != 'ups':
customs = self.build_sc_customs_decl(pickings, content_desc)