230
192
self.update(cr, uid, [], context=c)
234
def update_lines(self, cr, uid, ids, context=None):
235
location_obj = self.pool.get('stock.location')
236
data_obj = self.pool.get('ir.model.data')
237
line_obj = self.pool.get('stock.mission.report.line')
238
product_obj = self.pool.get('product.product')
239
# Search considered SLocation
240
stock_location_id = data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_stock')
241
if stock_location_id:
242
stock_location_id = stock_location_id[1]
243
internal_loc = location_obj.search(cr, uid, [('usage', '=', 'internal')], context=context)
244
central_loc = location_obj.search(cr, uid, [('central_location_ok', '=', True)], context=context)
245
cross_loc = location_obj.search(cr, uid, [('cross_docking_location_ok', '=', True)], context=context)
246
stock_loc = location_obj.search(cr, uid, [('location_id', 'child_of', stock_location_id),
247
('id', 'not in', cross_loc),
248
('central_location_ok', '=', False)], context=context)
249
cu_loc = location_obj.search(cr, uid, [('usage', '=', 'internal'), ('location_category', '=', 'consumption_unit')], context=context)
250
secondary_location_id = data_obj.get_object_reference(cr, uid, 'msf_config_locations', 'stock_location_intermediate_client_view')
251
if secondary_location_id:
252
secondary_location_id = secondary_location_id[1]
253
secondary_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', secondary_location_id)], context=context)
255
cu_loc = location_obj.search(cr, uid, [('location_id', 'child_of', cu_loc)], context=context)
256
central_loc = location_obj.search(cr, uid, [('location_id', 'child_of', central_loc)], context=context)
258
# Check if the instance is a coordination or a project
260
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
261
coordo = self.pool.get('msf.instance').search(cr, uid, [('level', '=', 'coordo')], context=context)
262
if company.instance_id.level == 'project' and coordo:
263
coordo_id = self.pool.get('msf.instance').browse(cr, uid, coordo[0], context=context).instance
267
cr.execute('''SELECT m.product_id, m.product_qty, m.product_uom, p.name, m.id
269
LEFT JOIN stock_picking s ON m.picking_id = s.id
270
LEFT JOIN res_partner p ON s.partner_id2 = p.id
271
WHERE s.type = 'in' AND m.state in ('confirmed', 'waiting', 'assigned')''')
273
in_pipe_moves = cr.fetchall()
274
for product_id, qty, uom, partner, move_id in in_pipe_moves:
275
line_id = line_obj.search(cr, uid, [('product_id', '=', product_id),
276
('mission_report_id', '=', id)])
278
line = line_obj.browse(cr, uid, line_id[0])
279
if uom != line.product_id.uom_id.id:
280
qty = self.pool.get('product.uom')._compute_qty(cr, uid, uom, qty, line.product_id.uom_id.id)
282
vals = {'in_pipe_qty': 0.00,
283
'in_pipe_coor_qty': 0.00,
286
vals['in_pipe_qty'] = vals['in_pipe_qty'] + qty
288
if partner == coordo_id:
289
vals['in_pipe_coor_qty'] = vals['in_pipe_coor_qty'] + qty
291
line_obj.write(cr, uid, line.id, vals)
295
SELECT id, product_id, product_uom, product_qty, location_id, location_dest_id
298
AND id not in (SELECT move_id FROM mission_move_rel WHERE mission_id = %s)
302
cr.execute('INSERT INTO mission_move_rel VALUES (%s, %s)' % (id, move[0]))
303
product = product_obj.browse(cr, uid, move[1])
304
line_id = line_obj.search(cr, uid, [('product_id', '=', move[1]),
305
('mission_report_id', '=', id)])
307
line = line_obj.browse(cr, uid, line_id[0])
308
qty = self.pool.get('product.uom')._compute_qty(cr, uid, move[2], move[3], product.uom_id.id)
309
vals = {'internal_qty': line.internal_qty or 0.00,
310
'stock_qty': line.stock_qty or 0.00,
311
'central_qty': line.central_qty or 0.00,
312
'cross_qty': line.cross_qty or 0.00,
313
'secondary_qty': line.secondary_qty or 0.00,
314
'cu_qty': line.cu_qty or 0.00,
317
if move[4] in internal_loc:
318
vals['internal_qty'] = vals['internal_qty'] - qty
319
if move[4] in stock_loc:
320
vals['stock_qty'] = vals['stock_qty'] - qty
321
if move[4] in central_loc:
322
vals['central_qty'] = vals['central_qty'] - qty
323
if move[4] in cross_loc:
324
vals['cross_qty'] = vals['cross_qty'] - qty
325
if move[4] in secondary_location_ids:
326
vals['secondary_qty'] = vals['secondary_qty'] - qty
327
if move[4] in cu_loc:
328
vals['cu_qty'] = vals['cu_qty'] - qty
330
if move[5] in internal_loc:
331
vals['internal_qty'] = vals['internal_qty'] + qty
332
if move[5] in stock_loc:
333
vals['stock_qty'] = vals['stock_qty'] + qty
334
if move[5] in central_loc:
335
vals['central_qty'] = vals['central_qty'] + qty
336
if move[5] in cross_loc:
337
vals['cross_qty'] = vals['cross_qty'] + qty
338
if move[5] in secondary_location_ids:
339
vals['secondary_qty'] = vals['secondary_qty'] + qty
340
if move[5] in cu_loc:
341
vals['cu_qty'] = vals['cu_qty'] + qty
343
vals.update({'internal_val': vals['internal_qty'] * product.standard_price})
344
line_obj.write(cr, uid, line.id, vals)
348
def _get_export_csv(self, cr, uid, ids, product_values, context=None):
350
Get the XML files of the stock mission report.
351
This method generates 4 files (according to option set) :
352
* 1 file with no split of WH and no valuation
353
* 1 file with no split of WH and valuation
354
* 1 file with split of WH and valuation
355
* 1 file with split aof WH and valuation
357
context = context or {}
358
if isinstance(ids, (int, long)):
361
def set_data(request, report_id, line, data_name,):
363
cr.execute(request, (report_id, line['id']))
365
product_amc = line['product_id'][0] in product_values and product_values[line['product_id'][0]]['product_amc'] or 0.00
366
reviewed_consumption = line['product_id'][0] in product_values and product_values[line['product_id'][0]]['reviewed_consumption'] or 0.00
367
for r in cr.dictfetchall():
368
data += r[data_name] % (product_amc, reviewed_consumption)
370
logging.getLogger('Mission stock report').warning("""An error is occured when compute the consumption values for product at mission stock report file generation. Data: \n %s""" % data_name)
375
# for report in self.browse(cr, uid, ids, context=context):
376
for report_id in ids:
377
# No split, no valuation
379
# No split, valuation
381
# Split, no valuation
387
l.product_id AS product_id,
390
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
391
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
392
replace(l.default_code, '%%', '%%%%'))),
394
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
395
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
396
replace(pt.name, '%%', '%%%%'))),
398
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
399
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
400
replace(pu.name, '%%', '%%%%'))),
402
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
403
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
404
trim(to_char(l.internal_qty, '999999999999.999')))),
406
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
407
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
408
trim(to_char(l.wh_qty, '999999999999.999')))),
410
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
411
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
412
trim(to_char(l.cross_qty, '999999999999.999')))),
414
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
415
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
416
trim(to_char(l.secondary_qty, '999999999999.999')))),
418
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
419
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
420
trim(to_char(l.cu_qty, '999999999999.999')))),
422
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
423
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
426
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
427
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
430
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
431
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
432
trim(to_char(l.in_pipe_qty, '999999999999.999'))))
436
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
437
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
438
replace(l.default_code, '%%', '%%%%'))),
440
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
441
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
442
replace(pt.name, '%%', '%%%%'))),
444
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
445
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
446
replace(pu.name, '%%', '%%%%'))),
448
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
449
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
450
trim(to_char(l.internal_qty, '999999999999.999')))),
452
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
453
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
454
trim(to_char(l.stock_qty, '999999999999.999')))),
456
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
457
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
458
trim(to_char(l.central_qty, '999999999999.999')))),
460
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
461
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
462
trim(to_char(l.cross_qty, '999999999999.999')))),
464
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
465
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
466
trim(to_char(l.secondary_qty, '999999999999.999')))),
468
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
469
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
470
trim(to_char(l.cu_qty, '999999999999.999')))),
472
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
473
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
476
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
477
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
480
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
481
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
482
trim(to_char(l.in_pipe_qty, '999999999999.999'))))
486
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
487
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
488
replace(l.default_code, '%%', '%%%%'))),
490
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
491
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
492
replace(pt.name, '%%', '%%%%'))),
494
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
495
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
496
replace(pu.name, '%%', '%%%%'))),
498
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
499
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
500
trim(to_char(pt.standard_price, '999999999999.999')))),
502
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
503
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
506
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
507
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
508
trim(to_char(l.internal_qty, '999999999999.999')))),
510
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
511
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
512
trim(to_char((l.internal_qty * pt.standard_price), '999999999999.999')))),
514
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
515
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
516
trim(to_char(l.wh_qty, '999999999999.999')))),
518
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
519
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
520
trim(to_char(l.cross_qty, '999999999999.999')))),
522
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
523
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
524
trim(to_char(l.secondary_qty, '999999999999.999')))),
526
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
527
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
528
trim(to_char(l.cu_qty, '999999999999.999')))),
530
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
531
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
534
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
535
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
538
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
539
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
540
trim(to_char(l.in_pipe_qty, '999999999999.999'))))
544
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
545
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
546
replace(l.default_code, '%%', '%%%%'))),
548
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
549
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
550
replace(pt.name, '%%', '%%%%'))),
552
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
553
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
554
replace(pu.name, '%%', '%%%%'))),
556
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
557
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
558
trim(to_char((l.internal_qty * pt.standard_price), '999999999999.999')))),
560
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
561
xmlelement(name Data, xmlattributes('String' as "ss:Type"),
564
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
565
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
566
trim(to_char(l.internal_qty, '999999999999.999')))),
568
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
569
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
570
trim(to_char((l.internal_qty * pt.standard_price), '999999999999.999')))),
572
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
573
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
574
trim(to_char(l.stock_qty, '999999999999.999')))),
576
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
577
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
578
trim(to_char(l.central_qty, '999999999999.999')))),
580
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
581
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
582
trim(to_char(l.cross_qty, '999999999999.999')))),
584
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
585
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
586
trim(to_char(l.secondary_qty, '999999999999.999')))),
588
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
589
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
590
trim(to_char(l.cu_qty, '999999999999.999')))),
592
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
593
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
596
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
597
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
600
xmlelement(name Cell, xmlattributes('ssBorder' as "ss:StyleID"),
601
xmlelement(name Data, xmlattributes('Number' as "ss:Type"),
602
trim(to_char(l.in_pipe_qty, '999999999999.999'))))
604
FROM stock_mission_report_line l
605
LEFT JOIN product_product pp ON l.product_id = pp.id
606
LEFT JOIN product_template pt ON pp.product_tmpl_id = pt.id
607
LEFT JOIN product_uom pu ON pt.uom_id = pu.id
608
LEFT JOIN res_currency rc ON pp.currency_id = rc.id
609
WHERE l.mission_report_id = %s'''
611
cr.execute(request, (report_id, ))
612
res = cr.dictfetchall()
615
product_amc = line['product_id'] in product_values and product_values[line['product_id']]['product_amc'] or 0.00
616
reviewed_consumption = line['product_id'] in product_values and product_values[line['product_id']]['reviewed_consumption'] or 0.00
617
ns_nv_data += replace_all(line['ns_nv_data'] % (product_amc, reviewed_consumption))
618
ns_v_data += replace_all(line['ns_v_data'] % (product_amc, reviewed_consumption))
619
s_nv_data += replace_all(line['s_nv_data'] % (product_amc, reviewed_consumption))
620
s_v_data += replace_all(line['s_v_data'] % (product_amc, reviewed_consumption))
622
logging.getLogger('Mission stock report').warning("""An error is occured when generate the mission stock report file. Data: \n %s""" % line)
624
for data, field in [(ns_nv_data, 'ns_nv_vals'), (ns_v_data, 'ns_v_vals'), (s_nv_data, 's_nv_vals'), (s_v_data, 's_v_vals')]:
625
self.write(cr, uid, [report_id], {field: data}, context=context)
627
self.write(cr, uid, [report_id], {'export_ok': True}, context=context)
631
197
stock_mission_report()
634
200
class stock_mission_report_line(osv.osv):
635
201
_name = 'stock.mission.report.line'
636
202
_description = 'Mission stock report line'
637
_order = 'default_code'
639
204
def _get_product_type_selection(self, cr, uid, context=None):
640
205
return self.pool.get('product.template').PRODUCT_TYPE
642
207
def _get_product_subtype_selection(self, cr, uid, context=None):
643
208
return self.pool.get('product.template').PRODUCT_SUBTYPE
645
210
def onChangeSearchNomenclature(self, cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=True, context=None):
646
211
return self.pool.get('product.product').onChangeSearchNomenclature(cr, uid, id, position, type, nomen_manda_0, nomen_manda_1, nomen_manda_2, nomen_manda_3, num=num, context=context)
648
213
def _get_nomen_s(self, cr, uid, ids, fields, *a, **b):
754
294
'in_pipe_coor_val': fields.float(digits=(16,2), string='In Pipe from Coord.'),
755
295
'updated': fields.boolean(string='Updated'),
756
296
'full_view': fields.related('mission_report_id', 'full_view', string='Full view', type='boolean', store=True),
757
'move_ids': fields.many2many('stock.move', 'mission_line_move_rel', 'line_id', 'move_id', string='Noves'),
761
'internal_qty': 0.00,
762
'internal_val': 0.00,
770
'secondary_qty': 0.00,
771
'secondary_val': 0.00,
776
'in_pipe_coor_qty': 0.00,
777
'in_pipe_coor_val': 0.00,
299
def _get_request(self, cr, uid, location_ids, product_id):
301
Browse the good values and give the result
303
obj = self.pool.get('report.stock.move')
305
if isinstance(location_ids, (int, long)):
306
location_ids = [location_ids]
308
if not isinstance(product_id, (int, long)):
309
raise osv.except_osv(_('Error'), _('You can\'t build the request for some products !'))
311
minus_ids = obj.search(cr, uid, [('location_id', 'in', location_ids),
312
('product_id', '=', product_id),
313
('state', '=', 'done')])
315
plus_ids = obj.search(cr, uid, [('location_dest_id', 'in', location_ids),
316
('product_id', '=', product_id),
317
('state', '=', 'done')])
320
for r in obj.browse(cr, uid, plus_ids):
322
for r in obj.browse(cr, uid, minus_ids):
780
327
def update_full_view_line(self, cr, uid, ids, context=None):
782
if self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.instance_id.level == 'project':
786
request = '''SELECT l.product_id AS product_id,
787
sum(l.internal_qty) AS internal_qty,
788
sum(l.stock_qty) AS stock_qty,
789
sum(l.central_qty) AS central_qty,
790
sum(l.cross_qty) AS cross_qty,
791
sum(l.secondary_qty) AS secondary_qty,
792
sum(l.cu_qty) AS cu_qty,
793
sum(l.in_pipe_qty) AS in_pipe_qty,
794
sum(l.in_pipe_coor_qty) AS in_pipe_coor_qty,
795
sum(l.internal_qty)*t.standard_price AS internal_val
796
FROM stock_mission_report_line l
798
stock_mission_report m
799
ON l.mission_report_id = m.id
802
ON l.product_id = p.id
805
ON p.product_tmpl_id = t.id
806
WHERE m.full_view = False
807
AND (l.internal_qty != 0.00
808
OR l.stock_qty != 0.00
809
OR l.central_qty != 0.00
810
OR l.cross_qty != 0.00
811
OR l.secondary_qty != 0.00
813
OR l.in_pipe_qty != 0.00
814
OR l.in_pipe_coor_qty != 0.00)
815
GROUP BY l.product_id, t.standard_price'''
820
mission_report_id = self.pool.get('stock.mission.report').search(cr, uid, [('full_view', '=', True)], context=context)
822
line_ids = self.search(cr, uid, [('mission_report_id.full_view', '=', True), ('product_id', '=', line[0])], context=context)
824
if not mission_report_id:
826
line_id = self.create(cr, uid, {'mission_report_id': mission_report_id[0],
827
'product_id': line[0]}, context=context)
829
line_id = line_ids[0]
831
in_pipe = line[7] or 0.00
328
for line in self.browse(cr, uid, ids, context=context):
329
line_ids = self.search(cr, uid, [('mission_report_id', '!=', line.mission_report_id.id), ('product_id', '=', line.product_id.id)], context=context)
330
lines = self.browse(cr, uid, line_ids, context=context)
346
in_pipe_not_coor_qty = 0.00
347
in_pipe_not_coor_val = 0.00
350
if self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.instance_id.level == 'project':
354
internal_qty += l.internal_qty
355
internal_val += l.internal_val
356
stock_qty += l.stock_qty
357
stock_val += l.stock_val
358
central_qty += l.central_qty
359
central_val += l.central_val
360
cross_qty += l.cross_qty
361
cross_val += l.cross_val
362
secondary_qty += l.secondary_qty
363
secondary_val += l.secondary_val
366
in_pipe_qty += l.in_pipe_qty
367
in_pipe_val += l.in_pipe_val
368
in_pipe_not_coor_qty += l.in_pipe_coor_qty
369
in_pipe_not_coor_val += l.in_pipe_coor_qty
832
371
if not is_project:
833
in_pipe = (line[7] or 0.00) - (line[8] or 0.00)
835
self.write(cr, uid, [line_id], {'internal_qty': line[1] or 0.00,
836
'internal_val': line[9] or 0.00,
837
'stock_qty': line[2] or 0.00,
838
'central_qty': line[3] or 0.00,
839
'cross_qty': line[4] or 0.00,
840
'secondary_qty': line[5] or 0.00,
841
'cu_qty': line[6] or 0.00,
842
'in_pipe_qty': line[7] or 0.00,
843
'in_pipe_coor_qty': line[8] or 0.00,}, context=context)
372
in_pipe_qty = in_pipe_qty - in_pipe_not_coor_qty
373
in_pipe_val = in_pipe_val - in_pipe_not_coor_val
375
self.write(cr, uid, [line.id], {'product_amc': line.product_id.product_amc,
376
'reviewed_consumption': line.product_id.reviewed_consumption,
377
'internal_qty': internal_qty,
378
'internal_val': internal_val,
379
'stock_qty': stock_qty,
380
'stock_val': stock_val,
381
'central_qty': central_qty,
382
'central_val': central_val,
383
'cross_qty': cross_qty,
384
'cross_val': cross_val,
385
'secondary_qty': secondary_qty,
386
'secondary_val': secondary_val,
389
'in_pipe_qty': in_pipe_qty,
390
'in_pipe_val': in_pipe_val,
391
'in_pipe_coor_qty': in_pipe_not_coor_qty,
392
'in_pipe_coor_val': in_pipe_not_coor_val}, context=context)
396
def update(self, cr, uid, ids, context=None):
403
if isinstance(ids, (int, long)):
406
location_obj = self.pool.get('stock.location')
407
data_obj = self.pool.get('ir.model.data')
409
stock_location_id = data_obj.get_object_reference(cr, uid, 'stock', 'stock_location_stock')
410
if stock_location_id:
411
stock_location_id = stock_location_id[1]
413
# Check if the instance is a coordination or a project
415
company = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id
416
coordo = self.pool.get('msf.instance').search(cr, uid, [('level', '=', 'coordo')], context=context)
417
if company.instance_id.level == 'project' and coordo:
418
coordo_id = self.pool.get('msf.instance').browse(cr, uid, coordo[0], context=context).instance
420
# Search considered SLocation
421
internal_loc = location_obj.search(cr, uid, [('usage', '=', 'internal')], context=context)
422
central_loc = location_obj.search(cr, uid, [('central_location_ok', '=', True)], context=context)
423
cross_loc = location_obj.search(cr, uid, [('cross_docking_location_ok', '=', True)], context=context)
424
stock_loc = location_obj.search(cr, uid, [('location_id', 'child_of', stock_location_id),
425
('id', 'not in', cross_loc),
426
('central_location_ok', '=', False)], context=context)
427
cu_loc = location_obj.search(cr, uid, [('usage', '=', 'internal'), ('location_category', '=', 'consumption_unit')], context=context)
428
secondary_location_id = data_obj.get_object_reference(cr, uid, 'msf_config_locations', 'stock_location_intermediate_client_view')
429
if secondary_location_id:
430
secondary_location_id = secondary_location_id[1]
431
secondary_location_ids = location_obj.search(cr, uid, [('location_id', 'child_of', secondary_location_id)], context=context)
433
for line in self.browse(cr, uid, ids, context=context):
434
# In case of full report
435
if line.mission_report_id.full_view:
438
standard_price = line.product_id.standard_price
443
internal_qty = self._get_request(cr, uid, internal_loc, line.product_id.id)
444
internal_val = internal_qty*standard_price
450
stock_qty = self._get_request(cr, uid, stock_loc, line.product_id.id)
451
stock_val = stock_qty*standard_price
453
# Central stock locations
457
central_loc = location_obj.search(cr, uid, [('location_id', 'child_of', central_loc)], context=context)
458
central_qty = self._get_request(cr, uid, central_loc, line.product_id.id)
459
central_val = central_qty*standard_price
461
# Cross-docking locations
465
cross_loc = location_obj.search(cr, uid, [('location_id', 'child_of', cross_loc)], context=context)
466
cross_qty = self._get_request(cr, uid, cross_loc, line.product_id.id)
467
cross_val = cross_qty*standard_price
469
# Secondary stock locations
472
if secondary_location_ids != False:
473
secondary_qty = self._get_request(cr, uid, secondary_location_ids, line.product_id.id)
474
secondary_val = secondary_qty*standard_price
476
# Consumption unit locations
480
cu_loc = location_obj.search(cr, uid, [('location_id', 'child_of', cu_loc)], context=context)
481
cu_qty = self._get_request(cr, uid, cu_loc, line.product_id.id)
482
cu_val = cu_qty*standard_price
486
in_pipe_not_coord_qty = 0.00
487
cr.execute('''SELECT m.product_qty, m.product_uom, p.name
489
LEFT JOIN stock_picking s ON m.picking_id = s.id
490
LEFT JOIN res_partner p ON s.partner_id2 = p.id
491
WHERE m.type = 'in' AND m.state in ('confirmed', 'waiting', 'assigned')
492
AND m.product_id = %s''' % line.product_id.id)
493
moves = cr.fetchall()
494
for qty, uom, partner in moves:
495
if uom != line.product_id.uom_id.id:
496
qty = self.pool.get('product.uom')._compute_qty(cr, uid, uom, qty, line.product_id.uom_id.id)
499
if partner == coordo_id:
500
in_pipe_not_coord_qty += qty
502
in_pipe_val = in_pipe_qty*standard_price
503
in_pipe_not_coord_val = in_pipe_not_coord_qty*standard_price
505
values = {'product_amc': line.product_id.product_amc,
506
'reviewed_consumption': line.product_id.reviewed_consumption,
507
'internal_qty': internal_qty,
508
'internal_val': internal_val,
509
'stock_qty': stock_qty,
510
'stock_val': stock_val,
511
'central_qty': central_qty,
512
'central_val': central_val,
513
'cross_qty': cross_qty,
514
'cross_val': cross_val,
515
'secondary_qty': secondary_qty,
516
'secondary_val': secondary_val,
519
'in_pipe_qty': in_pipe_qty,
520
'in_pipe_val': in_pipe_val,
521
'in_pipe_coor_qty': in_pipe_not_coord_qty,
522
'in_pipe_coor_val': in_pipe_not_coord_val,
525
line_read = self.read(cr, uid, line.id, values.keys(), context=context)
526
for k in values.keys():
527
if line_read[k] != values[k]:
528
values.update({'updated': True})
530
self.write(cr, uid, [line.id], values, context=context)
847
533
stock_mission_report_line()