Browse Source

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
master
Harald Welte 9 months ago
parent
commit
8a448e41e2
  1. 80
      models/shipcloud_delivery_carrier.py

80
models/shipcloud_delivery_carrier.py

@ -28,47 +28,47 @@ def split_first_lastname(name):
return ("", name)
return (r[0], r[1])
def build_sc_addr(partner):
"""Convert an Odoo partner object into a shipcloud address."""
addr = {}
(street, house) = split_street_house(partner.street)
addr['street'] = street
addr['street_no'] = house
if partner.street2:
addr['care_of'] = partner.street2
addr['zip_code'] = partner.zip
addr['city'] = partner.city
if partner.state_id and partner.state_id.code:
addr['state'] = partner.state_id.code
addr['country'] = partner.country_id.code
class SCDeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
if partner.is_company:
addr['company'] = partner.name
else:
if partner.parent_id.name:
addr['company'] = partner.parent_id.name
if partner.name:
(first, last) = split_first_lastname(partner.name)
addr['first_name'] = first
addr['last_name'] = last
if partner.email:
addr['email'] = partner.email
if partner.mobile:
addr['phone'] = partner.mobile
elif partner.phone:
addr['phone'] = partner.phone
elif partner.parent_id and partner.parent_id.phone:
addr['phone'] = partner.parent_id.phone
def build_sc_addr(self, partner):
"""Convert an Odoo partner object into a shipcloud address."""
addr = {}
(street, house) = split_street_house(partner.street)
addr['street'] = street
addr['street_no'] = house
if partner.street2:
addr['care_of'] = partner.street2
addr['zip_code'] = partner.zip
addr['city'] = partner.city
if partner.state_id and partner.state_id.code:
addr['state'] = partner.state_id.code
addr['country'] = partner.country_id.code
# We had trouble communicating with the carrier: ShipFrom phone number cannot be more than 15 digits long
if 'phone' in addr and len(addr['phone']) > 15:
addr['phone'] = ''.join(c for c in addr['phone'] if c.isdigit())
if partner.is_company:
addr['company'] = partner.name
else:
if partner.parent_id.name:
addr['company'] = partner.parent_id.name
if partner.name:
(first, last) = split_first_lastname(partner.name)
addr['first_name'] = first
addr['last_name'] = last
if partner.email:
addr['email'] = partner.email
if partner.mobile:
addr['phone'] = partner.mobile
elif partner.phone:
addr['phone'] = partner.phone
elif partner.parent_id and partner.parent_id.phone:
addr['phone'] = partner.parent_id.phone
return addr
# We had trouble communicating with the carrier: ShipFrom phone number cannot be more than 15 digits long
if 'phone' in addr and len(addr['phone']) > 15:
addr['phone'] = ''.join(c for c in addr['phone'] if c.isdigit())
class SCDeliveryCarrier(models.Model):
_inherit = 'delivery.carrier'
return addr
@staticmethod
def estimate_dimensions(weight_kg, density_kg_per_dm3):
@ -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)

Loading…
Cancel
Save