1
from mx.DateTime import *
6
from tools.misc import UpdateableStr, UpdateableDict
10
_moves_arch = UpdateableStr()
11
_moves_fields = UpdateableDict()
13
_form ='''<?xml version="1.0"?>
14
<form string="Dividir">
18
_form2 ='''<?xml version="1.0"?>
19
<form string="Sustituir Producto">
20
<field name="lista_id"/>
22
<field name="listas_ids"/>
28
'qty': {'string':'Cantidad de divisiones a realizar?', 'type':'integer','required':True},
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)]"},
37
def _get_moves(self, cr, uid, data, context):
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)
57
def _trae_listas(self, cr, uid, data, context):
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
63
SELECT bom_id,product_id FROM mrp_bom
64
WHERE mrp_bom.product_id=%s
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']
71
#ids = filter(None, map(lambda x:x[0], cr.fetchall()))
72
versiones=cr.dictfetchall()
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
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')
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')
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']
98
nuevo=cr.dictfetchall()
99
q2="""SELECT * FROM mrp_production_product_line
100
WHERE production_id=%s"""%data['id']
102
lineas=cr.dictfetchall()
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']):
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=[])
116
raise wizard.except_wizard('UserError','Esta Orden Ya se Dividio')
119
def end(self, cr, uid, data, context):
121
obj = pooler.get_pool(cr.dbname).get('mrp.production')
122
obj.unlink(cr,uid,[data['id']],context)
125
class wizard_divide_production(wizard.interface):
135
'state' : (('end', 'Cancel', 'gtk-cancel'),('dividir', 'Dividir', 'terp-gtk-go-back-rtl') )
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') ),
148
'actions': [_actualizar],
157
wizard_divide_production('wizard.divide.production')
b'\\ No newline at end of file'