~lambdasoftware/openerp-spain/7.0

« back to all changes in this revision

Viewing changes to extra_addons/sale_group/wizard/make_picking.py

  • Committer: Borja L.S.
  • Date: 2010-10-18 10:04:25 UTC
  • Revision ID: borjals@pexego.es-20101018100425-w1oxyw3qqkv3s90o
[REF] *: Refactorización para portar a 6.0 - Paso 1.

- Se han renombrado los módulos para usar la nomenclatura propuesta
  por OpenERP: l10n_es para el módulo base de localización (plan de 
  cuentas), l10n_es_* para el resto de módulos.

- Se eliminan los módulos extra_addons/* que deberían moverse a 
  los extra-addons genéricos (no son específicos de España).

- Se renombran los __terp__.py por __openerp__.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- encoding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (c) 2008 Pablo Rocandio. All Rights Reserved.
6
 
#    $Id$
7
 
#
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.
12
 
#
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.
17
 
#
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/>.
20
 
#
21
 
##############################################################################
22
 
 
23
 
import wizard
24
 
import netsvc
25
 
import pooler
26
 
 
27
 
 
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" />
32
 
</form>'''
33
 
 
34
 
 
35
 
picking_fields = {
36
 
    'grouped' : {'string':'Group the pickings', 'type':'boolean', 'default': lambda *a: True}
37
 
}
38
 
 
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" />
42
 
</form>'''
43
 
 
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" />
47
 
</form>'''
48
 
    
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" />
52
 
</form>'''
53
 
 
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" />
57
 
</form>'''
58
 
 
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" />
62
 
</form>'''
63
 
 
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'])
67
 
    for order in orders:
68
 
        # Estados:
69
 
        # draft: Presupuesto (borrador)
70
 
        # progress : En Proceso (acceptados)
71
 
        # cancel: Cancelado
72
 
        if order.state <> 'progress':
73
 
            return 'wrong_state'
74
 
    return 'confirm'
75
 
 
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
84
 
        for order in orders:
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:
92
 
                return 'wrong_shop'
93
 
    return 'picking'
94
 
 
95
 
def _makePickings(self, cr, uid, data, context):
96
 
    order_obj = pooler.get_pool(cr.dbname).get('sale.order')
97
 
    newinv = []
98
 
 
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)
103
 
 
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:
107
 
            newinv.append(i.id)
108
 
    # Este return tipo ir.actions.act_window abre un nuevo formulario
109
 
    return {
110
 
        'domain': "[('id','in', ["+','.join(map(str,newinv))+"])]",
111
 
        'name': 'Pickings',
112
 
        'view_type': 'form',
113
 
        'view_mode': 'tree,form',
114
 
        'res_model': 'stock.picking',
115
 
        'view_id': False,
116
 
        #'context': "{'type':'out_refund'}",
117
 
        'type': 'ir.actions.act_window'
118
 
    }
119
 
    #return {}
120
 
 
121
 
class make_picking(wizard.interface):
122
 
    states = {
123
 
        'init' : {
124
 
            'actions' : [],
125
 
            'result': {'type':'choice', 'next_state':_checkState}
126
 
        },
127
 
        'confirm' : {
128
 
            'actions' : [],
129
 
            'result' : {'type' : 'form',
130
 
                    'arch' : picking_form,
131
 
                    'fields' : picking_fields,
132
 
                    'state' : [('end', 'Cancel'),('check_values', 'Create pickings') ]}
133
 
        },
134
 
        'wrong_state' : {
135
 
            'actions' : [],
136
 
            'result' : {'type' : 'form',
137
 
                    'arch' : wrong_state_form,
138
 
                    'fields' : {},
139
 
                    'state' : [('end', 'Acept')]}
140
 
        },
141
 
        'check_values' : {
142
 
            'actions' : [],
143
 
            'result' : {'type' : 'choice',
144
 
                    'next_state':_checkValues}
145
 
        },    
146
 
        'wrong_partner' : {
147
 
            'actions' : [],
148
 
            'result' : {'type' : 'form',
149
 
                    'arch' : wrong_partner_form,
150
 
                    'fields' : {},
151
 
                    'state' : [('end', 'Acept')]}
152
 
        },
153
 
        'wrong_incoterm' : {
154
 
            'actions' : [],
155
 
            'result' : {'type' : 'form',
156
 
                    'arch' : wrong_incoterm_form,
157
 
                    'fields' : {},
158
 
                    'state' : [('end', 'Acept')]}
159
 
        }, 
160
 
        'wrong_picking_policy' : {
161
 
            'actions' : [],
162
 
            'result' : {'type' : 'form',
163
 
                    'arch' : wrong_picking_policy_form,
164
 
                    'fields' : {},
165
 
                    'state' : [('end', 'Acept')]}
166
 
        }, 
167
 
        'wrong_shop' : {
168
 
            'actions' : [],
169
 
            'result' : {'type' : 'form',
170
 
                    'arch' : wrong_shop_form,
171
 
                    'fields' : {},
172
 
                    'state' : [('end', 'Acept')]}
173
 
        }, 
174
 
        'picking' : {
175
 
            'actions' : [],
176
 
            'result' : {'type' : 'action',
177
 
                    'action' : _makePickings,
178
 
                    'state' : 'end'}
179
 
        },
180
 
    }
181
 
make_picking("sale_group.make_picking")