From b60bcc36931323d055455ac4c7293c3d0e7bae60 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Tue, 26 Nov 2013 17:51:04 +0100 Subject: [PATCH 01/56] [ADD] base_delivery_carrier_label portage of Akretion delivery_shipping_label --- base_delivery_carrier_label/__init__.py | 22 +++ base_delivery_carrier_label/__openerp__.py | 53 ++++++ base_delivery_carrier_label/delivery.py | 83 +++++++++ base_delivery_carrier_label/delivery_view.xml | 88 ++++++++++ base_delivery_carrier_label/reports.xml | 15 ++ .../security/ir.model.access.csv | 5 + base_delivery_carrier_label/stock.py | 160 ++++++++++++++++++ base_delivery_carrier_label/stock_view.xml | 77 +++++++++ 8 files changed, 503 insertions(+) create mode 100644 base_delivery_carrier_label/__init__.py create mode 100644 base_delivery_carrier_label/__openerp__.py create mode 100644 base_delivery_carrier_label/delivery.py create mode 100644 base_delivery_carrier_label/delivery_view.xml create mode 100644 base_delivery_carrier_label/reports.xml create mode 100644 base_delivery_carrier_label/security/ir.model.access.csv create mode 100644 base_delivery_carrier_label/stock.py create mode 100644 base_delivery_carrier_label/stock_view.xml diff --git a/base_delivery_carrier_label/__init__.py b/base_delivery_carrier_label/__init__.py new file mode 100644 index 0000000000..3d456ad9a1 --- /dev/null +++ b/base_delivery_carrier_label/__init__.py @@ -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 . +# +############################################################################## +from . import delivery +from . import stock diff --git a/base_delivery_carrier_label/__openerp__.py b/base_delivery_carrier_label/__openerp__.py new file mode 100644 index 0000000000..d0415b7e0c --- /dev/null +++ b/base_delivery_carrier_label/__openerp__.py @@ -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 . +# +############################################################################## +{'name': 'Base module for carrier labels', + 'version': '1.0', + 'author': 'Camptocamp', + 'maintainer': 'Camptocamp', + 'contributors': ['Yannick Vaucher +# Copyright (C) 2012-TODAY Akretion . +# +# 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 . +# +############################################################################## +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'), + } diff --git a/base_delivery_carrier_label/delivery_view.xml b/base_delivery_carrier_label/delivery_view.xml new file mode 100644 index 0000000000..b4a335342a --- /dev/null +++ b/base_delivery_carrier_label/delivery_view.xml @@ -0,0 +1,88 @@ + + + + + + + delivery_base.delivery_carrier_option.view_form + delivery.carrier.template.option + +
+ + + + + +
+ + + delivery_base.delivery_carrier_template_option.view_tree + delivery.carrier.template.option + + + + + + + + + + + + delivery_base.delivery_carrier_option.view_form + delivery.carrier.option + +
+ + + + +
+ + + delivery_base.delivery_carrier_option.view_tree + delivery.carrier.option + tree + + + + + + + + + + + + + delivery_base.delivery.carrier.view_form + delivery.carrier + + + + + + + + + + + + + + + + + delivery_carrier_base.tree + delivery.carrier + + + + + + + + + +
+
diff --git a/base_delivery_carrier_label/reports.xml b/base_delivery_carrier_label/reports.xml new file mode 100644 index 0000000000..d3e24ee3f7 --- /dev/null +++ b/base_delivery_carrier_label/reports.xml @@ -0,0 +1,15 @@ + + + + + + diff --git a/base_delivery_carrier_label/security/ir.model.access.csv b/base_delivery_carrier_label/security/ir.model.access.csv new file mode 100644 index 0000000000..fcde2c0e36 --- /dev/null +++ b/base_delivery_carrier_label/security/ir.model.access.csv @@ -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 diff --git a/base_delivery_carrier_label/stock.py b/base_delivery_carrier_label/stock.py new file mode 100644 index 0000000000..b347f36a98 --- /dev/null +++ b/base_delivery_carrier_label/stock.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Authors: David BEAL +# Sébastien BEAU +# Copyright (C) 2012-TODAY Akretion . +# 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 . +# +############################################################################## +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" diff --git a/base_delivery_carrier_label/stock_view.xml b/base_delivery_carrier_label/stock_view.xml new file mode 100644 index 0000000000..7e22a8c03f --- /dev/null +++ b/base_delivery_carrier_label/stock_view.xml @@ -0,0 +1,77 @@ + + + + + + + delivery.base.stock.picking.form + stock.picking.out + + + +