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

Display product code on pricelist item tree view

By
Aurélien Rivet
on 3/29/16, 5:11 AM 349 views

Hi ,

I don't know why the product code is not displayed on the pricelist item view.

On the pricelist.item.version model, you have a form view which contains an item called items_id. This items is displayed as a tree view with columns corresponding to some products. But code is not displayed. i want it. i tried the following code but it doesn't seem to do anything:

<record id="product_pricelist_item_tree_view_with_code" model="ir.ui.view">

    <field name="name">product.pricelist.item.tree</field>

    <field name="model">product.pricelist.item</field>

    <field name="inherit_id" ref="product.product_pricelist_item_tree_view" />

    <field name="arch" type="xml">

        <field name="product_id" position="attributes">

            <attribute name="context">{'display_default_code':True}</attribute>

        </field>

        <field name="product_tmpl_id" position="attributes">

            <attribute name="context">{'display_default_code':True}</attribute>

        </field>

    </field>

</record>


<record id="product_pricelist_item_form_view_with_code" model="ir.ui.view">

    <field name="name">product.pricelist.item.form</field>

    <field name="model">product.pricelist.item</field>

    <field name="inherit_id" ref="product.product_pricelist_item_form_view" />

    <field name="arch" type="xml">

        <field name="product_id" position="attributes">

            <attribute name="context">{'display_default_code':True}</attribute>

        </field>

        <field name="product_tmpl_id" position="attributes">

            <attribute name="context">{'display_default_code':True}</attribute>

        </field>

    </field>

</record>

<record id="product_pricelist_version_form_view_with_code" model="ir.ui.view">

    <field name="name">product.pricelist.version.form</field>

    <field name="model">product.pricelist.version</field>

    <field name="inherit_id" ref="product.product_pricelist_version_form_view" />

    <field name="arch" type="xml">

        <field name="items_id" position="attributes">

            <attribute name="context">{'display_default_code':True}</attribute>

        </field>

    </field>

</record>


Maybe someone could help ?

0
Aurélien Rivet
On 4/14/16, 4:27 AM

I overrided name_get function in product.template.


@api.multi

def name_get(self):

    context = self.env.context

    if context is None:

        context = {}

    if 'partner_id' in context:

        pass

    data = []

    for product in self:

        if context.get('display_default_code', False) is True:

            name_tuple = (product.id, '[%s] %s' %(product.default_code, product.name))

        else:

            name_tuple = (product.id, '%s' %(product.name))

        data.append(name_tuple)

    return data


That does the trick.

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: 3/29/16, 5:11 AM
Seen: 349 times
Last updated: 4/14/16, 4:27 AM