无效的视图定义-Odoo v9社区 [英] Invalid view definition - Odoo v9 community

查看:228
本文介绍了无效的视图定义-Odoo v9社区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法找到一种在stock.picking上显示产品价格的方法,但是现在出现了视图错误.

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

这是我的模特

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>

它说Error details: Field price_unity does not exist这怎么可能?

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'

我想念什么吗?

提前谢谢!

推荐答案

您要在 pack_operation_product_ids 字段内的视图中添加 price_unity 字段.

You are adding price_unity field in view inside pack_operation_product_ids field.

pack_operation_product_ids 是一个具有 stock_pack_operation 对象的One2many关系类型.

pack_operation_product_ids is a One2many relation type with stock_pack_operation object.

因此,我们需要在 stock_pack_operation 对象中添加/注册 price_unity 字段.

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

尝试以下代码:

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

然后重新启动Odoo服务器并升级您的自定义模块.

Afterwards restart Odoo server and upgrade your custom module.

注意:

由于添加/注册了 price_unity ,您在股票拣选树中没有出现错误.

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

您的查看代码很好.

这篇关于无效的视图定义-Odoo v9社区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆