openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #01961
lp:~camptocamp/carriers-deliveries/7.0-add-delivery_carrier_label_dispatch-yvr into lp:carriers-deliveries
Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/carriers-deliveries/7.0-add-delivery_carrier_label_dispatch-yvr into lp:carriers-deliveries with lp:~camptocamp/carriers-deliveries/7.0-add-base_delivery_carrier_label-yvr as a prerequisite.
Requested reviews:
Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
For more details, see:
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-add-delivery_carrier_label_dispatch-yvr/+merge/198049
--
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-add-delivery_carrier_label_dispatch-yvr/+merge/198049
Your team Stock and Logistic Core Editors is subscribed to branch lp:carriers-deliveries.
=== added directory 'delivery_carrier_label_dispatch'
=== added file 'delivery_carrier_label_dispatch/__init__.py'
--- delivery_carrier_label_dispatch/__init__.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/__init__.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from . import stock
+from . import wizard
=== added file 'delivery_carrier_label_dispatch/__openerp__.py'
--- delivery_carrier_label_dispatch/__openerp__.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/__openerp__.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{'name': 'Carrier labels - Picking dispatch (link)',
+ 'version': '1.0',
+ 'author': 'Camptocamp',
+ 'maintainer': 'Camptocamp',
+ 'category': 'version',
+ 'complexity': 'normal',
+ 'depends': ['base_delivery_carrier_label', 'picking_dispatch'],
+ 'description': """
+[Link module] Carrier labels - Picking dispatch
+==============================
+
+This module adds a wizard on picking dispatch to generate related picking
+labels
+
+Contributors
+------------
+
+* Yannick Vaucher <yannick.vaucher@xxxxxxxxxxxxxx>
+
+""",
+ 'website': 'http://www.camptocamp.com/',
+ 'data': [
+ 'wizard/generate_labels_view.xml',
+ ],
+ 'tests': [],
+ 'installable': True,
+ 'auto_install': True,
+ 'license': 'AGPL-3',
+ 'application': False,
+ 'external_dependencies': {
+ 'python': ['PyPDF2'],
+ }
+ }
=== added directory 'delivery_carrier_label_dispatch/i18n'
=== added file 'delivery_carrier_label_dispatch/stock.py'
--- delivery_carrier_label_dispatch/stock.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/stock.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from openerp.osv import orm
+
+
+class stock_picking(orm.Model):
+ _inherit = 'stock.picking'
+
+ def get_pdf_label(self, cr, uid, ids, context=None):
+ res = dict.fromkeys(ids, False)
+ label_obj = self.pool.get('shipping.label')
+ for picking_id in ids:
+ label_ids = label_obj.search(cr, uid,
+ [('file_type', '=', 'pdf'),
+ ('res_id', '=', picking_id)],
+ limit=1, order='create_date',
+ context=context)
+ if label_ids:
+ label = label_obj.browse(cr, uid, label_ids[0],
+ context=context)
+ res[picking_id] = label.datas
+ return res
=== added directory 'delivery_carrier_label_dispatch/tests'
=== added file 'delivery_carrier_label_dispatch/tests/__init__.py'
--- delivery_carrier_label_dispatch/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/tests/__init__.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from . import test_generate_labels
=== added file 'delivery_carrier_label_dispatch/tests/dummy.pdf'
Binary files delivery_carrier_label_dispatch/tests/dummy.pdf 1970-01-01 00:00:00 +0000 and delivery_carrier_label_dispatch/tests/dummy.pdf 2013-12-06 12:56:25 +0000 differ
=== added file 'delivery_carrier_label_dispatch/tests/test_generate_labels.py'
--- delivery_carrier_label_dispatch/tests/test_generate_labels.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/tests/test_generate_labels.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+import openerp.tests.common as common
+from openerp.addons import get_module_resource
+
+
+class test_generate_labels(common.TransactionCase):
+ """ Test the wizard for delivery carrier label generation """
+
+ def setUp(self):
+ super(test_generate_labels, self).setUp()
+ cr, uid = self.cr, self.uid
+
+ self.Move = self.registry('stock.move')
+ self.Picking = self.registry('stock.picking')
+ self.ShippingLabel = self.registry('shipping.label')
+ self.PickingDispatch = self.registry('picking.dispatch')
+ self.DeliveryCarrierLabelGenerate = self.registry('delivery.carrier.label.generate')
+
+ picking_out_1_id = self.Picking.create(
+ cr, uid,
+ {'partner_id': self.ref('base.res_partner_12'),
+ 'type': 'out'})
+
+ picking_out_2_id = self.Picking.create(
+ cr, uid,
+ {'partner_id': self.ref('base.res_partner_12'),
+ 'type': 'out'})
+
+ self.picking_dispatch_id = self.PickingDispatch.create(
+ cr, uid,
+ {'name': 'demo_prep001',
+ 'picker_id': self.ref('base.user_demo'),
+ })
+
+ self.Move.create(
+ cr, uid,
+ {'name': '/',
+ 'picking_id': picking_out_1_id,
+ 'dispatch_id': self.picking_dispatch_id,
+ 'product_id': self.ref('product.product_product_33'),
+ 'product_uom': self.ref('product.product_uom_unit'),
+ 'product_qty': 2,
+ 'location_id': self.ref('stock.stock_location_14'),
+ 'location_dest_id': self.ref('stock.stock_location_7'),
+ })
+
+ self.Move.create(
+ cr, uid,
+ {'name': '/',
+ 'picking_id': picking_out_2_id,
+ 'dispatch_id': self.picking_dispatch_id,
+ 'product_id': self.ref('product.product_product_33'),
+ 'product_uom': self.ref('product.product_uom_unit'),
+ 'product_qty': 1,
+ 'location_id': self.ref('stock.stock_location_14'),
+ 'location_dest_id': self.ref('stock.stock_location_7'),
+ })
+
+ label = ''
+ dummy_pdf_path = get_module_resource('delivery_carrier_label_dispatch', 'tests' ,'dummy.pdf')
+ with file(dummy_pdf_path) as dummy_pdf:
+ label = dummy_pdf.read()
+
+ self.ShippingLabel.create(
+ cr, uid,
+ {'name': 'picking_out_1',
+ 'res_id': picking_out_1_id,
+ 'res_model': 'stock.picking.out',
+ 'datas': label.encode('base64'),
+ 'file_type': 'pdf',
+ })
+
+ self.ShippingLabel.create(
+ cr, uid,
+ {'name': 'picking_out_2',
+ 'res_id': picking_out_2_id,
+ 'res_model': 'stock.picking.out',
+ 'datas': label.encode('base64'),
+ 'file_type': 'pdf',
+ })
+
+ def test_00_action_generate_labels(self):
+ """ Check merging of pdf labels
+
+ We don't test pdf generation as without dependancies the
+ test would fail
+
+ """
+ cr, uid = self.cr, self.uid
+ active_ids = [self.picking_dispatch_id]
+ wizard_id = self.DeliveryCarrierLabelGenerate.create(
+ cr, uid,
+ {},
+ context={'active_ids': active_ids,
+ 'active_model': 'picking.dispatch'})
+ wizard = self.DeliveryCarrierLabelGenerate.browse(
+ cr, uid, [wizard_id], context=None)
+ act_win = self.DeliveryCarrierLabelGenerate.action_generate_labels(
+ cr, uid, [wizard_id], context={'active_ids': active_ids})
+ wizard = self.DeliveryCarrierLabelGenerate.browse(
+ cr, uid, wizard_id, context=None)
+ assert wizard.label_pdf_file
=== added directory 'delivery_carrier_label_dispatch/wizard'
=== added file 'delivery_carrier_label_dispatch/wizard/__init__.py'
--- delivery_carrier_label_dispatch/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/wizard/__init__.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from . import generate_labels
=== added file 'delivery_carrier_label_dispatch/wizard/generate_labels.py'
--- delivery_carrier_label_dispatch/wizard/generate_labels.py 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/wizard/generate_labels.py 2013-12-06 12:56:25 +0000
@@ -0,0 +1,112 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# Author: Yannick Vaucher
+# Copyright 2013 Camptocamp SA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from StringIO import StringIO
+from PyPDF2 import PdfFileReader, PdfFileWriter
+
+from openerp.osv import orm, fields
+from tools.translate import _
+
+
+def assemble_pdf(pdf_list):
+ """
+ Assemble a list of pdf
+ """
+ # Even though we are using PyPDF2 we can't use PdfFileMerger
+ # as this issue still exists in mostly used wkhtmltohpdf reports version
+ # http://code.google.com/p/wkhtmltopdf/issues/detail?id=635
+ #merger = PdfFileMerger()
+ #merger.append(fileobj=StringIO(invoice_pdf))
+ #merger.append(fileobj=StringIO(bvr_pdf))
+
+ #with tempfile.TemporaryFile() as merged_pdf:
+ #merger.write(merged_pdf)
+ #return merged_pdf.read(), 'pdf'
+
+ output = PdfFileWriter()
+ for pdf in pdf_list:
+ reader = PdfFileReader(StringIO(pdf))
+ for page in range(reader.getNumPages()):
+ output.addPage(reader.getPage(page))
+ s = StringIO()
+ output.write(s)
+ return s.getvalue()
+
+
+class DeliveryCarrierLabelGenerate(orm.TransientModel):
+
+ _name = 'delivery.carrier.label.generate'
+
+ def _get_dispatch_ids(self, cr, uid, context=None):
+ if context is None:
+ context = {}
+ res = False
+ if (context.get('active_model') == 'picking.dispatch'
+ and context.get('active_ids')):
+ res = context['active_ids']
+ return res
+
+ _columns = {
+ 'dispatch_ids': fields.many2many('picking.dispatch',
+ string='Picking Dispatch'),
+ 'label_pdf_file': fields.binary('Labels file'),
+ }
+
+ _defaults = {
+ 'dispatch_ids': _get_dispatch_ids,
+ }
+
+ def action_generate_labels(self, cr, uid, ids, context=None):
+ """
+ Call the creation of the delivery carrier label
+ and merge them in a single PDF
+ """
+ context = context or {}
+ this = self.browse(cr, uid, ids, context=context)[0]
+ if not this.dispatch_ids:
+ raise orm.except_orm(_('Error'), _('No picking dispatch selected'))
+
+ picking_out_obj = self.pool.get('stock.picking.out')
+
+ # flatten all ids
+ picking_ids = [picking.id for dispatch in this.dispatch_ids
+ for picking in dispatch.related_picking_ids
+ if not picking.get_pdf_label()[picking.id]]
+ # generate missing picking labels
+ picking_out_obj.action_generate_carrier_label(cr, uid,
+ picking_ids,
+ #file_type='pdf',
+ context=context)
+
+ data_list = [picking.get_pdf_label()[picking.id]
+ for dispatch in this.dispatch_ids
+ for picking in dispatch.related_picking_ids]
+ pdf_list = [data.decode('base64') for data in data_list if data]
+ pdf_file = assemble_pdf(pdf_list)
+ this.write({'label_pdf_file': pdf_file.encode('base64')})
+ return {
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'delivery.carrier.label.generate',
+ 'view_mode': 'form',
+ 'view_type': 'form',
+ 'res_id': this.id,
+ 'views': [(False, 'form')],
+ 'target': 'new',
+ }
=== added file 'delivery_carrier_label_dispatch/wizard/generate_labels_view.xml'
--- delivery_carrier_label_dispatch/wizard/generate_labels_view.xml 1970-01-01 00:00:00 +0000
+++ delivery_carrier_label_dispatch/wizard/generate_labels_view.xml 2013-12-06 12:56:25 +0000
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+ <data>
+
+ <record id="view_delivery_carrier_label_generate" model="ir.ui.view">
+ <field name="name">Generate Carriers Labels</field>
+ <field name="model">delivery.carrier.label.generate</field>
+ <field name="arch" type="xml">
+ <form string="Generate Carriers Labels" version="7.0">
+
+ <group>
+ <field name="dispatch_ids"/>
+ </group>
+ <separator string="Labels"/>
+ <group>
+ <field name="label_pdf_file" filename="picking_labels.pdf"/>
+ </group>
+ <footer>
+ <button name="action_generate_labels" string="Generate Labels" type="object" icon="gtk-execute" class="oe_highlight"/>
+ or
+ <button string="Close" class="oe_link" special="cancel" />
+ </footer>
+
+ </form>
+ </field>
+ </record>
+
+ <record id="action_delivery_carrier_label_generate" model="ir.actions.act_window">
+ <field name="name">Generate Carrier Labels</field>
+ <field name="res_model">delivery.carrier.label.generate</field>
+ <field name="view_type">form</field>
+ <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="target">new</field>
+ </record>
+
+ <record model="ir.values" id="delivery_carrier_file_generate_ir_values">
+ <field name="object" eval="1" />
+ <field name="name">Generate Carrier Labels</field>
+ <field name="key2">client_action_multi</field>
+ <field name="value" eval="'ir.actions.act_window,' + str(ref('action_delivery_carrier_label_generate'))" />
+ <field name="key">action</field>
+ <field name="model">picking.dispatch</field>
+ </record>
+
+ </data>
+</openerp>
Follow ups