265
265
'doc_state': move.picking_id.state,
266
266
'doc_model': 'stock.picking',
267
267
'doc_id': move.picking_id.id,
268
'doc_type': doc_type}, context=context)
268
'doc_type': doc_type})
269
269
elif not move.picking_id:
270
270
line_obj.create(cr, uid, {'problem_id': problem_id,
271
271
'doc_name': move.name,
272
272
'doc_state': move.state,
273
273
'doc_model': 'stock.move',
274
274
'doc_id': move.id,
275
'doc_type': 'Stock move'}, context=context)
275
'doc_type': 'Stock move'})
278
278
def _add_purchase_order(self, cr, uid, problem_id, po_ids, context=None):
288
288
'doc_state': order.state,
289
289
'doc_model': 'purchase.order',
290
290
'doc_id': order.id,
291
'doc_type': order.rfq_ok and 'Request for Quotation' or 'Purchase Order'}, context=context)
291
'doc_type': order.rfq_ok and 'Request for Quotation' or 'Purchase Order'})
294
294
def go_to_problems(self, cr, uid, ids, context=None):
319
319
doc = self.pool.get(wiz.real_model).browse(cr, uid, wiz.res_id, context=context)
320
320
pb_id = pb_obj.create(cr, uid, {'wizard_id': wiz.id,
321
'doc_name': doc.name}, context=context)
321
'doc_name': doc.name})
323
323
# For sales orders and procurement request
324
324
if wiz.real_model == 'sale.order':
330
330
elif wiz.real_model == 'tender':
331
331
order = self.pool.get('tender').browse(cr, uid, wiz.res_id, context=context)
332
332
po_ids = self._get_problem_tender(cr, uid, order, context=context)
335
pick_ids = list(set(pick_ids))
336
move_ids = list(set(move_ids))
337
proc_ids = list(set(proc_ids))
338
po_ids = list(set(po_ids))
339
so_ids = list(set(so_ids))
340
tender_ids = list(set(tender_ids))
341
invoice_ids = list(set(invoice_ids))
343
333
# Process all stock moves
344
334
self._add_stock_move_pb(cr, uid, pb_id, move_ids, context=context)
345
335
# Process all PO/RfQ
351
341
'doc_state': tender.state,
352
342
'doc_model': 'tender',
353
343
'doc_id': tender.id,
354
'doc_type': 'Tender'}, context=context)
344
'doc_type': 'Tender'})
355
345
# Search all procurement orders attached to the sale order
356
346
for proc in self.pool.get('procurement.order').browse(cr, uid, proc_ids, context=context):
357
347
pb_line_obj.create(cr, uid, {'problem_id': pb_id,
359
349
'doc_state': proc.state,
360
350
'doc_model': 'procurement.order',
361
351
'doc_id': proc.id,
362
'doc_type': 'Procurement Order'}, context=context)
352
'doc_type': 'Procurement Order'})
364
354
# Process all invoices
365
355
for inv in self.pool.get('account.invoice').browse(cr, uid, invoice_ids, context=context):
368
358
'doc_state': inv.state,
369
359
'doc_model': 'account.invoice',
370
360
'doc_id': inv.id,
371
'doc_type': 'Invoice'}, context=context)
361
'doc_type': 'Invoice'})
373
363
return {'type': 'ir.actions.act_window',
374
364
'res_model': 'documents.done.problem',
391
380
if self.pool.get(doc.real_model).browse(cr, uid, doc.res_id, context=context).state not in ('cancel', 'done'):
392
381
self.pool.get(doc.real_model).set_manually_done(cr, uid, doc.res_id, all_doc=all_doc, context=context)
394
if doc.real_model == 'sale.order' and self.pool.get(doc.real_model).read(cr, uid, doc.res_id, ['procurement_request'])['procurement_request']:
395
proc_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'procurement_request', 'procurement_request_form_view')
396
context.update({'view_id': proc_view and proc_view[1] or False})
397
self.pool.get(doc.real_model).log(cr, uid, doc.res_id, _('The Internal request \'%s\' has been closed.')%(doc.name), context=context)
399
self.pool.get(doc.real_model).log(cr, uid, doc.res_id, _('The %s \'%s\' has been closed.')%(self._get_model_name(doc.real_model), doc.name), context=context)
400
pb_ids = pb_obj.search(cr, uid, [('wizard_id', '=', doc.id)], context=context)
401
pb_obj.done_all_documents(cr, uid, pb_ids, all_doc=all_doc, context=context)
383
self.pool.get(doc.real_model).log(cr, uid, doc.res_id, _('The %s \'%s\' has been closed.')%(self._get_model_name(doc.real_model), doc.name), context=context)
403
385
if not context.get('direct_cancel', False):
404
386
return {'type': 'ir.actions.act_window_close'}
549
531
if invoice_state == 'draft':
550
532
wf_service.trg_validate(uid, line.doc_model, line.doc_id, 'invoice_cancel', cr)
551
533
# elif invoice_state not in ('cancel', 'paid'):
552
# raise osv.except_osv(_('Error'), _('You cannot set the SO to \'Closed\' because the following invoices are not Cancelled or Paid : %s') % ([map(x.name + '/') for x in error_inv_ids]))
534
# raise osv.except_osv(_('Error'), _('You cannot set the SO to \'Closed\' because the following invoices are not Cancelled or Paid : %s' % ([map(x.name + '/') for x in error_inv_ids])))
553
535
elif line.doc_model == 'tender':
554
self.pool.get('tender').set_manually_done(cr, uid, [line.doc_id], context=context)
536
wf_service.trg_validate(uid, line.doc_model, line.doc_id, 'manually_done', cr)
555
537
elif self.pool.get(line.doc_model).browse(cr, uid, line.doc_id, context=context).state not in ('cancel', 'done'):
556
538
self.pool.get(line.doc_model).set_manually_done(cr, uid, line.doc_id, all_doc=all_doc, context=context)
558
# return self.pool.get('documents.done.wizard').go_to_problems(cr, uid, [wiz.wizard_id.id], context=context)
540
return self.pool.get('documents.done.wizard').go_to_problems(cr, uid, [wiz.wizard_id.id], context=context)
560
# return {'type': 'ir.actions.act_window',
561
# 'res_model': 'documents.done.wizard',
562
# 'view_type': 'form',
563
# 'view_mode': 'tree',
564
# 'context': context,
542
return {'type': 'ir.actions.act_window',
543
'res_model': 'documents.done.wizard',
567
548
def cancel_document(self, cr, uid, ids, context=None):