-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock_packages.py
executable file
·73 lines (62 loc) · 3.26 KB
/
stock_packages.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
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
# Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
##############################################################################
from openerp.osv import fields, osv
from openerp.tools.translate import _
from . import api
class stock_packages(osv.osv):
_inherit = "stock.packages"
def cancel_postage(self, cr, uid, ids, context=None):
for package in self.browse(cr, uid, ids, context=context):
if package.shipping_company_name.lower() != "usps":
continue
usps_config = api.v1.get_config(cr, uid, sale=package.pick_id.sale_id, context=context)
test = package.pick_id.logis_company.test_mode
if hasattr(package, "tracking_no") and package.tracking_no:
try:
response = api.v1.cancel_shipping(usps_config, package, shipper=None, test=test)
except Exception, e:
self.pool.get('stock.packages').write(cr, uid, package.id, {'ship_message': str(e)}, context=context)
return {
'type': 'ir.actions.client',
'tag': 'action_warn',
'name': _('Exception'),
'params': {'title': _('Exception'), 'text': str(e), 'sticky': True}
}
if hasattr(response, "error") or not response.refunds[0].refunded:
err = response.error if hasattr(response, "error") else response.refunds[0].message
self.pool.get('stock.packages').write(cr, uid, package.id, {'ship_message': err}, context=context)
return {
'type': 'ir.actions.client',
'tag': 'action_warn',
'name': _('Failure'),
'params': {
'title': _('Package #%s Cancellation Failed') % package.packge_no,
'text': err,
'sticky': True
}
}
else:
self.pool.get('stock.packages').write(cr, uid, package.id, {
'ship_message' : 'Shipment Cancelled', 'tracking_no': ''
}, context=context)
return super(stock_packages, self).cancel_postage(cr, uid, ids, context=context)
stock_packages()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: