← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~camptocamp/carriers-deliveries/7.0-add-base_delivery_carrier_label-yvr into lp:carriers-deliveries

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/carriers-deliveries/7.0-add-base_delivery_carrier_label-yvr into lp:carriers-deliveries.

Commit message:
Port of delivery_base and deliver_shipping_label removing direct print logic

Requested reviews:
  Guewen Baconnier @ Camptocamp (gbaconnier-c2c)

For more details, see:
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-add-base_delivery_carrier_label-yvr/+merge/196753


-- 
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-add-base_delivery_carrier_label-yvr/+merge/196753
Your team Stock and Logistic Core Editors is subscribed to branch lp:carriers-deliveries.
=== added directory 'base_delivery_carrier_label'
=== added file 'base_delivery_carrier_label/__init__.py'
--- base_delivery_carrier_label/__init__.py	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/__init__.py	2013-11-26 17:00:40 +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 delivery
+from . import stock

=== added file 'base_delivery_carrier_label/__openerp__.py'
--- base_delivery_carrier_label/__openerp__.py	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/__openerp__.py	2013-11-26 17:00:40 +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': 'Base module for carrier labels',
+ 'version': '1.0',
+ 'author': 'Camptocamp',
+ 'maintainer': 'Camptocamp',
+ 'contributors': ['Yannick Vaucher <yannick.vaucher@xxxxxxxxxxxxxx'],
+ 'category': 'version',
+ 'complexity': 'normal',
+ 'depends': ['stock', 'delivery'],
+ 'description': """
+Base module for carrier labels
+==============================
+
+This module adds a button on delivery order to generate a label as an attachement.
+
+.. tip::
+   It doesn't implement a label. To add a default label, you can install
+   module `delivery_carrier_label_default_webkit`
+
+It can be used print specific labels per carrier.
+
+.. note::
+   Inspired by Akretion module delivery_base and delivery_shipping_label
+ """,
+ 'website': 'http://www.camptocamp.com/',
+ 'data': [
+     'delivery_view.xml',
+     'stock_view.xml',
+     ],
+ 'tests': [],
+ 'installable': True,
+ 'auto_install': False,
+ 'license': 'AGPL-3',
+ 'application': True}

=== added file 'base_delivery_carrier_label/delivery.py'
--- base_delivery_carrier_label/delivery.py	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/delivery.py	2013-11-26 17:00:40 +0000
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Author: Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#    Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
+#
+#    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, fields
+
+
+class DeliveryCarrierTemplateOption(orm.Model):
+    """
+    Available options for a carrier (partner)
+    """
+    _name = 'delivery.carrier.template.option'
+    _description = 'Delivery carrier template option'
+
+    _columns = {
+        'partner_id': fields.many2one('res.partner', 'Partner Carrier'),
+        'name': fields.char('Name', size=64),
+        'code': fields.char('Code', size=64),
+        }
+
+
+class DeliveryCarrierOption(orm.Model):
+    """
+    Option selected for a carrier method
+    Those options define the list of available pre-added and available
+    to be added on delivery orders
+    """
+    _name = 'delivery.carrier.option'
+    _description = 'Delivery carrier option'
+    _inherits = {'delivery.carrier.template.option': 'tmpl_option_id'}
+
+    _columns = {
+        'state': fields.selection((
+            ('mandatory', 'Mandatory'),
+            ('default_option', 'Optional by Default'),
+            ('option', 'Optional'),
+            ), 'Option Configuration',
+            help="Ensure you add and define correctly all your options or those won't "
+                 "be available for the packager\n"
+                 "- Mandatory: This option will be copied on carrier and cannot be removed\n"
+                 "- Optional by Default: This option will be copied but can be removed\n"
+                 "- Optional: This option can be added later by the user on the picking."),
+        'tmpl_option_id': fields.many2one(
+            'delivery.carrier.template.option',
+            string='Option', required=True, ondelete="cascade"),
+        'carrier_id': fields.many2one('delivery.carrier', 'Carrier'),
+        }
+
+
+class DeliveryCarrier(orm.Model):
+    _inherit = 'delivery.carrier'
+
+    def _get_carrier_type_selection(self, cr, uid, context=None):
+        """ To inherit to add carrier type """
+        return []
+
+    _columns = {
+        'type': fields.selection(
+            _get_carrier_type_selection, 'Type',
+            help="Carrier type (combines several delivery methods)"),
+        'code': fields.char(
+            'Code', size=10, help="Delivery Method Code (according to carrier)"),
+        'description': fields.text('Description'),
+        'available_option_ids': fields.one2many(
+            'delivery.carrier.option',
+            'carrier_id', 'Option'),
+        }

=== added file 'base_delivery_carrier_label/delivery_view.xml'
--- base_delivery_carrier_label/delivery_view.xml	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/delivery_view.xml	2013-11-26 17:00:40 +0000
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+
+    <!-- VIEW FOR THE OBJECT : delivery_carrier_template_option -->
+    <record id="delivery_carrier_template_option_view_form" model="ir.ui.view">
+      <field name="name">delivery_base.delivery_carrier_option.view_form</field>
+      <field name="model">delivery.carrier.template.option</field>
+      <field name="arch" type="xml">
+        <form string="delivery_carrier_option">
+          <field name="partner_id" />
+          <field name="code"/>
+          <field name="name"/>
+        </form>
+      </field>
+    </record>
+
+    <record id="delivery_carrier_template_option_view_tree" model="ir.ui.view">
+      <field name="name">delivery_base.delivery_carrier_template_option.view_tree</field>
+      <field name="model">delivery.carrier.template.option</field>
+      <field name="arch" type="xml">
+        <tree string="delivery_carrier_option">
+          <field name="partner_id" />
+          <field name="code"/>
+          <field name="name"/>
+        </tree>
+      </field>
+    </record>
+
+    <!-- VIEW FOR THE OBJECT : delivery_carrier_option -->
+    <record id="delivery_carrier_option_view_form" model="ir.ui.view">
+      <field name="name">delivery_base.delivery_carrier_option.view_form</field>
+      <field name="model">delivery.carrier.option</field>
+      <field name="arch" type="xml">
+        <form string="delivery_carrier_option">
+          <field name="state"/>
+          <field name="tmpl_option_id"/>
+        </form>
+      </field>
+    </record>
+
+    <record id="delivery_carrier_option_view_tree" model="ir.ui.view">
+      <field name="name">delivery_base.delivery_carrier_option.view_tree</field>
+      <field name="model">delivery.carrier.option</field>
+      <field name="type">tree</field>
+      <field name="arch" type="xml">
+        <tree string="delivery_carrier_option">
+          <field name="state" />
+          <field name="tmpl_option_id" />
+          <field name="code" readonly="1"/>
+        </tree>
+      </field>
+    </record>
+
+    <!-- INHERITED VIEW FOR THE OBJECT : delivery.carrier -->
+
+    <record id="view_delivery_carrier_form" model="ir.ui.view">
+      <field name="name">delivery_base.delivery.carrier.view_form</field>
+      <field name="model">delivery.carrier</field>
+      <field name="inherit_id" ref="delivery.view_delivery_carrier_form"/>
+      <field name="arch" type="xml">
+        <field name="pricelist_ids" position="after">
+          <separator string="Options" colspan="4"/>
+          <field name="available_option_ids" nolabel="1" colspan="4"/>
+        </field>
+        <field name="active" position="after">
+          <field name="type"/>
+          <field name="code"/>
+          <separator name='description' colspan="4" string="Description"/>
+          <field name="description" colspan="4" nolabel="1"/>
+        </field>
+      </field>
+    </record>
+
+    <record id="view_delivery_carrier_tree" model="ir.ui.view">
+      <field name="name">delivery_carrier_base.tree</field>
+      <field name="model">delivery.carrier</field>
+      <field name="inherit_id" ref="delivery.view_delivery_carrier_tree"/>
+      <field name="arch" type="xml">
+        <field name="name" position="after">
+          <field name="type"/>
+          <field name="code"/>
+        </field>
+      </field>
+    </record>
+
+  </data>
+</openerp>

=== added directory 'base_delivery_carrier_label/i18n'
=== added file 'base_delivery_carrier_label/reports.xml'
--- base_delivery_carrier_label/reports.xml	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/reports.xml	2013-11-26 17:00:40 +0000
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+  <data>
+    <report
+      auto="False"
+      id="delivery.shipping_label"
+      model="stock.picking"
+      name="delivery.shipping.label"
+      file="base_delivery_carrier_label/report/template/shipping_label.mako"
+      string="Shipping Label"
+      attachment_use="1"
+      multi="False"
+      report_type="webkit"/>
+  </data>
+</openerp>

=== added directory 'base_delivery_carrier_label/security'
=== added file 'base_delivery_carrier_label/security/ir.model.access.csv'
--- base_delivery_carrier_label/security/ir.model.access.csv	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/security/ir.model.access.csv	2013-11-26 17:00:40 +0000
@@ -0,0 +1,5 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_delivery_carrier_option_salesman,delivery.carrier.option.salesman,model_delivery_carrier_option,base.group_sale_salesman,1,0,0,0
+access_delivery_carrier_option_manager,delivery.carrier.option.manager,model_delivery_carrier_option,base.group_sale_manager,1,1,1,1
+access_delivery_carrier_template_option_salesman,delivery.carrier.relation.option.salesman,model_delivery_carrier_template_option,base.group_sale_salesman,1,0,0,0
+access_delivery_carrier_template_option_manager,delivery.carrier.relation.option.manager,model_delivery_carrier_template_option,base.group_sale_manager,1,1,1,1

=== added file 'base_delivery_carrier_label/stock.py'
--- base_delivery_carrier_label/stock.py	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/stock.py	2013-11-26 17:00:40 +0000
@@ -0,0 +1,160 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    Authors: David BEAL <david.beal@xxxxxxxxxxxx>
+#             Sébastien BEAU <sebastien.beau@xxxxxxxxxxxx>
+#    Copyright (C) 2012-TODAY Akretion <http://www.akretion.com>.
+#    Author: Yannick Vaucher <yannick.vaucher@xxxxxxxxxxxxxx>
+#    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, fields
+from openerp.tools.translate import _
+
+
+class stock_picking(orm.Model):
+    """
+    Devfine m2m field due to inheritance to have it in stock.picking.out model
+    """
+    _inherit = 'stock.picking'
+
+    _columns = {
+        'option_ids': fields.many2many('delivery.carrier.option', string='Options'),
+        }
+
+
+class stock_picking_out(orm.Model):
+    _inherit = 'stock.picking.out'
+
+    def _get_carrier_type_selection(self, cr, uid, context=None):
+        carrier_obj = self.pool.get('delivery.carrier')
+        return carrier_obj._get_carrier_type_selection(cr, uid, context=context)
+
+    _columns = {
+        'carrier_id': fields.many2one(
+            'delivery.carrier', 'Carrier',
+            states={'done': [('readonly', True)]}),
+        'carrier_tracking_ref': fields.char(
+            'Carrier Tracking Ref',
+            size=32,
+            states={'done': [('readonly', True)]}),
+        'carrier_type': fields.related(
+            'carrier_id', 'type',
+            string='Carrier type',
+            readonly=True,
+            type='selection',
+            selection=_get_carrier_type_selection,
+            help="Carrier type ('group')"),
+        'carrier_code': fields.related(
+            'carrier_id', 'code',
+            string='Delivery Method Code',
+            readonly=True,
+            type='char',
+            help="Delivery Method Code (from carrier)"),
+        'option_ids': fields.many2many('delivery.carrier.option', string='Options'),
+        }
+
+    def generate_default_label(self, cr, uid, ids, context=None):
+        """
+        Abstract method
+        """
+        return NotImplementedError
+
+    def generate_single_label(self, cr, uid, ids, context=None):
+        """
+        Abstract method
+        """
+        return self.generate_default_label(cr, uid, ids, context=None)
+
+    def action_generate_carrier_label(self, cr, uid, ids, context=None):
+        shipping_label_obj = self.pool.get('shipping.label')
+
+        pickings = self.browse(cr, uid, ids, context=context)
+
+        pdf_list = []
+        for pick in pickings:
+            pdf = pick.generate_single_label()
+            pdf_list.append(pdf)
+            data = {
+                'name': pick.name,
+                'res_id': pick.id,
+                'res_model': 'stock.picking.out',
+                'datas': pdf.encode('base64'),
+                }
+            context_attachment = context.copy()
+            # remove default_type setted for stock_picking
+            # as it would try to define default value of attachement
+            if 'default_type' in context_attachment:
+                del context_attachment['default_type']
+            shipping_label_obj.create(cr, uid, data, context=context_attachment)
+        return True
+
+    def carrier_id_change(self, cr, uid, ids, carrier_id, context=None):
+        """ Inherit this method in your module """
+        carrier_obj = self.pool.get('delivery.carrier')
+        res = {}
+        if carrier_id:
+            carrier = carrier_obj.browse(cr, uid, carrier_id, context=context)
+            #This can look useless as the field carrier_code and carrier_type
+            #are related field. But it's needed to fill this field for using
+            #this fields in the view. Indeed the module that depend of delivery
+            #base can hide some field depending of the type or the code
+
+            default_option_ids = []
+            available_option_ids = []
+            for available_option in carrier.available_option_ids:
+                available_option_ids.append(available_option.id)
+                if available_option.state in ['default_option', 'mandatory']:
+                    default_option_ids.append(available_option.id)
+            res = {
+                'value': {
+                    'carrier_type': carrier.type,
+                    'carrier_code': carrier.code,
+                    'option_ids': default_option_ids,
+                    },
+                'domain': {
+                    'option_ids': [('id', 'in', available_option_ids)],
+                    },
+                }
+        return res
+
+    def option_ids_change(self, cr, uid, ids, option_ids, carrier_id, context=None):
+        carrier_obj = self.pool.get('delivery.carrier')
+        res = {}
+        if carrier_id:
+            carrier = carrier_obj.browse(cr, uid, carrier_id, context=context)
+            for available_option in carrier.available_option_ids:
+                if (available_option.state == 'mandatory'
+                        and not available_option.id in option_ids[0][2]):
+                    res['warning'] = {
+                        'title': _('User Error !'),
+                        'message':  _("You can not remove a mandatory option."
+                                      "\nOption are reset to default")
+                    }
+                    default_value = self.carrier_id_change(cr, uid, ids,
+                                                           carrier_id,
+                                                           context=context)
+                    res.update(default_value)
+        return res
+
+
+class ShippingLabel(orm.Model):
+    """
+    Child class of ir attachment to identify which are labels
+    """
+    _inherits = {'ir.attachment': 'attachment_id'}
+    _name = "shipping.label"
+    _description = "Shipping Label"

=== added file 'base_delivery_carrier_label/stock_view.xml'
--- base_delivery_carrier_label/stock_view.xml	1970-01-01 00:00:00 +0000
+++ base_delivery_carrier_label/stock_view.xml	2013-11-26 17:00:40 +0000
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<openerp>
+  <data>
+    <!-- From DELIVERY module on STOCK.PICKING -->
+    <!-- FORM -->
+    <record id="view_picking_out_form" model="ir.ui.view">
+      <field name="name">delivery.base.stock.picking.form</field>
+      <field name="model">stock.picking.out</field>
+      <field name="inherit_id" ref="delivery.view_picking_withcarrier_out_form"/>
+      <field name="arch" type="xml">
+        <field name="state" position="before">
+          <button name="action_generate_carrier_label" states="assigned,confirmed,draft" string="Create Label" type="object"/>
+        </field>
+        <field name="carrier_id" position="attributes">
+          <attribute name="on_change">carrier_id_change(carrier_id, context)</attribute>
+        </field>
+        <notebook position='inside'>
+          <page name="carrier" string="Carrier Info">
+            <separator string="Delivery"/>
+            <field name="carrier_type"/>
+            <field name="carrier_code"/>
+            <separator string="Options"/>
+            <field name="option_ids" nolabel="1"
+              on_change="option_ids_change(option_ids, carrier_id, context)"/>
+          </page>
+        </notebook>
+      </field>
+    </record>
+
+    <!-- TREE -->
+    <!--<record id="view_picking_out_tree" model="ir.ui.view">-->
+      <!--<field name="name">stock.picking.tree</field>-->
+      <!--<field name="model">stock.picking.out</field>-->
+      <!--<field name="inherit_id" ref="stock.view_picking_out_tree" />-->
+      <!--<field name="arch" type="xml">-->
+        <!--<field name="partner_id" position="after">-->
+          <!--[><field name="carrier_type" string="carrier"/><]-->
+          <!--<field name="carrier_code" string="code"/>-->
+        <!--</field>-->
+      <!--</field>-->
+    <!--</record>-->
+
+    <!--<record id="view_picking_internal_tree" model="ir.ui.view">-->
+      <!--<field name="name">stock.picking.tree</field>-->
+      <!--<field name="model">stock.picking</field>-->
+      <!--<field name="inherit_id" ref="stock.vpicktree" />-->
+      <!--<field name="arch" type="xml">-->
+        <!--<field name="partner_id" position="after">-->
+          <!--<field name="carrier_type"/>-->
+        <!--</field>-->
+      <!--</field>-->
+    <!--</record>-->
+
+    <!--<record id="view_picking_out_search" model="ir.ui.view">-->
+      <!--<field name="name">stock.picking.out.search</field>-->
+      <!--<field name="model">stock.picking</field>-->
+      <!--<field name="inherit_id" ref="stock.view_picking_out_search"/>-->
+      <!--<field name="arch" type="xml">-->
+        <!--<field name="name" position="before">-->
+          <!--<field name="carrier_type"/>-->
+        <!--</field>-->
+      <!--</field>-->
+    <!--</record>-->
+
+    <!--<record id="view_picking_internal_search" model="ir.ui.view">-->
+      <!--<field name="name">stock.picking.internal.search</field>-->
+      <!--<field name="model">stock.picking</field>-->
+      <!--<field name="inherit_id" ref="stock.view_picking_internal_search"/>-->
+      <!--<field name="arch" type="xml">-->
+        <!--<field name="name" position="before">-->
+          <!--[><field name="carrier_type"/><]-->
+        <!--</field>-->
+      <!--</field>-->
+    <!--</record>-->
+
+  </data>
+</openerp>


References