在销售订单中的销售订单行中添加字段

M.E*_*.E. 2 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, 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
Run Code Online (Sandbox Code Playgroud)

以及继承sale.view_order_form的新视图:

<?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>
Run Code Online (Sandbox Code Playgroud)

但是未显示该字段(当您检查继承当前视图的视图时,将显示该视图).我重新加载了所有内容,重新启动了服务器并清除了浏览器缓存.

欢迎任何有关该领域未被展示的提示.也许Xpath表达?谢谢.

Shi*_*uku 5

可能在销售.订单查看price_unit得到2次所以它的混淆在哪里添加和销售订单视图包括销售订单行的形式视图和树视图.您可以在视图中获得的代码.FormView控件:

<xpath expr="//notebook//page//field//form//field[@name='price_unit']" position="before">
    <field name="markup"/>
</xpath>
Run Code Online (Sandbox Code Playgroud)

在树视图中:

<xpath expr="//notebook//page//field//tree//field[@name='price_unit']" position="before">
  <field name="markup"/>
</xpath>
Run Code Online (Sandbox Code Playgroud)