stored function fields don't get updated on unlink() if the trigger is the same object (5.0)

Bug #623889 reported by Dukai Gábor on 2010-08-25
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Status tracked in Trunk
5.0
Triaged
Undecided
Jay Vora (Serpent Consulting Services)
Trunk
Fix Released
Undecided
Unassigned

Bug Description

Hi!
5.0 latest bzr.
Stored function fields that calculate values depending on other records from the same object, don't get updated on unlink().

Example code:
        '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),
            }),
Here, _get_orderpoints() won't be called on unlink() because of the following code in orm.orm.unlink():
        for order, object, store_ids, fields in result_store:
            if object != self._name:

Related branches

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),
            }),
    }

I think this should receive high or at least medium importance. Function fields are too important on the ORM so we need to be sure they work properly.

Hello,

I have checked this issue in current latest updated code and your specified function is called at the time of unlink the related record.

Thanks.

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers