~moylop260-team/moylop260-project/saberysabor-dev-carlos

« back to all changes in this revision

Viewing changes to mrp_custom/wizard/wizard_divide_production.py

  • Committer: ferig1125
  • Date: 2012-01-10 23:16:27 UTC
  • Revision ID: fernandoig1125@hotmail.com-20120110231627-x6cw5jzu43xamdtw
[ADD][Modules Saber y Sabor]

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from mx.DateTime import *
 
2
import wizard
 
3
import netsvc
 
4
import ir
 
5
import pooler
 
6
from tools.misc import UpdateableStr, UpdateableDict
 
7
from osv import osv
 
8
import time
 
9
 
 
10
_moves_arch = UpdateableStr()
 
11
_moves_fields = UpdateableDict()
 
12
 
 
13
_form ='''<?xml version="1.0"?>
 
14
<form string="Dividir">
 
15
        <field name="qty"/>
 
16
</form>'''
 
17
 
 
18
_form2 ='''<?xml version="1.0"?>
 
19
<form string="Sustituir Producto">
 
20
        <field name="lista_id"/>
 
21
        <newline/>
 
22
        <field name="listas_ids"/>
 
23
</form>'''
 
24
 
 
25
 
 
26
 
 
27
_fields ={
 
28
        'qty': {'string':'Cantidad de divisiones a realizar?', 'type':'integer','required':True},
 
29
 
 
30
}
 
31
 
 
32
_fields2 ={
 
33
        'lista_id': {'string':'Lista Material', 'type':'many2one','relation':'mrp.bom'},
 
34
        'listas_ids': {'string':'Listas', 'type':'many2many', 'relation': 'mrp.remplaza','domain':"[('product_id','=',product_id)]"},
 
35
}
 
36
 
 
37
def _get_moves(self, cr, uid, data, context):
 
38
        res = {}
 
39
        lista=[]
 
40
        _moves_arch_lst = ['<?xml version="1.0"?>', '<form string="Divisiones">']
 
41
        for m in range(0,data['form']['qty']):
 
42
                _moves_arch_lst.append('<field name="move%s" />'% (m,))
 
43
                _moves_arch_lst.append('<newline/>')
 
44
                _moves_arch_lst.append('<field name="move2%s" />'% (m,))
 
45
                _moves_arch_lst.append('<field name="move3%s" />'% (m,))
 
46
                _moves_arch_lst.append('<separator string="" colspan="4"/>')
 
47
                _moves_fields['move%s' %m] = {'string': 'PRODUCCION-%s\nCantidad de productos a producir'%(m), 'type': 'integer'}
 
48
                _moves_fields['move2%s' %m] = {'string': 'Estacion', 'type': 'many2one','relation':'stock.location','domain':[('station_ok','=',True)]}
 
49
                _moves_fields['move3%s' %m] = {'string': 'Fecha', 'type': 'date'}
 
50
                _moves_arch_lst.append('<newline/>')
 
51
                res.setdefault('moves', []).append(m)
 
52
        _moves_arch_lst.append('</form>')
 
53
        _moves_arch.string = '\n'.join(_moves_arch_lst)
 
54
        return res
 
55
 
 
56
 
 
57
def _trae_listas(self, cr, uid, data, context):
 
58
        res = {}
 
59
        lista=[]
 
60
        obj = pooler.get_pool(cr.dbname).get('mrp.remplaza')
 
61
        query="""SELECT primer.bom_id,talla_id,default_code as sku,color_id,estilo_id,mrp_bom.name FROM 
 
62
                                (
 
63
                                SELECT bom_id,product_id FROM  mrp_bom 
 
64
                                WHERE mrp_bom.product_id=%s
 
65
                                )as primer
 
66
                        INNER JOIN  mrp_bom ON primer.bom_id=mrp_bom.id
 
67
                        JOIN product_product ON product_product.id=mrp_bom.product_id
 
68
                        JOIN product_template ON product_template.id=product_product.product_tmpl_id
 
69
                """%data['form']['product_id']
 
70
        cr.execute( query )
 
71
        #ids = filter(None, map(lambda x:x[0], cr.fetchall()))
 
72
        versiones=cr.dictfetchall()
 
73
        for ver in versiones:
 
74
                lista.append(obj.create(cr,uid,{'bom_id':ver['bom_id'],'sku':ver['sku'],'talla_id':ver['talla_id'],'color_id':ver['color_id'],'estilo_id':ver['estilo_id'],'nombre':ver['name']},context))
 
75
        data['form']['listas_ids']=lista
 
76
        return data['form']
 
77
 
 
78
 
 
79
def _actualizar(self, cr, uid, data, context):
 
80
        obj = pooler.get_pool(cr.dbname).get('mrp.production')
 
81
        obj_line = pooler.get_pool(cr.dbname).get('mrp.production.product.line')
 
82
        stock_obj = pooler.get_pool(cr.dbname).get('stock.move')
 
83
        res = {}
 
84
        total=0
 
85
        ordenes_ids=[]
 
86
        cantidad=obj.read(cr,uid,[data['id']],['product_qty'],context)
 
87
        state=obj.read(cr,uid,[data['id']],['state'],context)
 
88
        for m in range(0,data['form']['qty']):
 
89
                total +=data['form']['move%s'%m]
 
90
        if state[0]['state']!='draft':
 
91
                raise wizard.except_wizard('UserError','Solo Puedes Dividir Antes de Confirmar')
 
92
        if cantidad:
 
93
                if int(cantidad[0]['product_qty']) != total:
 
94
                        raise wizard.except_wizard('UserError','Cantidad No Coincide')
 
95
                query="""SELECT * FROM mrp_production
 
96
                                WHERE id=%s"""%data['id']
 
97
                cr.execute(query)
 
98
                nuevo=cr.dictfetchall()
 
99
                q2="""SELECT * FROM mrp_production_product_line
 
100
                                WHERE production_id=%s"""%data['id']
 
101
                cr.execute(q2)
 
102
                lineas=cr.dictfetchall()
 
103
                nom=nuevo[0]['name']
 
104
                obj.write(cr,uid,[data['id']],{'name':nom + '-1','product_qty':data['form']['move0'],'station_id':data['form']['move20'],'date_planned':data['form']['move30']})
 
105
                for t in range(1,data['form']['qty']):
 
106
                        id_name=int(t)+1
 
107
                        nuevo[0]['product_qty']=data['form']['move%s'%t]
 
108
                        nuevo[0]['station_id']=data['form']['move2%s'%t]
 
109
                        nuevo[0]['date_planned']=data['form']['move3%s'%t]
 
110
                        nuevo[0]['name']=nom + '-'+ str(id_name)
 
111
                        id_p=obj.create(cr,uid,nuevo[0],context)
 
112
                        ordenes_ids.append(id_p)
 
113
                ordenes_ids.append(data['id'])
 
114
                len = obj.action_compute(cr, uid, ordenes_ids, properties=[])
 
115
        else:
 
116
                raise wizard.except_wizard('UserError','Esta Orden Ya se Dividio')
 
117
        return res
 
118
 
 
119
def end(self, cr, uid, data, context):
 
120
        res={}
 
121
        obj = pooler.get_pool(cr.dbname).get('mrp.production')
 
122
        obj.unlink(cr,uid,[data['id']],context)
 
123
        return res
 
124
 
 
125
class wizard_divide_production(wizard.interface):
 
126
        
 
127
        states = {
 
128
                
 
129
                'init': {
 
130
                        'actions': [],
 
131
                        'result': {
 
132
                                'type': 'form', 
 
133
                                'arch': _form, 
 
134
                                'fields': _fields,
 
135
                                'state' : (('end', 'Cancel', 'gtk-cancel'),('dividir', 'Dividir', 'terp-gtk-go-back-rtl') )
 
136
                        },
 
137
                },
 
138
                
 
139
                'dividir': {
 
140
                        'actions': [_get_moves],
 
141
                        'result': {'type': 'form', 'arch': _moves_arch, 'fields': _moves_fields,
 
142
                                'state': (('end', 'Cancel', 'gtk-cancel'),('init', 'Regresar', 'terp-gtk-go-back-ltr'),('actualizar', 'Actualizar', 'terp-gtk-go-back-rtl') ),
 
143
                        },
 
144
                },
 
145
                
 
146
                
 
147
                'actualizar': {
 
148
                        'actions': [_actualizar],
 
149
                        'result': {
 
150
                                'type': 'state',
 
151
                                'state': 'end',
 
152
                        },
 
153
                },
 
154
                
 
155
        }
 
156
        
 
157
wizard_divide_production('wizard.divide.production')
 
 
b'\\ No newline at end of file'