简体   繁体   English

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

[英]Adding a field to sale order lines in sale orders

I want to add a computed field "markup" to sale order lines in sale orders (quotes/sales orders). 我想在销售订单(报价/销售订单)的销售订单行中添加一个计算字段“标记”。

在此处输入图片说明

I have created the model: 我创建了模型:

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

And a new view which inherits sale.view_order_form: 还有一个继承了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>

But the field is not shown (the view appears when you check views that inherit current view). 但是未显示该字段(当您检查继承当前视图的视图时,将显示该视图)。 I have reloaded everything, restarted the server and cleared the browser cache. 我已经重新加载了所有内容,重新启动了服务器并清除了浏览器缓存。

Any tip on why the field is not being shown is welcomed. 欢迎提供任何关于为什么不显示该字段的提示。 Maybe the Xpath expression? 也许是Xpath表达式? Thanks. 谢谢。

may be in sale.order view price_unit getting 2 times so it's confusion where to add and sale order view consist as formview and tree view for the sale orderline.here is the code you can get in view. 可能是在sale.order视图中price_unit获得了2倍,所以在哪里添加和销售订单视图就很复杂了,包括销售订单行的formview和tree view。这是您可以查看的代码。 formview: FormView控件:

<xpath expr="//notebook//page//field//form//field[@name='price_unit']" position="before">
    <field name="markup"/>
</xpath>

in Tree View: 在树状视图中:

<xpath expr="//notebook//page//field//tree//field[@name='price_unit']" position="before">
  <field name="markup"/>
</xpath>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM