Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Get a functionnnal field on advanced research fields option , on the filter [v7]

By
Yassine TEIMI
on 1/28/15, 5:16 PM 1,324 views

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.

0
Yassine TEIMI
On 1/29/15, 10:55 AM

@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.

 

 

 

You need to upgrade the module first.

Ivan
on 1/29/15, 10:53 PM

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

Yassine TEIMI
on 1/30/15, 4:52 AM

@ivan : check my edited answer please.

Yassine TEIMI
on 1/30/15, 5:13 AM

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

Ivan
on 1/30/15, 11:53 AM

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.

Yassine TEIMI
on 2/3/15, 11:32 AM
0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
On 1/28/15, 10:39 PM

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.

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 ?

Yassine TEIMI
on 1/29/15, 5:33 AM

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

Yassine TEIMI
on 1/29/15, 5:44 AM

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.

Ivan
on 1/29/15, 6:16 AM

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

Ivan
on 1/29/15, 6:18 AM

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...

Yassine TEIMI
on 1/29/15, 7:59 AM

You need to upgrade the module first.

Ivan
on 1/29/15, 8:49 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/28/15, 5:16 PM
Seen: 1324 times
Last updated: 3/16/15, 8:10 AM