Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
10243 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
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'.

Powiązane posty Odpowiedzi Widoki Czynność
2
lut 25
2239
1
lut 19
3178
2
paź 18
9717
1
cze 15
5952
0
lut 25
3835