29
29
super(picking, self).__init__(cr, uid, name, context=context)
30
30
self.localcontext.update({
32
'get_qtytotal':self._get_qtytotal
32
'get_qtytotal':self._get_qtytotal,
34
'_get_parent':self._get_parent,
35
'_get_childs':self._get_childs,
36
'_get_move_lines' : self._get_move_lines,
40
def _get_move_lines(self, pick_id):
43
context = self.localcontext
44
pick = self.pool.get('stock.picking').browse(cr, uid, pick_id)
49
for move in pick.move_lines:
51
'name' : '[' + move.product_id.default_code + '] ' + move.product_id.name,
52
'lot' : move.prodlot_id and move.prodlot_id.name or '',
54
'location' : move.location_id and move.location_id.name or '',
55
'quantity' : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
63
#===============================================================================
64
# move_lines = self.pool.get('stock.move').search(cr, uid, [('picking_id','=',pick.id)], order="parent_bom_id,id desc", offset=0, limit=None,
65
# context=context, count=False )
67
#===============================================================================
69
self.cr.execute("SELECT id from stock_move where picking_id='%s' order by parent_bom_id;"%(pick.id))
70
fetchdata = self.cr.fetchall() or None
73
if isinstance(fetchdata, list):
74
move_lines = [t[0] for t in fetchdata]
76
move_lines = fetchdata[0]
78
moves = self.pool.get('stock.move').browse(cr, uid, move_lines, context=context)
83
'state' : 'init', # added, assigned bom
87
'parent_product' : False
90
for i, move_data in enumerate(move_datas):
91
move=move_data['object']
92
for order_line in sale.order_line:
93
if order_line.product_id and order_line.product_id.bom_ids:
94
bom=order_line.product_id.bom_ids[0]
95
if bom.type=='assembly':
97
#Check the product present in bom lines
98
for bom_line in bom.bom_lines:
99
if bom_line.product_id.id == move.product_id.id:
102
# if product is a sub component
104
order_data[order_line.id] = 1
105
move_datas[i]['parent_product'] = order_line.product_id.id
106
move_datas[i]['bom'] = bom_line
107
move_datas[i]['bom_type'] = 'assembly'
108
move_datas[i]['order_line'] = order_line
111
for i, move_data in enumerate(move_datas):
112
move=move_data['object']
113
if move_data['bom_type'] == 'assembly':
114
if order_data[move_data['order_line'].id]:
116
'name' : ' [' + move_data['order_line'].product_id.code + '] ' + move_data['order_line'].product_id.name,
124
order_data[move_data['order_line'].id] = 0
127
'name' : '[' + move.product_id.default_code + '] ' + move.product_id.name,
128
'lot' : move.prodlot_id and move.prodlot_id.name or '',
129
'state' : move.state,
130
'location' : move.location_id and move.location_id.name or '',
131
'quantity' : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
137
'name' : '[' + move.product_id.default_code + '] ' + move.product_id.name,
138
'lot' : move.prodlot_id and move.prodlot_id.name or '',
139
'state' : move.state,
140
'location' : move.location_id and move.location_id.name or '',
141
'quantity' : self.formatLang(move.product_qty) + ' ' + move.product_uom.name,
148
def _get_parent(self,pick_id):
151
context=self.localcontext
152
move_obj=self.pool.get('stock.move')
153
move_ids=move_obj.search(cr,uid,[('picking_id','=',pick_id),("parent_bom_id","!=",False)])
154
moves=move_obj.browse(cr,uid,move_ids,context=context)
156
production=move.kit_id
158
product_qty=production.product_qty
159
sale_id=move.sale_id.id
161
parent_move_ids=move_obj.search(cr,uid,[("sale_id","=",sale_id),
162
("product_qty","=",product_qty),
163
("product_id","=",production.product_id.id)])
164
parent_moves=move_obj.browse(cr,uid,parent_move_ids)
165
#print "parent_move_ids",parent_move_ids
166
# return {'child_moves':moves,"parent_moves":parent_moves}
171
def _get_childs(self,pick_id):
174
context=self.localcontext
175
move_obj=self.pool.get('stock.move')
176
move_ids=move_obj.search(cr,uid,[('picking_id','=',pick_id),("parent_bom_id","!=",False)])
177
print move_ids,'====================move_ids================================'
178
return move_obj.browse(cr,uid,move_ids,context=context)
34
180
def _get_qtytotal(self,move_lines):
36
182
uom = move_lines[0].product_uom.name