This question has been flagged
6 Replies
9885 Views

I has a moudle that inherit stock.packing and also has a custom field name cw_inventory_ref.

if I write my code like this,

<xpath expr="//field[@name='partner_id']" position="after">
                      <field name="cw_inventory_ref"/>

</xpath>  

the cw_inventory_ref is appeared after parent_id.

I don't want like this.

I want cw_inventory_ref to appeared in front of parent_id.

for example, [data of cw_inventory_ref]data of parent_id.

So, I write my code as following but it doesn't work,

in xml file:

        <record id="cw_stock_picking_tree_view" model="ir.ui.view">
                <field name="name">cw_stock_picking_tree_view</field>
                <field name="model">stock.picking</field>
                <field name="inherit_id" ref="stock.vpicktree"></field>
                <field name="arch" type="xml">                 
                    <xpath expr="//field[@name='partner_id']" position="replace">
                      [<field name="cw_inventory_ref"/>]<field name="partner_id"/>
                    </xpath>                                     
                </field>
        </record>

In .py file:

# -*- coding: utf-8 -*-

from odoo import models, fields, api

class cw_update(models.Model):
    _inherit = 'stock.picking'
    cw_inventory_ref = fields.Char(string=' Internal Reference ',related = "partner_id.ref",readonly=True)  
How can I fix this?Thank you.
 

Avatar
Discard

Why don't you use position="before" ??

Author

If I used before and after, I will show one line per data.

I want to shown like this [partner_ref]partner in position of partner_id.

Best Answer

Try this


<xpath expr="//field[@name='partner_id']" position="replace">

    <div>

        [<field name="cw_inventory_ref" style="width: 50%%"/>]

        <field name="partner_id" style="width: 60%%"/> 

    </div>

</xpath>


or else 

Try this


<xpath expr="//field[@name='partner_id']" position="replace">

    <group>

<group>

        [<field name="cw_inventory_ref"/>]

</group>

<group>        

<field name="partner_id"/> 

<group>    

</group>

</xpath>



Avatar
Discard
Author

Thank you for your reply but not ok.I got Invaild view definition error.

Best Answer

try this

        <record id="cw_stock_picking_tree_view" model="ir.ui.view">
                <field name="name">cw_stock_picking_tree_view</field>
                <field name="model">stock.picking</field>
                <field name="inherit_id" ref="stock.vpicktree"></field>
                <field name="arch" type="xml">
                       <xpath expr="//field[@name='partner_id']" position="replace">
                          [<field name="cw_inventory_ref" class="oe_inline"/>]
                            <field name="partner_id" class="oe_inline"/>
                       </xpath>
                 </field>
        </record>


I didn't tested, have a try

Avatar
Discard
Author

Thank you for your replay.But not okey.

I got TypeError: field.attrs is undefined error.

Then there will be problem with your previous views that is inherited here

Best Answer

Try this

<xpath expr="//field[@name='partner_id']" position="before">
                      <field name="cw_inventory_ref"/>
  </xpath>    


Avatar
Discard
Author

I want to show cw_inventory_ref data and partner_id together in the position of partner_id with square bracket.If I used before, It will show one data per line.I want my data like this [partner_ref]partner44 where

partner_ref is data of cw_inventory_ref

and

partner44 is data of partner_id.

Thank You.