Openerp 向销售订单中的销售订单行添加字段
我想在销售订单(报价单/销售订单)的销售订单行中添加一个计算字段“标记” 我已经创建了模型:Openerp 向销售订单中的销售订单行添加字段,openerp,Openerp,我想在销售订单(报价单/销售订单)的销售订单行中添加一个计算字段“标记” 我已经创建了模型: class SaleOrderLine(models.Model): _inherit = "sale.order.line" markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=True) def _compute_markup(self, orde
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=True)
def _compute_markup(self, order_id, product_id, product_uom_id):
frm_cur = self.env.user.company_id.currency_id
to_cur = order_id.pricelist_id.currency_id
purchase_price = product_id.standard_price
if product_uom_id != product_id.uom_id:
purchase_price = product_id.uom_id._compute_price(purchase_price, product_uom_id)
ctx = self.env.context.copy()
ctx['date'] = order_id.date_order
price = frm_cur.with_context(ctx).compute(purchase_price, to_cur, round=False)
return price
以及继承sale.view\u order\u表单的新视图:
<?xml version="1.0"?>
<odoo>
<record id="view_order_form_margin" model="ir.ui.view">
<field name="name">sale.order.form.margin</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr='//field[@name="order_line"]/form/group/group/field[@name="price_unit"]' position="before">
<field name="markup"/>
</xpath>
</field>
</record>
</odoo>
销售、订单、表格、保证金
销售订单
但未显示该字段(当您选中继承当前视图的视图时,将显示该视图)。我已重新加载所有内容,重新启动服务器并清除浏览器缓存
欢迎提供任何关于该字段未显示原因的提示。可能是Xpath表达式?
谢谢。可能正在销售中。订单查看价格单位获得2倍,因此在何处添加和销售订单视图以销售订单行的formview和tree view的形式存在混淆。以下是您可以查看的代码。 formview:
<xpath expr="//notebook//page//field//form//field[@name='price_unit']" position="before">
<field name="markup"/>
</xpath>
在树状视图中:
<xpath expr="//notebook//page//field//tree//field[@name='price_unit']" position="before">
<field name="markup"/>
</xpath>
man您正在将字段添加到embadded表单,而不是树。你的目标也在树中检查答案。由@ShivaGuntuku提供。若要查看该字段是否以读取模式添加到表单,请单击该项以查看是否已添加到表单。