~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to shipping_api_usps/sale.py

  • Committer: npgllc
  • Date: 2012-07-30 13:49:29 UTC
  • mfrom: (59.3.1 Shipping_USPS)
  • Revision ID: npgllc-20120730134929-kjevcau0o06ms4az
ADD: shipping_api_usps

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
 
6
#    Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>
 
20
#
 
21
##############################################################################
 
22
from osv import fields,osv
 
23
 
 
24
class sale_order(osv.osv):
 
25
    _inherit="sale.order"
 
26
    
 
27
    def _get_company_code(self, cr, user, context=None):
 
28
        res =  super(sale_order, self)._get_company_code(cr, user, context=context)
 
29
        res.append(('usps', 'USPS'))
 
30
        return res
 
31
    def _get_service_type_usps(self, cr, uid, context=None):
 
32
        return [
 
33
            ('First Class', 'First Class'),
 
34
            ('First Class HFP Commercial', 'First Class HFP Commercial'),
 
35
            ('FirstClassMailInternational', 'First Class Mail International'),
 
36
            ('Priority', 'Priority'),
 
37
            ('Priority Commercial', 'Priority Commercial'),
 
38
            ('Priority HFP Commercial', 'Priority HFP Commercial'),
 
39
            ('PriorityMailInternational', 'Priority Mail International'),
 
40
            ('Express', 'Express'),
 
41
            ('Express Commercial', 'Express Commercial'),
 
42
            ('Express SH', 'Express SH'),
 
43
            ('Express SH Commercial', 'Express SH Commercial'),
 
44
            ('Express HFP', 'Express HFP'),
 
45
            ('Express HFP Commercial', 'Express HFP Commercial'),
 
46
            ('ExpressMailInternational', 'Express Mail International'),
 
47
            ('ParcelPost', 'Parcel Post'),
 
48
            ('ParcelSelect', 'Parcel Select'),
 
49
            ('StandardMail', 'Standard Mail'),
 
50
            ('CriticalMail', 'Critical Mail'),
 
51
            ('Media', 'Media'),
 
52
            ('Library', 'Library'),
 
53
            ('All', 'All'),
 
54
            ('Online', 'Online'),
 
55
        ]
 
56
    
 
57
    def _get_first_class_mail_type_usps(self, cr, uid, context=None):
 
58
        return [
 
59
            ('Letter', 'Letter'),
 
60
            ('Flat', 'Flat'),
 
61
            ('Parcel', 'Parcel'),
 
62
            ('Postcard', 'Postcard'),
 
63
        ]
 
64
    
 
65
    def _get_container_usps(self, cr, uid, context=None):
 
66
        return [
 
67
            ('Variable', 'Variable'),
 
68
            ('Card', 'Card'),
 
69
            ('Letter', 'Letter'),
 
70
            ('Flat', 'Flat'),
 
71
            ('Parcel', 'Parcel'),
 
72
            ('Large Parcel', 'Large Parcel'),
 
73
            ('Irregular Parcel', 'Irregular Parcel'),
 
74
            ('Oversized Parcel', 'Oversized Parcel'),
 
75
            ('Flat Rate Envelope', 'Flat Rate Envelope'),
 
76
            ('Padded Flat Rate Envelope', 'Padded Flat Rate Envelope'),
 
77
            ('Legal Flat Rate Envelope', 'Legal Flat Rate Envelope'),
 
78
            ('SM Flat Rate Envelope', 'SM Flat Rate Envelope'),
 
79
            ('Window Flat Rate Envelope', 'Window Flat Rate Envelope'),
 
80
            ('Gift Card Flat Rate Envelope', 'Gift Card Flat Rate Envelope'),
 
81
            ('Cardboard Flat Rate Envelope', 'Cardboard Flat Rate Envelope'),
 
82
            ('Flat Rate Box', 'Flat Rate Box'),
 
83
            ('SM Flat Rate Box', 'SM Flat Rate Box'),
 
84
            ('MD Flat Rate Box', 'MD Flat Rate Box'),
 
85
            ('LG Flat Rate Box', 'LG Flat Rate Box'),
 
86
            ('RegionalRateBoxA', 'RegionalRateBoxA'),
 
87
            ('RegionalRateBoxB', 'RegionalRateBoxB'),
 
88
            ('Rectangular', 'Rectangular'),
 
89
            ('Non-Rectangular', 'Non-Rectangular'),
 
90
         ]
 
91
    
 
92
    def _get_size_usps(self, cr, uid, context=None):
 
93
        return [
 
94
            ('REGULAR', 'Regular'),
 
95
            ('LARGE', 'Large'),
 
96
         ]
 
97
    def action_ship_create(self, cr, uid, ids, *args):
 
98
        result = super(sale_order, self).action_ship_create(cr, uid, ids, *args)
 
99
        if result:
 
100
            for sale in self.browse(cr, uid, ids, context=None):
 
101
                if sale.ship_company_code=='usps':
 
102
                    pick_ids = self.pool.get('stock.picking').search(cr, uid, [('sale_id','=',sale.id),('type','=','out')], context=None)
 
103
                    if pick_ids:
 
104
                        vals = {
 
105
                                    'ship_company_code'     : 'usps',
 
106
                                    'logis_company'         : sale.logis_company and sale.logis_company.id or False,
 
107
                                    'usps_service_type'     : sale.usps_service_type,
 
108
                                    'usps_package_location' : sale.usps_package_location,
 
109
                                    'usps_first_class_mail_type' : sale.usps_first_class_mail_type,
 
110
                                    'usps_container'    : sale.usps_container,
 
111
                                    'usps_size'         : sale.usps_size,
 
112
                                    'usps_length'       : sale.usps_length,
 
113
                                    'usps_width'        : sale.usps_width,
 
114
                                    'usps_height'       : sale.usps_height,
 
115
                                    'usps_girth'        : sale.usps_girth
 
116
                                }
 
117
                        self.pool.get('stock.picking').write(cr, uid, pick_ids,vals, context=None)
 
118
        return result
 
119
    _columns= {
 
120
                    'ship_company_code': fields.selection(_get_company_code, 'Ship Company', method=True,  size=64),
 
121
                    'usps_service_type' : fields.selection(_get_service_type_usps, 'Service Type', size=100),
 
122
                    'usps_package_location' : fields.selection([
 
123
                            ('Front Door','Front Door'),
 
124
                            ('Back Door','Back Door'),
 
125
                            ('Side Door','Side Door'),
 
126
                            ('Knock on Door/Ring Bell','Knock on Door/Ring Bell'),
 
127
                            ('Mail Room','Mail Room'),
 
128
                            ('Office','Office'),
 
129
                            ('Reception','Reception'),
 
130
                            ('In/At Mailbox','In/At Mailbox'),
 
131
                            ('Other','Other'),
 
132
                       ],'Package Location', size=64),
 
133
                    'usps_first_class_mail_type' : fields.selection(_get_first_class_mail_type_usps, 'First Class Mail Type', size=50),
 
134
                    'usps_container' : fields.selection(_get_container_usps,'Container', size=100),
 
135
                    'usps_size' : fields.selection(_get_size_usps,'Size'),
 
136
                    'usps_length' : fields.float('Length'),
 
137
                    'usps_width' :  fields.float('Width'),
 
138
                    'usps_height' :  fields.float('Height'),
 
139
                    'usps_girth' :  fields.float('Girth'),
 
140
                }
 
141
    _defaults = {
 
142
        'usps_service_type'         : 'Priority',
 
143
        'usps_package_location'     : 'Front Door',
 
144
        'usps_first_class_mail_type': 'Parcel',
 
145
        'usps_size'                 : 'REGULAR',
 
146
        'usps_container'            : 'Variable',
 
147
 
 
148
    }
 
149
sale_order()
 
 
b'\\ No newline at end of file'