Invalid view definition - Odoo v9 community
<p>I manage to find a way to have the product price on <code>stock.picking</code>, but now I have a view error.</p>

<p>This is my  model:</p>

<pre><code>from openerp import models, fields, api
import openerp.addons.decimal_precision as dp 

class StockPicking(models.Model):
    _inherit = 'stock.picking'

    product_id = fields.Many2one("product.product", "Product")
    price_unity = fields.Float(string="Precio", store=True, readonly=True, related="product_id.lst_price")
</code></pre>

<p>Now, the offending code in my view:</p>

<pre><code>&lt;record id="view_stock_picking_form" model="ir.ui.view"&gt;
    &lt;field name="name"&gt;Stock Picking Price Form&lt;/field&gt;
    &lt;field name="model"&gt;stock.picking&lt;/field&gt;
    &lt;field name="inherit_id" ref="stock.view_picking_form"/&gt;
    &lt;field name="arch" type="xml"&gt;
            &lt;xpath expr="//page/field[@name='pack_operation_product_ids']/tree/field[@name='qty_done']" position="after"&gt;
                &lt;field name="price_unity"/&gt;
            &lt;/xpath&gt;
    &lt;/field&gt;
&lt;/record&gt;
</code></pre>

<p>It says <code>Error details:
Field</code>price_unity<code>does not exist</code> how is this even possible?</p>

<p>On tree view it doesn't throws this error:</p>

<pre><code>&lt;record id="view_stock_picking_tree" model="ir.ui.view"&gt;
    &lt;field name="name"&gt;Stock Picking Price Tree&lt;/field&gt;
    &lt;field name="model"&gt;stock.picking&lt;/field&gt;
    &lt;field name="inherit_id" ref="stock.vpicktree"/&gt;
    &lt;field name="arch" type="xml"&gt;
        &lt;field name="state" position="before"&gt;
            &lt;field name="price_unity"/&gt;
        &lt;/field&gt;
    &lt;/field&gt; 
&lt;/record&gt;
</code></pre>

<p>So, how is it that in form view I can't declare it'</p>

<p>Am I missing something?</p>

<p>Thanks in advance!</p>

<p>You are adding <em>price_unity</em> field in view inside <em>pack_operation_product_ids</em> field.</p>

<p><em>pack_operation_product_ids</em> is a One2many relation type with <em>stock_pack_operation</em> object.</p>

<p>So we need to add/register <em>price_unity</em> field in <em>stock_pack_operation</em> object.</p>

<p>Try with following code:</p>

<pre><code>class StockPackOperation(models.Model):
    _inherit = 'stock.pack.operation'

    price_unity = fields.Float(string="Precio", store=True, readonly=True, related="product_id.lst_price")

    #product_id is already in table so no need to add/register
</code></pre>

<p>Afterwards restart Odoo server and upgrade your custom module.</p>

<p>NOTE:</p>

<p>You are not getting error in tree of Stock Picking because you have added/registered <em>price_unity</em>.</p>

<p>Your view code is good.</p>

python openerp odoo-9 qweb