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

« back to all changes in this revision

Viewing changes to shipping_api/wizard/shipping_rate_calculation.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
 
 
25
 
class shipping_rate_wizard(osv.osv_memory):
26
 
    _inherit = 'shipping.rate.wizard'
27
 
    
28
 
    def _get_company_code(self, cr, user, context=None):
29
 
        return [('', '')]
30
 
    
31
 
    def onchange_logis_company(self, cr, uid, ids, logistic_company_id, context=None):
32
 
        company_code = ''
33
 
        if logistic_company_id:
34
 
            logis_comp_obj =  self.pool.get('logistic.company')
35
 
            company_code = logis_comp_obj.read(cr, uid, logistic_company_id, ['ship_company_code'], context=context )['ship_company_code']
36
 
        res =  {'value': {'ship_company_code': company_code}}
37
 
        return res
38
 
    
39
 
    def _get_rate_selection(self, cr, uid, context=None):
40
 
        
41
 
        if context is None:
42
 
            context = {}
43
 
        if context.get('active_model', False) == 'sale.order':
44
 
            sale_id = context.get('active_id', False)
45
 
            if sale_id:
46
 
                sale = self.pool.get('sale.order').browse(cr, uid, sale_id, context=context)
47
 
                if sale.rate_selection:
48
 
                    return sale.rate_selection
49
 
                return sale.company_id and sale.company_id.rate_selection or 'rate_card' 
50
 
        return 'rate_card'
51
 
    
52
 
    def default_get(self, cr, uid, fields, context=None):
53
 
        res = super(shipping_rate_wizard, self).default_get(cr, uid, fields, context=context)
54
 
        if context is None:
55
 
            context = {}
56
 
        if context.get('active_model', False) == 'sale.order':
57
 
            sale_id = context.get('active_id', False)
58
 
            if sale_id:
59
 
                sale = self.pool.get('sale.order').browse(cr, uid, sale_id, context=context)
60
 
                res.update({
61
 
                    'logis_company': sale.logis_company and sale.logis_company.id or False,
62
 
                    'ship_company_code': sale.ship_company_code,
63
 
                    'shipping_cost': sale.shipcharge
64
 
                    })
65
 
        elif context.get('active_model', False) == 'account.invoice':
66
 
            inv_id = context.get('active_id', False)
67
 
            invoice = self.pool.get('account.invoice').browse(cr, uid, inv_id, context=context)
68
 
            if inv_id:
69
 
                res.update({
70
 
                    'shipping_cost': invoice.shipcharge
71
 
                    })
72
 
        return res
73
 
                    
74
 
    def update_shipping_cost(self, cr, uid, ids, context=None):
75
 
        data = self.browse(cr, uid, ids[0], context=context)
76
 
        if context is None:
77
 
            context = {}
78
 
        if context.get('active_model', False) == 'sale.order':
79
 
            sale_id = context.get('active_id', False)
80
 
            if sale_id:
81
 
                self.pool.get('sale.order').write(cr, uid, [sale_id], {'rate_selection': data.rate_selection}, context=context)
82
 
        return super(shipping_rate_wizard, self).update_shipping_cost(cr, uid, ids, context=context)
83
 
    
84
 
    def get_rate(self, cr, uid, ids, context=None):
85
 
        return True
86
 
    
87
 
    _columns= {
88
 
        'rate_selection': fields.selection([('rate_card', 'Rate Card'), ('rate_request', 'Rate Request')], 'Ship Rate Method'),
89
 
        'logis_company': fields.many2one('logistic.company', 'Logistics Company', help='Name of the Logistics company providing the shipper services.'),
90
 
        'ship_company_code': fields.selection(_get_company_code, 'Ship Company', method=True, size=64),
91
 
        'status_message': fields.char('Status', size=128, readonly=True),
92
 
        }
93
 
    
94
 
    _defaults = {
95
 
        'rate_selection': _get_rate_selection,
96
 
        }
97
 
 
98
 
shipping_rate_wizard()
99
 
 
100
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'