This question has been flagged

I added a functionnal field on stock.picking model, I want to have this field, on the list of fields to choose, when you try to filter on fields, using the openerp filter tool. How this can be possible ?

As it's for payed and delivered functionnal fields on sale.order, I want to put my field among the choosable fields on advanced research option, on the filter. 

Many thanks.

Avatar
Discard
Best Answer

This has been discussed numerous times albeit with different context: by default function fields are not stored in the database and cannot be used for filtering/domain/sorting unless if you implement fnct_search or set the store attribute to True.

Avatar
Discard
Author

I have already values computed for this functionnal field, when I add the store=True parameter, it raises error that the column of this functionnal field does not exist on database. Do I have to add store=True only when there is no values computed for this field ?

Author

I'm inheriting with "orm.Model" should I do it with osv.osv so that the field can be stored on database ?

orm.Model is just an alias for osv.osv. They are pointing to the same object/class. So, it is not the issue. I don't quite get what you mean by "Do I have to add store=True only when there is no values computed for this field ?". Also by "I have already values computed for this functionnal field, when I add the store=True parameter, it raises error that the column of this functionnal field does not exist on database.". Exact wording of error will help. If you previously already have a field with the same name, it may cause problem, though I'm not sure what it will be exactly.

store=True is defined for a column/field. So, it will be applicable whether the function used to calculate the column/field return value or not. In fact they MUST return value, although the value can be NULL or 0.0

Author

I mean that I created the functionnal field, without the store=True parameter, and i have data on this field, it means that on the view containing this field, i already created records. and when I add the store=True parameter, for the functionnal field "amount_bl" for example it raises error : ProgrammingError: column stock_picking.amount_bl does not exist LINE 1: ...stock_picking."num_bl",stock_picking."commercial",stock_pick...

You need to upgrade the module first.

Author Best Answer

@Ivan : To Explain more my situation : First of all, I created the functionnal field without the store parameter (i forgot), it's on stock.picking.out model, (stock_picking table). Then, users created "delivery orders", so this functionnal field has computed values. So, right now, when I add the store parameter, into the functionnal field "amount_bl" for example, it raises error : ProgrammingError: column stock_picking.amount_bl does not exist LINE 1: ...stock_picking."num_bl",stock_picking."commercial",stock_pick...

I wonder if that error comes from the fact that users have already created delivery orders, and does not find where to store it.? (a supposition).

                                                            EDITED ANWSER :

@Ivan : When updating the module an error raises : 

File "/opt/openerp/server/openerp/addons/add_bl_valcr/stock.py", line 23, in _amount_order so_record = self.pool.get('sale.order').browse(cr, uid, so_id, context=None) AttributeError: 'NoneType' object has no attribute 'browse'

It's related the function of the field, here is the code : 

class StockPickingOut(orm.Model):

    _inherit = 'stock.picking.out'
    _name = 'stock.picking.out'

    def _amount_order(self, cr, uid, ids, amount_bl, arg, context):

        res = {}
       
        for picking in self.browse(cr, uid, ids, context):

            res[picking.id] =  0.0
            origin = picking.origin
            cr.execute("SELECT ID FROM SALE_ORDER WHERE NAME='%s' AND ID IS NOT NULL" %(origin))
            so = cr.fetchone()
            if so:
                so_id = so[0]
                so_record = self.pool.get('sale.order').browse(cr, uid, so_id, context=None)
                amount = so_record.amount_total
             
                res[picking.id] = amount
        return res

I think it has a relation with the fact that old none stored values have been deleted. 

So what I did, it's ignoring this error, and updating the module, So now the functionnal field is empty.

Just to explain more what the function does, it just pull the amount of the sale order, and put it on the delivery order. I don't know now after putting store=True, it's not working properly (supposition).

I'm now working to improve the code of my functionnal field, I'll let you know of my results.

Many thanks Ivan.

 

 

 

Avatar
Discard

You need to upgrade the module first.

Author

Yes it worked, but I lost all old none stored values for this field. How can I recompute these values again ?

Author

@ivan : check my edited answer please.

Remove the column from the table (or rename it to something else), the upgrade the module again.

Author

In fact, that's what I did, I first renamed the column and add the store parameter as True, same result, The column is created on database, but with empty values for existing records. Secondly, I created other column, with the same function code, but of course renamed, (I passed the correct field_name parameter for the field's function). then, same result.