~serpent-consulting-services/openerp-usa/shipping_api_6-1

« back to all changes in this revision

Viewing changes to partner_address_validation/fedex_account.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

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
 
 
23
 
from osv import fields,osv
24
 
import netsvc
25
 
 
26
 
 
27
 
class fedex_account(osv.osv):
28
 
    _name = "fedex.account"
29
 
    
30
 
    '''
31
 
    FedEx Account details
32
 
    '''
33
 
    _columns = {
34
 
                    'name'          : fields.char('Comapny Name', size=64),
35
 
                    'fedex_key'     : fields.char('FedEx Key', size=64),
36
 
                    'fedex_password': fields.char('Password', size=128),
37
 
                    'fedex_account_number'  : fields.char('Account Number', size=64),
38
 
                    'fedex_meter_number'    : fields.char('Meter Number', size=64),
39
 
                    'test_mode'             : fields.boolean('Test Mode'),
40
 
                }
41
 
    _defaults  = {
42
 
                    'test_mode' : lambda * a: True,
43
 
                  }
44
 
 
45
 
    def address_validation(self,cr, uid, address_id, context={}):
46
 
        """ This function is called from the wizard.Performs the actual computing in address validation """
47
 
        status=0
48
 
        error_msg=''
49
 
        
50
 
        fedex_accounts = self.pool.get('fedex.account').search(cr, uid, [], context={})
51
 
        if not fedex_accounts:
52
 
            warning = {
53
 
                    'title': "No FedEx account!",
54
 
                    'message': "No FedEx account found for validation."
55
 
                }
56
 
 
57
 
            return {'warning': warning} 
58
 
        
59
 
        if fedex_accounts and address_id:
60
 
            fedex_account = self.pool.get('fedex.account').browse(cr, uid, fedex_accounts[0], context=context)
61
 
            if type(address_id) == type([]):
62
 
                address_id=address_id[0]
63
 
                
64
 
            partner_address = self.pool.get('res.partner.address').browse(cr, uid, address_id, context=context)
65
 
            
66
 
            from fedex.config import FedexConfig
67
 
            
68
 
            config_obj = FedexConfig(key=fedex_account.fedex_key,
69
 
                             password=fedex_account.fedex_password,
70
 
                             account_number=fedex_account.fedex_account_number,
71
 
                             meter_number=fedex_account.fedex_meter_number,
72
 
                             use_test_server=fedex_account.test_mode)
73
 
 
74
 
        
75
 
            from fedex.services.address_validation_service import FedexAddressValidationRequest
76
 
            
77
 
            address = FedexAddressValidationRequest(config_obj)
78
 
 
79
 
            address1 = address.create_wsdl_object_of_type('AddressToValidate')
80
 
            address1.CompanyName = partner_address.partner_id and partner_address.partner_id.name or ''
81
 
            address1.Address.StreetLines =  [ partner_address.street, partner_address.street2 ]
82
 
            address1.Address.City = partner_address.city
83
 
            address1.Address.StateOrProvinceCode = partner_address.state_id and partner_address.state_id.code or ''
84
 
            address1.Address.PostalCode = partner_address.zip_id and partner_address.zip_id.zipcode or partner_address.zip
85
 
            address1.Address.CountryCode = partner_address.country_id and  partner_address.country_id.code or ''
86
 
            address1.Address.Residential = False
87
 
            
88
 
            address.add_address(address1)
89
 
            
90
 
            ret_list = []
91
 
            try:
92
 
                address.send_request()
93
 
                response=address.response
94
 
                
95
 
                
96
 
                print "Response : ", response
97
 
                
98
 
                #Possible values ERROR, FAILURE, NOTE, WARNING, SUCCESS
99
 
                if response.HighestSeverity=='SUCCESS':
100
 
                    error_msg  = "The address is valid"
101
 
                    status=1
102
 
                    
103
 
                elif response.HighestSeverity=='ERROR' or response.HighestSeverity=='FAILURE':
104
 
                    error_msg = str(response.Notifications[0].Message)
105
 
                
106
 
                
107
 
                
108
 
            except Exception, e:
109
 
                print "Error : ", e
110
 
                error_msg =  error_msg + str(e)
111
 
                    
112
 
            return {
113
 
                        'addr_status':status,
114
 
                        'error_msg':error_msg,
115
 
                        'address_list':ret_list
116
 
                    }
117
 
            
118
 
 
119
 
fedex_account()
120
 
 
121
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: