[FIX] delivery_gso: paper label handling

This commit is contained in:
Jared Kipe
2021-09-20 08:18:20 -07:00
parent 9ea00c570f
commit 23d84e7799

View File

@@ -1,5 +1,6 @@
import pytz import pytz
from math import ceil from math import ceil
from base64 import b64decode
from requests import HTTPError from requests import HTTPError
from hashlib import sha1 from hashlib import sha1
@@ -13,6 +14,13 @@ _logger = logging.getLogger(__name__)
GSO_TZ = 'PST8PDT' GSO_TZ = 'PST8PDT'
def inline_b64decode(data):
try:
return b64decode(data)
except:
return ''
class ProductPackaging(models.Model): class ProductPackaging(models.Model):
_inherit = 'product.packaging' _inherit = 'product.packaging'
@@ -228,7 +236,7 @@ class ProviderGSO(models.Model):
raise ValidationError(e) raise ValidationError(e)
# Handle results # Handle results
trackings = [l[0] for l in labels['thermal']] + [l(0) for l in labels['paper']] trackings = [l[0] for l in labels['thermal']] + [l[0] for l in labels['paper']]
carrier_tracking_ref = ','.join(trackings) carrier_tracking_ref = ','.join(trackings)
logmessage = _("Shipment created into GSO<br/>" logmessage = _("Shipment created into GSO<br/>"
@@ -237,7 +245,8 @@ class ProviderGSO(models.Model):
if labels['thermal']: if labels['thermal']:
attachments += [('LabelGSO-%s.zpl' % (l[0], ), l[1]) for l in labels['thermal']] attachments += [('LabelGSO-%s.zpl' % (l[0], ), l[1]) for l in labels['thermal']]
if labels['paper']: if labels['paper']:
attachments += [('LabelGSO-%s.pdf' % (l[0], ), l[1]) for l in labels['thermal']] # paper labels re-encoded base64
attachments += [('LabelGSO-%s.png' % (l[0], ), inline_b64decode(l[1])) for l in labels['paper']]
picking.message_post(body=logmessage, attachments=attachments) picking.message_post(body=logmessage, attachments=attachments)
shipping_data = {'exact_price': cost, shipping_data = {'exact_price': cost,
'tracking_number': carrier_tracking_ref} 'tracking_number': carrier_tracking_ref}