Skip to Content
Menu
This question has been flagged
1 Reply
4053 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 ?

Avatar
Discard
Author Best Answer

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.

Avatar
Discard