~openerp-spain-team/openerp-spain/6.0-git

« back to all changes in this revision

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

  • Committer: Borja L.S.
  • Date: 2010-10-18 10:04:25 UTC
  • Revision ID: git-v1:271c47a993616dbba60585d48b8b98d603199d93
[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 ir
26
 
import pooler
27
 
 
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" />
31
 
</form>"""
32
 
 
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" />
36
 
</form>'''
37
 
 
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" />
41
 
</form>'''
42
 
 
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" />
46
 
</form>'''
47
 
 
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" />
51
 
</form>'''
52
 
 
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" />
57
 
</form>
58
 
"""
59
 
 
60
 
picking_fields = {
61
 
    'grouped' : {'string':'Group the pickings', 'type':'boolean', 'default': lambda *a: True}
62
 
}
63
 
 
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':
70
 
            return 'wrong_state'
71
 
    return 'confirm'
72
 
 
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:
89
 
                return 'wrong_shop'
90
 
    return 'picking'
91
 
 
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)
95
 
    lines_ids = {}
96
 
    for line in order_line_obj.browse(cr,uid,data['ids']):
97
 
        if line.state == 'confirmed':
98
 
            """
99
 
            if not line.order_id.id in lines_ids:
100
 
                lines_ids[line.order_id.id] = [line.id]
101
 
            else:
102
 
                lines_ids[line.order_id.id].append(line.id)
103
 
            """
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)
108
 
    """
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
 
    """
120
 
    return {}
121
 
 
122
 
 
123
 
class line_make_picking(wizard.interface):
124
 
    states = {
125
 
        'init' : {
126
 
            'actions' : [],
127
 
            'result': {'type':'choice', 'next_state':_checkState}
128
 
        },
129
 
        'confirm' : {
130
 
            'actions': [],
131
 
            'result': {
132
 
                'type': 'form',
133
 
                'arch': picking_form,
134
 
                'fields': picking_fields,
135
 
                'state': [
136
 
                    ('end', 'Cancel'),
137
 
                    ('check_values', 'Create pickings')
138
 
                ]
139
 
            }
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' : [_makePickings],
176
 
            'result' : {'type': 'state', 'state': 'end'}
177
 
        },
178
 
        'wrong_state' : {
179
 
            'actions' : [],
180
 
            'result' : {'type' : 'form',
181
 
                    'arch' : wrong_state_form,
182
 
                    'fields' : {},
183
 
                    'state' : [('end', 'Acept')]}
184
 
        },
185
 
    }
186
 
 
187
 
line_make_picking("sale_group.make_line_picking")