Skip to content

Commit

Permalink
[FIX] Wait data encoded in base64 / write tracking number on package
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Sep 5, 2019
1 parent 78a3a4e commit 86552f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
13 changes: 2 additions & 11 deletions base_delivery_carrier_label/models/shipping_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2014 Akretion <http://www.akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class ShippingLabel(models.Model):
Expand All @@ -12,16 +12,7 @@ class ShippingLabel(models.Model):
_inherits = {'ir.attachment': 'attachment_id'}
_description = "Shipping Label"

@api.model
def _selection_file_type(self):
""" To inherit to add file type """
return [
('pdf', 'PDF'),
('zpl2', 'ZPL2'),
]

file_type = fields.Selection(
selection='_selection_file_type',
file_type = fields.Char(
string='File type',
default='pdf',
)
Expand Down
9 changes: 6 additions & 3 deletions base_delivery_carrier_label/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Copyright 2013-2016 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
import logging
from odoo import _, api, fields, models
from odoo.exceptions import UserError
Expand Down Expand Up @@ -48,7 +47,7 @@ def generate_shipping_labels(self):
:return: list of dict containing
name: name to give to the attachement
file: file as string
file: file as base64
file_type: string of file type like 'PDF'
(optional)
tracking_number: tracking id defined by your carrier
Expand All @@ -70,7 +69,7 @@ def get_shipping_label_values(self, label):
'datas_fname': label.get('filename', label['name']),
'res_id': self.id,
'res_model': 'stock.picking',
'datas': base64.b64encode(label['file']),
'datas': label['file'],
'file_type': label['file_type'],
}

Expand Down Expand Up @@ -101,13 +100,17 @@ def action_generate_carrier_label(self):
Packages are mandatory in this case
"""
package_obj = self.env['stock.quant.package']
for pick in self:
pick._set_a_default_package()
shipping_labels = pick.generate_shipping_labels()
for label in shipping_labels:
data = pick.get_shipping_label_values(label)
if label.get('package_id'):
data['package_id'] = label['package_id']
if label.get('tracking_number'):
package_obj.browse(label['package_id']).write(
{'parcel_tracking': label.get('tracking_number')})
context_attachment = self.env.context.copy()
# remove default_type setted for stock_picking
# as it would try to define default value of attachement
Expand Down

0 comments on commit 86552f8

Please sign in to comment.