1
# -*- coding: utf-8 -*-
2
##############################################################################
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>)
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.
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.
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/>
21
##############################################################################
23
from osv import fields, osv
25
class shipping_rate_wizard(osv.osv_memory):
26
_inherit = 'shipping.rate.wizard'
28
def _get_company_code(self, cr, user, context=None):
31
def onchange_logis_company(self, cr, uid, ids, logistic_company_id, context=None):
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}}
39
def _get_rate_selection(self, cr, uid, context=None):
43
if context.get('active_model', False) == 'sale.order':
44
sale_id = context.get('active_id', False)
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'
52
def default_get(self, cr, uid, fields, context=None):
53
res = super(shipping_rate_wizard, self).default_get(cr, uid, fields, context=context)
56
if context.get('active_model', False) == 'sale.order':
57
sale_id = context.get('active_id', False)
59
sale = self.pool.get('sale.order').browse(cr, uid, sale_id, context=context)
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
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)
70
'shipping_cost': invoice.shipcharge
74
def update_shipping_cost(self, cr, uid, ids, context=None):
75
data = self.browse(cr, uid, ids[0], context=context)
78
if context.get('active_model', False) == 'sale.order':
79
sale_id = context.get('active_id', False)
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)
84
def get_rate(self, cr, uid, ids, context=None):
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),
95
'rate_selection': _get_rate_selection,
98
shipping_rate_wizard()
100
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'