Skip to Content
Menu
This question has been flagged
1 Odpoveď
10096 Zobrazenia

Hi Folks,

I have just started understanding openerp. I am customizing it's warehouse & sales modules according to my needs. But i am stuck now. Below is the description of problem, for which i need help:

I want to fetch product location from product_template relation. I will show the fetched product location in tree view of product_product, for which i need to define fields.function(_get_product_loc_case, string='Product Location) function, plz help.

class product_product(osv.osv):

def _get_product_loc_case(self, cr, uid, ids, name, value, args, context=None):
    res = {}
    for product in self.browse(cr, uid, ids):
        res = {'product_loc': product_template.loc_case}

'product_loc': fields.function(_get_product_loc_case, string='Case')

class product_template(osv.osv): 'loc_case': fields.char('Location Case', size=50)

Any help would be appreciated, and sorry if the code is confusing you, coz i really don't know about complex programming in openerp, just trying to learn that....

Avatar
Zrušiť
Best Answer

Hello Pankaj,

You can get the location of product using following code:

def _get_product_loc_case(self, cr, uid, ids, name, args, context=None):
    res = {}
    for product in self.browse(cr, uid, ids, context=context):
        result[product.id] = product.product_tmpl_id and product.product_tmpl_id.loc_case or ''
    return res

class product_product(osv.osv)
    _inherit = 'product.product'
    _column = {
        'product_loc': fields.function(_get_product_loc_case, type='char', string='Case')
    }

Now you just need to inherit the Tree View of product.product and put the our new field product_loc in the Tree View.

Note: You must write the function field method before the field is declare in the file.

Hope this will helps you.

Thank you.

Avatar
Zrušiť
Autor

thanks a lot, it solved my problem...:)

Autor

result[product.id] = product.product_tmpl_id and product.product_tmpl_id.loc_case or '', plz explain meainig of this.

The meaning of the above code is that each record is distinguished by its id right? So we are retrieving the result for a particular record into a field which is a functional field, here the result is product.product_tmpl_id.loc_case and the record distinguisher is its id so we are assigning the result to that record and display the result using that functional field 'product_loc'.

Related Posts Replies Zobrazenia Aktivita
2
feb 25
2104
1
feb 19
3081
2
okt 18
9561
1
jún 15
5842
0
feb 25
3835