~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to documents_done/documents_done.py

  • Committer: jf
  • Date: 2012-03-27 14:38:50 UTC
  • Revision ID: jf@tempo4-20120327143850-e41gh5zyjam3un11
[FIX] Default values

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    _description = 'Documents not \'Done\''
39
39
    _auto = False
40
40
 
41
 
    def _get_selection(self, cr, uid, context={}):
 
41
    def _get_selection(self, cr, uid, context=None):
42
42
        states = []
43
43
        if not context:
44
44
            context = {}
57
57
 
58
58
        return states
59
59
 
60
 
    def _get_model_from_state(self, cr, uid, state, context={}):
 
60
    def _get_model_from_state(self, cr, uid, state, context=None):
61
61
        '''
62
62
        Returns the model which have the value of state in the selection field 'state'.
63
63
        '''
76
76
 
77
77
        return models, states
78
78
 
79
 
    def _get_state(self, cr, uid, ids, field_name, args, context={}):
 
79
    def _get_state(self, cr, uid, ids, field_name, args, context=None):
80
80
        '''
81
81
        Returns the good value according to the doc type
82
82
        '''
83
83
        res = {}
 
84
        if not context:
 
85
            context = {}
84
86
 
85
87
        for doc in self.browse(cr, uid, ids, context=context):
86
88
            context.update({'models': [doc.real_model], 'db_value': True})
90
92
 
91
93
        return res
92
94
    
93
 
    def _search_state(self, cr, uid, obj, name, args, context={}):
 
95
    def _search_state(self, cr, uid, obj, name, args, context=None):
94
96
        '''
95
97
        Returns all documents according to state
96
98
        '''
103
105
 
104
106
        return [('id', 'in', ids)]
105
107
 
106
 
    def _get_related_stock_moves(self, cr, uid, order, field, context={}):
 
108
    def _get_related_stock_moves(self, cr, uid, order, field, context=None):
107
109
        '''
108
110
        Returns all stock moves related to an order (sale.order/purchase.order)
109
111
        '''
112
114
            line_ids.append(line.id)
113
115
        return self.pool.get('stock.move').search(cr, uid, [('state', 'not in', ['cancel', 'done']), (field, 'in', line_ids)], context=context)
114
116
 
115
 
    def _get_problem_sale_order(self, cr, uid, order, context={}):
 
117
    def _get_problem_sale_order(self, cr, uid, order, context=None):
116
118
        '''
117
119
        Check if all stock moves, all procurement orders, all purchase orders
118
120
        and all stock picking generated from the sale order is closed or canceled
119
121
        '''
 
122
        if not context:
 
123
            context = {}
120
124
        move_ids = self._get_related_stock_moves(cr, uid, order, 'sale_line_id', context=context)
121
125
        proc_ids = []
122
126
        po_ids = []
153
157
        else:
154
158
            return move_ids, proc_ids, po_ids, tender_ids, invoice_ids
155
159
 
156
 
    def _get_problem_purchase_order(self, cr, uid, order, context={}):
 
160
    def _get_problem_purchase_order(self, cr, uid, order, context=None):
157
161
        '''
158
162
        Check if all stock moves, all invoices
159
163
        and all stock picking generated from the purchase order is closed or canceled
160
164
        '''
 
165
        if not context:
 
166
            context = {}
161
167
        move_ids = self._get_related_stock_moves(cr, uid, order, 'purchase_line_id', context=context)
162
168
        so_ids = []
163
169
        invoice_ids = []
174
180
        else:
175
181
            return move_ids, so_ids, invoice_ids
176
182
 
177
 
    def _get_problem_tender(self, cr, uid, order, context={}):
 
183
    def _get_problem_tender(self, cr, uid, order, context=None):
178
184
        '''
179
185
        Check if all request for quotations and all purchase orders
180
186
        generated from the tender is closed or canceled
181
187
        '''
 
188
        if not context:
 
189
            context = {}
182
190
        po_ids = self.pool.get('purchase.order').search(cr, uid, [('state', 'not in', ['cancel', 'done']), ('tender_id', '=', order.id)], context=context)
183
191
        if context.get('count', False):
184
192
            return po_ids or False
185
193
        else:
186
194
            return po_ids
187
195
 
188
 
    def _get_problem(self, cr, uid, ids, field_name, args, context={}):
 
196
    def _get_problem(self, cr, uid, ids, field_name, args, context=None):
189
197
        '''
190
198
        Returns True if at least one doc stop the manually done processe
191
199
        '''
 
200
        if not context:
 
201
            context = {}
192
202
        res = {}
193
203
        c = context.copy()
194
204
        c.update({'count': True})
231
241
            
232
242
        return 'Undefined'
233
243
 
234
 
    def _add_stock_move_pb(self, cr, uid, problem_id, moves, context={}):
 
244
    def _add_stock_move_pb(self, cr, uid, problem_id, moves, context=None):
235
245
        '''
236
246
        Add a line for each moves
237
247
        '''
 
248
        if not context:
 
249
            context = {}
238
250
        line_obj = self.pool.get('documents.done.problem.line')
239
251
        picking_ids = []
240
252
        for move in self.pool.get('stock.move').browse(cr, uid, moves, context=context):
260
272
                                          'doc_type': 'Stock move'})
261
273
        return
262
274
 
263
 
    def _add_purchase_order(self, cr, uid, problem_id, po_ids, context={}):
 
275
    def _add_purchase_order(self, cr, uid, problem_id, po_ids, context=None):
264
276
        '''
265
277
        Add line for each PO/RfQ
266
278
        '''
 
279
        if not context:
 
280
            context = {}
267
281
        line_obj = self.pool.get('documents.done.problem.line')
268
282
        for order in self.pool.get('purchase.order').browse(cr, uid, po_ids, context=context):
269
283
            line_obj.create(cr, uid, {'problem_id': problem_id,
274
288
                                      'doc_type': order.rfq_ok and 'Request for Quotation' or 'Purchase Order'})
275
289
        return
276
290
 
277
 
    def go_to_problems(self, cr, uid, ids, context={}):
 
291
    def go_to_problems(self, cr, uid, ids, context=None):
278
292
        '''
279
293
        Returns a wizard with all documents posing a problem
280
294
        '''
 
295
        if not context:
 
296
            context = {}
281
297
        pb_obj = self.pool.get('documents.done.problem')
282
298
        pb_line_obj = self.pool.get('documents.done.problem.line')
283
299
        move_obj = self.pool.get('stock.move')
350
366
                'target': 'popup'}
351
367
                        
352
368
 
353
 
    def cancel_line(self, cr, uid, ids, all_doc=True, context={}):
 
369
    def cancel_line(self, cr, uid, ids, all_doc=True, context=None):
354
370
        '''
355
371
        Set the document to done state
356
372
        '''
475
491
class documents_done_problem(osv.osv_memory):
476
492
    _name = 'documents.done.problem'
477
493
 
478
 
    def _get_errors(self, cr, uid, ids, field_name, args, context={}):
 
494
    def _get_errors(self, cr, uid, ids, field_name, args, context=None):
479
495
        '''
480
496
        Returns True if at least one problem is found
481
497
        '''
 
498
        if not context:
 
499
            context = {}
482
500
        res = {}
483
501
 
484
502
        for doc in self.browse(cr, uid, ids, context=context):
495
513
        'pb_lines': fields.one2many('documents.done.problem.line', 'problem_id', string='Lines'),
496
514
    }
497
515
 
498
 
    def done_all_documents(self, cr, uid, ids, all_doc=True, context={}):
 
516
    def done_all_documents(self, cr, uid, ids, all_doc=True, context=None):
499
517
        '''
500
518
        For all documents, check the state of the doc and send the signal
501
519
        of 'manually_done' if needed
502
520
        '''
 
521
        if not context:
 
522
            context = {}
503
523
        wf_service = netsvc.LocalService("workflow")
504
524
        for wiz in self.browse(cr, uid, ids, context=context):
505
525
            for line in wiz.pb_lines:
522
542
                'view_mode': 'tree',
523
543
                'target': 'crush'}
524
544
 
525
 
    def cancel_document(self, cr, uid, ids, context={}):
 
545
    def cancel_document(self, cr, uid, ids, context=None):
526
546
        '''
527
547
        Cancel the document
528
548
        '''
 
549
        if not context:
 
550
            context = {}
529
551
        for wiz in self.browse(cr, uid, ids, context=context):
530
552
            return self.pool.get('documents.done.wizard').cancel_line(cr, uid, [wiz.wizard_id.id], all_doc=True, context=context)
531
553
 
536
558
class documents_done_problem_line(osv.osv_memory):
537
559
    _name = 'documents.done.problem.line'
538
560
 
539
 
    def _get_state(self, cr, uid, ids, field_name, arg, context={}):
 
561
    def _get_state(self, cr, uid, ids, field_name, arg, context=None):
540
562
        '''
541
563
        Return the state of the related doc
542
564
        '''
570
592
        'doc_id': fields.integer(string='Doc. Id'),
571
593
    }
572
594
 
573
 
    def go_to_doc(self, cr, uid, ids, context={}):
 
595
    def go_to_doc(self, cr, uid, ids, context=None):
574
596
        '''
575
597
        Open the form of the related doc
576
598
        '''
 
599
        if not context:
 
600
            context = {}
577
601
        for item in self.browse(cr, uid, ids, context=context):
578
602
            return {'type': 'ir.actions.act_window',
579
603
                    'res_model': item.doc_model,