forked from OCA/connector-magento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelivery.py
74 lines (61 loc) · 2.62 KB
/
delivery.py
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
# -*- coding: utf-8 -*-
##############################################################################
#
# Authors: Guewen Baconnier, Sébastien Beau
# Copyright (C) 2010 BEAU Sébastien
# Copyright 2011-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 import models, fields, api
# TODO magento.delivery.carrier & move specific stuff
class DeliveryCarrier(models.Model):
""" Adds Magento specific fields to ``delivery.carrier``
``magento_code``
Code of the carrier delivery method in Magento.
Example: ``colissimo_express``
``magento_tracking_title``
Display name of the carrier for the tracking in Magento.
Example: Colissimo Express
``magento_carrier_code``
General code of the carrier, the first part of the ``magento_code``.
Example: ``colissimo`` for the method ``colissimo_express``.
``magento_export_tracking``
Defines if the tracking numbers should be exported to Magento.
"""
_inherit = "delivery.carrier"
magento_code = fields.Char(
string='Magento Carrier Code',
required=False,
)
magento_tracking_title = fields.Char(
string='Magento Tracking Title',
required=False,
)
# in Magento, the delivery method is something like that:
# tntmodule2_tnt_basic
# where the first part before the first _ is always the carrier code
# in this example, the carrier code is tntmodule2
magento_carrier_code = fields.Char(
compute='_compute_carrier_code',
string='Magento Base Carrier Code',
)
magento_export_tracking = fields.Boolean(string='Export tracking numbers',
default=True)
@api.depends('magento_code')
def _compute_carrier_code(self):
for carrier in self:
if carrier.magento_code:
self.magento_carrier_code = carrier.magento_code.split('_')[0]