~stock-logistic-core-editors/carriers-deliveries/github-7.0

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# -*- coding: utf-8 -*-
##############################################################################
#
#    Author: Sébastien BEAU <sebastien.beau@akretion.com>
#    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'),
             ),
            string='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 Delivery Order."),
        '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'),
    }