-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsale.py
107 lines (97 loc) · 5.01 KB
/
sale.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# -*- coding: utf-8 -*-
##############################################################################
#
# 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
class sale_order(osv.osv):
_inherit = "sale.order"
def action_ship_create(self, cr, uid, ids, context=None):
pick_obj = self.pool.get('stock.picking')
result = super(sale_order, self).action_ship_create(cr, uid, ids, context=context)
if result:
for sale in self.browse(cr, uid, ids):
if sale.ship_company_code == 'ups':
pick_ids = pick_obj.search(cr, uid, [('sale_id', '=', sale.id), ('type', '=', 'out')], context=context)
if pick_ids:
vals = {
'ship_company_code': 'ups',
'logis_company': sale.logis_company and sale.logis_company.id or False,
'shipper': sale.ups_shipper_id and sale.ups_shipper_id.id or False,
'ups_service': sale.ups_service_id and sale.ups_service_id.id or False,
'ups_pickup_type': sale.ups_pickup_type,
'ups_packaging_type': sale.ups_packaging_type and sale.ups_packaging_type.id or False,
'ship_from_address':sale.ups_shipper_id and sale.ups_shipper_id.address and sale.ups_shipper_id.address.id or False,
'shipcharge':sale.shipcharge or False
}
pick_obj.write(cr, uid, pick_ids, vals)
else:
pick_ids = pick_obj.search(cr, uid, [('sale_id', '=', sale.id), ('type', '=', 'out')])
if pick_ids:
pick_obj.write(cr, uid, pick_ids, {'shipper': False, 'ups_service': False}, context=context)
return result
def _get_company_code(self, cr, user, context=None):
res = super(sale_order, self)._get_company_code(cr, user, context=context)
res.append(('ups', 'UPS'))
return list(set(res))
def onchange_service(self, cr, uid, ids, ups_shipper_id=False, context=None):
vals = {}
service_type_ids = []
if ups_shipper_id:
shipper_obj = self.pool.get('ups.account.shipping').browse(cr, uid, ups_shipper_id)
for shipper in shipper_obj.ups_shipping_service_ids:
service_type_ids.append(shipper.id)
domain = [('id', 'in', service_type_ids)]
return {'domain': {'ups_service_id': domain}}
_columns = {
'payment_method':fields.selection([
('cc_pre_auth', 'Credit Card – PreAuthorized'),
('invoice', 'Invoice'),
('cod', 'COD'),
('p_i_a', 'Pay In Advance'),
('pay_pal', 'Paypal'),
('no_charge', 'No Charge')], 'Payment Method'),
'ship_company_code': fields.selection(_get_company_code, 'Logistic Company', method=True, size=64),
'ups_shipper_id': fields.many2one('ups.account.shipping', 'Shipper'),
'ups_service_id': fields.many2one('ups.shipping.service.type', 'Service Type'),
'ups_pickup_type': fields.selection([
('01', 'Daily Pickup'),
('03', 'Customer Counter'),
('06', 'One Time Pickup'),
('07', 'On Call Air'),
('11', 'Suggested Retail Rates'),
('19', 'Letter Center'),
('20', 'Air Service Center'),
], 'Pickup Type'),
'ups_packaging_type': fields.many2one('shipping.package.type', 'Packaging Type')
}
def _get_sale_account(self, cr, uid, context=None):
if context is None:
context = {}
logsitic_obj = self.pool.get('logistic.company')
user_rec = self.pool.get('res.users').browse(cr , uid, uid, context)
logis_company = logsitic_obj.search(cr, uid, [])
if not logis_company:
return False
return logsitic_obj.browse(cr, uid, logis_company[0], context).ship_account_id.id
_defaults = {
'sale_account_id': _get_sale_account,
}
sale_order()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: