diff --git a/modules/purchase_trade/stock.py b/modules/purchase_trade/stock.py index ec94e37..44d08b0 100755 --- a/modules/purchase_trade/stock.py +++ b/modules/purchase_trade/stock.py @@ -710,14 +710,21 @@ class ShipmentIn(metaclass=PoolMeta): for sh in shipments: sh.result = "Email not sent" - attachment = None + attachment = [] if sh.add_bl: attachments = Attachment.search([ ('resource', '=', 'stock.shipment.in,' + str(sh.id)), ]) if attachments: - attachment = attachments[0] - + content_b64 = base64.b64encode(attachments[0].data).decode('ascii') + attachment = [ + { + "filename": attachments[0].name, + "content": content_b64, + "content_type": attachments[0].mimetype or "application/pdf" + } + ] + if sh.controller: Contact = Pool().get('party.contact_mechanism') contact = Contact.search(['party','=',sh.controller.id]) @@ -726,13 +733,7 @@ class ShipmentIn(metaclass=PoolMeta): "to": [contact[0].value], "subject": "Request for control", "body": sh.html_to_text(sh.instructions), - "attachments": [ - { - "filename": attachment.name, - "content": attachment.data, - "content_type": "application/pdf" - } - ], + "attachments": attachment, "meta": { "shipment": sh.bl_number, "controller": sh.controller.id