تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
10099 أدوات العرض

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

الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
الكاتب

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

الكاتب

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

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
فبراير 25
2106
1
فبراير 19
3088
2
أكتوبر 18
9568
1
يونيو 15
5844
0
فبراير 25
3835