1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
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
##############################################################################
28
wrong_state_form = """<?xml version="1.0" encoding="utf-8"?>
29
<form string="Create pickings">
30
<separator string="One or more sale order line is not confirmed" />
33
wrong_partner_form = '''<?xml version="1.0" encoding="utf-8"?>
34
<form string="Create pickings">
35
<label string="It is not possible to group lines from sale orders from different partners" />
38
wrong_incoterm_form = '''<?xml version="1.0" encoding="utf-8"?>
39
<form string="Create pickings">
40
<label string="It is not possible to group lines from sale orders with different incoterms" />
43
wrong_picking_policy_form = '''<?xml version="1.0" encoding="utf-8"?>
44
<form string="Create pickings">
45
<label string="It is not possible to group lines from sale orders with different picking policies" />
48
wrong_shop_form = '''<?xml version="1.0" encoding="utf-8"?>
49
<form string="Create pickings">
50
<label string="It is not possible to group lines from sale orders with different shops" />
53
picking_form = """<?xml version="1.0" encoding="utf-8"?>
54
<form string="Create pickings">
55
<separator colspan="4" string="Do you really want to create the pickings ?" />
56
<field name="grouped" />
61
'grouped' : {'string':'Group the pickings', 'type':'boolean', 'default': lambda *a: True}
64
def _checkState(self, cr, uid, data, context):
65
order_line_obj = pooler.get_pool(cr.dbname).get('sale.order.line')
66
order_lines = order_line_obj.browse(cr,uid,data['ids'])
67
for order_line in order_lines:
68
print order_line.state
69
if order_line.state <> 'confirmed':
73
def _checkValues(self, cr, uid, data, context):
74
if data['form']['grouped']:
75
order_line_obj = pooler.get_pool(cr.dbname).get('sale.order.line')
76
order_lines = order_line_obj.browse(cr,uid,data['ids'])
77
partner = order_lines[0].order_id.partner_id
78
incoterm = order_lines[0].order_id.incoterm
79
picking_policy = order_lines[0].order_id.picking_policy
80
shop = order_lines[0].order_id.shop_id
81
for order_line in order_lines:
82
if partner != order_line.order_id.partner_id:
83
return 'wrong_partner'
84
if incoterm != order_line.order_id.incoterm:
85
return 'wrong_incoterm'
86
if picking_policy != order_line.order_id.picking_policy:
87
return 'wrong_picking_policy'
88
if shop != order_line.order_id.shop_id:
92
def _makePickings(self, cr, uid, data, context):
93
order_line_obj = pooler.get_pool(cr.dbname).get('sale.order.line')
94
#pool = pooler.get_pool(cr.dbname)
96
for line in order_line_obj.browse(cr,uid,data['ids']):
97
if line.state == 'confirmed':
99
if not line.order_id.id in lines_ids:
100
lines_ids[line.order_id.id] = [line.id]
102
lines_ids[line.order_id.id].append(line.id)
104
lines_ids.setdefault(line.order_id.id,[]).append(line.id)
105
#pool.get('sale.order').action_ship_create(cr, uid, lines_ids.keys(), data['form']['grouped'], lines_ids = lines_ids)
106
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
107
order_obj.action_ship_create(cr, uid, lines_ids.keys(), data['form']['grouped'], lines_ids = lines_ids)
110
'domain': "[('id','in', ["+','.join(map(str,newinv))+"])]",
113
'view_mode': 'tree,form',
114
'res_model': 'stock.picking',
116
#'context': "{'type':'out_refund'}",
117
'type': 'ir.actions.act_window'
123
class line_make_picking(wizard.interface):
127
'result': {'type':'choice', 'next_state':_checkState}
133
'arch': picking_form,
134
'fields': picking_fields,
137
('check_values', 'Create pickings')
143
'result' : {'type' : 'choice',
144
'next_state':_checkValues}
148
'result' : {'type' : 'form',
149
'arch' : wrong_partner_form,
151
'state' : [('end', 'Acept')]}
155
'result' : {'type' : 'form',
156
'arch' : wrong_incoterm_form,
158
'state' : [('end', 'Acept')]}
160
'wrong_picking_policy' : {
162
'result' : {'type' : 'form',
163
'arch' : wrong_picking_policy_form,
165
'state' : [('end', 'Acept')]}
169
'result' : {'type' : 'form',
170
'arch' : wrong_shop_form,
172
'state' : [('end', 'Acept')]}
175
'actions' : [_makePickings],
176
'result' : {'type': 'state', 'state': 'end'}
180
'result' : {'type' : 'form',
181
'arch' : wrong_state_form,
183
'state' : [('end', 'Acept')]}
187
line_make_picking("sale_group.make_line_picking")