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

How-to add the field product_code from the table product.supplierinfo in the product.product tree view

By
Christian Parent
on 4/8/14, 9:52 PM 1,446 views

I am trying to get the field product_code from the table product.supplierinfo in the product.product tree view so that my users can then make searches with the supplier code instead of the internal reference.

Is there a Tutorial or a snippet that could help me do so ?

Since internal reference can have many related suppliers/suppliers code, would there be a better way to do this ?

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 4/9/14, 12:30 PM

Based on your requirement to inherit product object and create functional field to store product_code in product table. And add the field in tree view and search view.

Python Code:-

class product_product(osv.osv):
    _inherit = "product.product"

def _sup_product_code(self, cr, uid, ids, name, arg, context=None):
    res = {}
    if context is None:
        context = {}
    sup_code_list = []    
    for product in self.browse(cr, uid, ids, context=context):
        for supinfo in product.seller_ids:
            if isinstance(supinfo.product_code, str) or isinstance(supinfo.product_code, unicode):
                sup_code_list.append(supinfo.product_code)   
        sup_code_res = ', '.join(sup_code_list)     
        res[product.id] = sup_code_res
    return res

_columns = {
    'sup_product_code': fields.function(_sup_product_code, string="Supplier Product Code", type='char', store=True),
}

Xml File:-

<record id="product_search_view_suppcode" model="ir.ui.view">
            <field name="name">product.search.suppcode</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_search_form_view"/>
            <field name="arch" type="xml">
                <field name="name" position="after">
                    <field name="sup_product_code"/>
                </field>
            </field>
        </record>

        <record id="product_tree_view_suppcode" model="ir.ui.view">
            <field name="name">product.tree.suppcode</field>
            <field name="model">product.product</field>
            <field name="inherit_id" ref="product.product_product_tree_view"/>
            <field name="arch" type="xml">
                <field name="state" position="after">
                    <field name="sup_product_code"/>                    
                </field>
            </field>
        </record>

Note: In the Functional Field use Store=False in the first time (then only it generate all the Product Code in tree view for old records). After that update the code Store=True and it execute the Product Code after saving the record and also we can use the field in Filter Options.

0
Christian Parent
On 4/10/14, 5:23 PM

Finally, the module product_manufacturer_extension adds the ability to do so.

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

0 follower(s)

Stats

Asked: 4/8/14, 9:52 PM
Seen: 1446 times
Last updated: 3/16/15, 8:10 AM