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
picking_form = '''<?xml version="1.0" encoding="utf-8"?>
29
<form string="Create pickings">
30
<label colspan="4" string="Do you really want to create the pickings ?" />
31
<field name="grouped" />
36
'grouped' : {'string':'Group the pickings', 'type':'boolean', 'default': lambda *a: True}
39
wrong_state_form = '''<?xml version="1.0" encoding="utf-8"?>
40
<form string="Create pickings">
41
<label string="One or more sale orders have are not confirmed" />
44
wrong_partner_form = '''<?xml version="1.0" encoding="utf-8"?>
45
<form string="Create pickings">
46
<label string="It is not possible to group sale orders from different partners" />
49
wrong_incoterm_form = '''<?xml version="1.0" encoding="utf-8"?>
50
<form string="Create pickings">
51
<label string="It is not possible to group sale orders with different incoterms" />
54
wrong_picking_policy_form = '''<?xml version="1.0" encoding="utf-8"?>
55
<form string="Create pickings">
56
<label string="It is not possible to group sale orders with different picking policies" />
59
wrong_shop_form = '''<?xml version="1.0" encoding="utf-8"?>
60
<form string="Create pickings">
61
<label string="It is not possible to group sale orders from different shops" />
64
def _checkState(self, cr, uid, data, context):
65
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
66
orders = order_obj.browse(cr,uid,data['ids'])
69
# draft: Presupuesto (borrador)
70
# progress : En Proceso (acceptados)
72
if order.state <> 'progress':
76
def _checkValues(self, cr, uid, data, context):
77
if data['form']['grouped']:
78
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
79
orders = order_obj.browse(cr,uid,data['ids'])
80
partner = orders[0].partner_id
81
incoterm = orders[0].incoterm
82
picking_policy = orders[0].picking_policy
83
shop = orders[0].shop_id
85
if partner != order.partner_id:
86
return 'wrong_partner'
87
if incoterm != order.incoterm:
88
return 'wrong_incoterm'
89
if picking_policy != order.picking_policy:
90
return 'wrong_picking_policy'
91
if shop != order.shop_id:
95
def _makePickings(self, cr, uid, data, context):
96
order_obj = pooler.get_pool(cr.dbname).get('sale.order')
99
order_obj.action_ship_create(cr, uid, data['ids'], data['form']['grouped'])
100
for id in data['ids']:
101
wf_service = netsvc.LocalService("workflow")
102
wf_service.trg_validate(uid, 'sale.order', id, 'manual_picking', cr)
104
# Establece la relación entre pedidos y albaranes
105
for o in order_obj.browse(cr, uid, data['ids'], context):
106
for i in o.picking_ids:
108
# Este return tipo ir.actions.act_window abre un nuevo formulario
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'
121
class make_picking(wizard.interface):
125
'result': {'type':'choice', 'next_state':_checkState}
129
'result' : {'type' : 'form',
130
'arch' : picking_form,
131
'fields' : picking_fields,
132
'state' : [('end', 'Cancel'),('check_values', 'Create pickings') ]}
136
'result' : {'type' : 'form',
137
'arch' : wrong_state_form,
139
'state' : [('end', 'Acept')]}
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')]}
176
'result' : {'type' : 'action',
177
'action' : _makePickings,
181
make_picking("sale_group.make_picking")