我设法找到了一种在stock.picking上获得产品价格的方法,但是现在我有了一个视图错误。
这是我的模型:
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")现在,在我看来,违规代码:
<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: Fieldprice_unitydoes not exist这怎么可能?
在树视图中,它不会抛出此错误:
<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>那么,在形式上我怎么不能声明它呢?
我是不是遗漏了什么?
提前感谢!
发布于 2016-10-19 05:04:09
在price_unity字段中添加视图中的pack_operation_product_ids字段。
pack_operation_product_ids是一个带有stock_pack_operation对象的One2many关系类型。
因此,我们需要在price_unity对象中添加/注册stock_pack_operation字段。
尝试使用以下代码:
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服务器并升级您的自定义模块。
注意:
您不会因为添加/注册了price_unity而在选股树中出错。
您的视图代码很好。
https://stackoverflow.com/questions/40118981
复制相似问题