Invalid view definition - Odoo v9 community

删除回忆录丶 提交于 2020-01-05 03:57:12

问题


I manage to find a way to have the product price on stock.picking, but now I have a view error.

This is my model:

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")

Now, the offending code in my view:

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

It says Error details: Fieldprice_unitydoes not exist how is this even possible?

On tree view it doesn't throws this error:

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

So, how is it that in form view I can't declare it'

Am I missing something?

Thanks in advance!


回答1:


You are adding price_unity field in view inside pack_operation_product_ids field.

pack_operation_product_ids is a One2many relation type with stock_pack_operation object.

So we need to add/register price_unity field in stock_pack_operation object.

Try with following 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

Afterwards restart Odoo server and upgrade your custom module.

NOTE:

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

Your view code is good.



来源:https://stackoverflow.com/questions/40118981/invalid-view-definition-odoo-v9-community

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!