Browse Source

addach customs declaration, too - not just shipping label

master
Harald Welte 8 months ago
parent
commit
1287ccf59d
  1. 4
      models/shipcloud.py
  2. 19
      models/shipcloud_delivery_carrier.py

4
models/shipcloud.py

@ -101,6 +101,10 @@ class api(object):
r = requests.get(res['label_url'], stream=True)
if r.ok:
res['label_bin'] = r.content
if 'customs_declaration' in res and 'carrier_declaration_document_url' in res['customs_declaration']:
r = requests.get(res['customs_declaration']['carrier_declaration_document_url'], stream=True)
if r.ok:
res['customs_declaration_bin'] = r.content
return res
def delete_shipment(self, shipment_id):

19
models/shipcloud_delivery_carrier.py

@ -5,6 +5,8 @@ import pycountry
import shipcloud
_logger = logging.getLogger(__name__)
# FIXME: unify with odoo-internetmarke
# split the last word of a string containing stree name + house number
def split_street_house(streethouse):
@ -219,7 +221,7 @@ class SCDeliveryCarrier(models.Model):
label_fmt=carrier_service.label_size, descr=content_desc)
api = self._shipcloud_api()
try:
#print("SHP: %s" % shp)
_logger.debug("shipcloud Shipment dict: %s", shp)
result = api.create_shipment(shp, gen_label=True)
#print("RES: %s" % result)
except shipcloud.ApiError as err:
@ -227,16 +229,25 @@ class SCDeliveryCarrier(models.Model):
# result = ["id", "carrier_tracking_no", "tracking_url", "label_url", "price"]
# {u'label_url': u'https://shipping-labels.shipcloud.io/shipments/a948e8c2/e3fb26be59/label/shipping_label_e3fb26be59.pdf', u'price': 0.0, u'id': u'e3fb26be59a68acd04d565dda027efd415ca8117', u'tracking_url': u'https://track.shipcloud.io/e3fb26be59a68acd04d565dda027efd415ca8117', u'carrier_tracking_no': u'1ZV306W00493609016'}
filename = '%s.pdf' % result['carrier_tracking_no']
filename = '%s_%s.pdf' % (carrier_service.carrier, result['carrier_tracking_no'])
pickings.update({'sc_shipment_id': result['id'],
'sc_tracking_url': result['tracking_url']})
# TODO: download label from label_url so it can be returned as attachment
# build list of attachments
attachments = [(filename, result['label_bin'])]
if 'customs_declaration_bin' in result:
filename = '%s_%s_customs.pdf' % (carrier_service.carrier, result['carrier_tracking_no'])
attachments.append((filename, result['customs_declaration_bin']))
# log the (filtered) result
result.pop('label_bin', None)
result.pop('customs_declaration_bin', None)
_logger.info("shipcloud Shipment result: %s", result)
res = {'exact_price': result['price'],
'weight': pkg['weight'],
'date_delivery': None,
'tracking_number': ' ' + result['carrier_tracking_no'],
'attachments': [(filename, result['label_bin'])]}
'attachments': attachments}
return res

Loading…
Cancel
Save