This question has been flagged
2 Replies
5635 Views

I'm getting set up to write my first OpenERP module. I want to add some fields to a list that is displayed on a Product form view, Procurements tab (View ID 233). If you look at that screen, toward the bottom there is a list titled "Suppliers". By default, this list has headers for "Supplier", "Delivery Lead Time", and "Minimal Quantity". I would like to add in "Product Name" and "Product Code".

If I go into "Manage Views" from the debug menu, it looks like the list comes from this code:

<view view_id=589>
    <group>
        <separator string='Suppliers'>
            <field name='seller_ids'>

The XML for that bit seems to live in addons/purchase/purchase_view.xml in this bit, beginning on line 554:

<record id="view_product_supplier_inherit" model="ir.ui.view">
    <field name="name">product.normal.supplier.form.inherit</field>
    <field name="model">product.product</field> <field name="inherit_id" ref="product.product_normal_form_view"/>
    <field name="arch" type="xml">
        <div name="options" position="inside">
            <field name="purchase_ok"/>
            <label for="purchase_ok"/>
        </div>
        <group name="procurement" position="after">
            <separator string="Suppliers"/>
                <field name="seller_ids" context="{'uom_id': uom_id}"/>
        </group>
    </field>
</record>

I had thought that this would be the view code that I'd need to inherit and override, but now I'm confused. The only field listed is 'seller_ids', but when viewed in the browser, the list displays "Supplier", "Delivery Lead Time", and "Minimal Quantity". Where are these extra fields defined, and how would I get to the point where I can add the fields 'product_name' and 'product_code', both from 'product.supplierinfo'?

Avatar
Discard
Best Answer

This line is addon module which alters view. Main definition is in file product/product_view.xml in tab "Procurement"

In your addon module you can add or remove fields as you want. All definitions are agregated and then displayed.

 

Marek Mosiewicz

http://consultantodoo.com

Avatar
Discard
Best Answer

Sub-views like that (one2many and many2many fields in the main view) will just attempt to find an already existing tree view definition.  seller_ids is a one2many field relating to the product.supplierinfo model, which does have an already existing tree view (xml id="product.product_supplierinfo_tree_view").  You've got two options, either inherit and edit the supplierinfo view so the tree view is updated everywhere, or replace the existing seller_ids field with one that has an alternative, inline tree view.

I'd suggest inheriting the supplierinfo view because I don't think that list view is used anywhere else in the first place.  If it was a much more widely used model (e.g.: res.partner), you may potentially want to make an inline tree view instead so that it would only look different when you're viewing from that particular page.  I'll show how both methods would look in your XML file.

Inheriting product.supplierinfo's list view:

<record id="product_supplierinfo_tree_view_productname" model="ir.ui.view">
    <field name="name">product.supplierinfo.tree.view.productname</field>
    <field name="model">product.supplierinfo</field>
    <field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='min_qty']" position="after">
            <field name="product_name"/>
            <field name="product_code"/>
        </xpath>
    </field>
</record>

 

Inheriting product.product's form view:

<record id="view_product_supplier_inherit_productname" model="ir.ui.view">
    <field name="name">product.normal.supplier.form.inherit.productname</field>
    <field name="model">product.product</field>
    <field name="inherit_id" ref="purchase.view_product_supplier_inherit"/>
    <field name="arch" type="xml">
        <xpath expr="//field[@name='seller_ids']" position="inside">
            <tree>
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="delay"/>
                <field name="min_qty"/>
                <field name="product_name"/>
                <field name="product_code"/>
                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
            </tree>
        </xpath>
    </field>
</record>

Avatar
Discard