~camptocamp/stock-logistic-flows/7.0-picking_dispatch-check-availability

« back to all changes in this revision

Viewing changes to product_serial/stock.py

[MRG] product_serial: add button to visualize prodlots currently presents from a location

Show diffs side-by-side

added added

removed removed

Lines of Context:
296
296
 
297
297
        return res
298
298
 
 
299
    def _last_location_id_search(self, cr, uid, obj, name, args, context=None):
 
300
        ops = ['=', ]
 
301
        prodlot_ids = ()
 
302
        if not len(args):
 
303
            return []
 
304
        prodlot_ids = []
 
305
        for a in args:
 
306
            operator = a[1]
 
307
            value = a[2]
 
308
            if not operator in ops:
 
309
                raise osv.except_osv(_('Error !'), _('Operator %s not supported in searches for last_location_id (product.product).' % operator))
 
310
            if operator == '=':
 
311
                cr.execute(
 
312
                    "select distinct prodlot_id "\
 
313
                    "from stock_report_prodlots "\
 
314
                    "where location_id = %s and qty > 0 ",
 
315
                    (value, ))
 
316
                prodlot_ids = filter(None, map(lambda x:x[0], cr.fetchall()))
 
317
        return [('id','in',tuple(prodlot_ids))]
 
318
 
299
319
    _columns = {
300
 
        'last_location_id': fields.function(_last_location_id,
 
320
        'last_location_id': fields.function(_last_location_id, fnct_search=_last_location_id_search,
301
321
                                    type="many2one", relation="stock.location",
302
322
                                    string="Last location",
303
323
                                    help="Display the current stock location of this production lot"),