Comment 1 for bug 623889

Revision history for this message
Dukai Gábor (gdukai) wrote :

I forgot to mention that the example field is in the stock.warehouse.orderpoint class. Here's the whole code:
class stock_warehouse_orderpoint(osv.osv):
    _inherit = 'stock.warehouse.orderpoint'

    def _is_internal(self, cr, uid, ids, name, args, context=None):
        res = {}
        for op in self.browse(cr, uid, ids, context=context):
            res[op.id] = False
            proc_loc_id = op.location_id.procurement_location_id
            parent_ids = self.search(cr, uid, [
                ('location_id', '=', proc_loc_id.id),
                ('product_id', '=', op.product_id.id)])
            if parent_ids:
                res[op.id] = True
        return res

    def _get_orderpoints(self, cr, uid, ids, context):
        prod_ids = set()
        for op in self.browse(cr, uid, ids):
            prod_ids.add(op.product_id.id)
        return self.search(cr, uid, [('product_id', 'in', list(prod_ids))])

    def _get_locations(self, cr, uid, ids, context):
        return self.pool.get('stock.warehouse.orderpoint')\
            .search(cr, uid, [('location_id', 'in', ids)])

    _columns = {
        #bug: deleting an orderpoint won't trigger recalculation of the
        #other orderpoints with the same product_id
        'internal': fields.function(_is_internal, method=True, type='boolean',
            string='Internal', store={
                'stock.warehouse.orderpoint':
                    (_get_orderpoints, ['location_id'], 10),
                'stock.location': (_get_locations, ['procurement_location_id'], 20),
            }),
    }