Skip to content

Commit

Permalink
fixes for cahnges in migration of base_deliver_carrier_label (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
tschanzt authored and Hadrien Huvelle committed Apr 2, 2024
1 parent 0a2ed95 commit fa5789d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion delivery_carrier_label_batch/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'maintainer': 'Camptocamp',
'category': 'Carrier',
'complexity': 'normal',
'depends': ['base_delivery_carrier_label', 'stock_batch_picking'],
'depends': ['base_delivery_carrier_label', 'stock_picking_batch_extended'],
'website': 'http://github.com/OCA/delivery-carrier',
'data': [
'views/stock_batch_picking.xml',
Expand Down
4 changes: 2 additions & 2 deletions delivery_carrier_label_batch/models/stock_batch_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class StockBatchPicking(models.Model):
to be able to massively set those options on related picking.
"""
_inherit = "stock.batch.picking"
_inherit = "stock.picking.batch"

carrier_id = fields.Many2one(
'delivery.carrier', 'Carrier',
Expand Down Expand Up @@ -52,7 +52,7 @@ def carrier_id_change(self):
available_options = self.carrier_id.available_option_ids
default_options = self._get_options_to_add()
self.option_ids = [(6, 0, default_options.ids)]
self.carrier_type = self.carrier_id.type
self.carrier_type = self.carrier_id.delivery_type
self.carrier_code = self.carrier_id.code
return {'domain': {
'option_ids': [('id', 'in', available_options.ids)],
Expand Down
3 changes: 2 additions & 1 deletion delivery_carrier_label_batch/pdf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ def assemble_pdf(pdf_list):

output = PdfFileWriter()
for pdf in pdf_list:

if not pdf:
continue
reader = PdfFileReader(StringIO(pdf))
reader = PdfFileReader(BytesIO(pdf))

for page in range(reader.getNumPages()):
output.addPage(reader.getPage(page))
Expand Down
6 changes: 3 additions & 3 deletions delivery_carrier_label_batch/views/stock_batch_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<odoo>

<record model="ir.ui.view" id="stock_batch_picking_form">
<field name="name">stock.batch.picking.form</field>
<field name="model">stock.batch.picking</field>
<field name="inherit_id" ref="stock_batch_picking.stock_batch_picking_form"/>
<field name="name">stock.picking.batch.form</field>
<field name="model">stock.picking.batch</field>
<field name="inherit_id" ref="stock_picking_batch_extended.stock_batch_picking_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page name="carrier" string="Carrier Info">
Expand Down
2 changes: 1 addition & 1 deletion delivery_carrier_label_batch/wizard/apply_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def apply(self):
raise exceptions.UserError(
_('No selected picking batch'))

batch_obj = self.env['stock.batch.picking']
batch_obj = self.env['stock.picking.batch']
domain = self._check_domain(batch_ids)
batchs = batch_obj.search(domain)
batchs.write({'carrier_id': self.carrier_id.id})
Expand Down
2 changes: 1 addition & 1 deletion delivery_carrier_label_batch/wizard/apply_carrier_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_picking_batch_apply_carrier"/>
<field name="binding_model_id" ref="stock_batch_picking.model_stock_batch_picking"/>
<field name="binding_model_id" ref="stock_picking_batch_extended.model_stock_picking_batch"/>
<field name="target">new</field>
</record>

Expand Down
16 changes: 7 additions & 9 deletions delivery_carrier_label_batch/wizard/generate_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import logging
import odoo
import threading
import codecs
from contextlib import contextmanager
from itertools import groupby
from odoo import _, api, exceptions, fields, models

from ..pdf_utils import assemble_pdf

_logger = logging.getLogger(__name__)
Expand All @@ -21,13 +21,13 @@ class DeliveryCarrierLabelGenerate(models.TransientModel):
@api.multi
def _get_batch_ids(self):
res = False
if (self.env.context.get('active_model') == 'stock.batch.picking' and
if (self.env.context.get('active_model') == 'stock.picking.batch' and
self.env.context.get('active_ids')):
res = self.env.context['active_ids']
return res

batch_ids = fields.Many2many(
'stock.batch.picking',
'stock.picking.batch',
string='Picking Batch',
default=_get_batch_ids)
generate_new_labels = fields.Boolean(
Expand Down Expand Up @@ -86,9 +86,7 @@ def _do_generate_labels(self, group):
# generate the label of the pack
package_ids = [pack.id] if pack else None
try:
picking.with_env(new_env).generate_labels(
package_ids=package_ids
)
picking.with_env(new_env).action_generate_carrier_label()
except Exception as e:
# add information on picking and pack in the exception
picking_name = _('Picking: %s') % picking.name
Expand Down Expand Up @@ -220,7 +218,7 @@ def action_generate_labels(self):
to_generate = self.batch_ids
if not self.generate_new_labels:
already_generated_ids = self.env['ir.attachment'].search(
[('res_model', '=', 'stock.batch.picking'),
[('res_model', '=', 'stock.picking.batch'),
('res_id', 'in', self.batch_ids.ids)]
).mapped('res_id')
to_generate = to_generate.filtered(
Expand All @@ -229,12 +227,12 @@ def action_generate_labels(self):

for batch in to_generate:
labels = self._get_all_pdf(batch)
labels = (label.decode('base64') for label in labels if label)
labels = (codecs.decode(label, 'base64') for label in labels if label)
filename = batch.name + '.pdf'
data = {
'name': filename,
'res_id': batch.id,
'res_model': 'stock.batch.picking',
'res_model': 'stock.picking.batch',
'datas': base64.b64encode(assemble_pdf(labels)),
'datas_fname': filename,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<field name="view_mode">form</field>
<field name="view_id" ref="view_delivery_carrier_label_generate"/>
<field name="groups_id" eval="[(6, 0, [ref('stock.group_stock_manager')])]"/>
<field name="binding_model_id" ref="stock_batch_picking.model_stock_batch_picking"/>
<field name="binding_model_id" ref="stock_picking_batch_extended.model_stock_picking_batch"/>
<field name="target">new</field>
</record>

Expand Down

0 comments on commit fa5789d

Please sign in to comment.