2
我想爲銷售訂單(報價/銷售訂單)中的銷售訂單行添加計算字段「標記」。向銷售訂單中的銷售訂單行添加字段
我已經創建的模型:
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_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>
但現場沒有顯示(顯示視圖時你檢查繼承當前視圖的視圖)。我重新加載了所有內容,重新啓動了服務器並清除了瀏覽器緩存。
歡迎任何提示爲什麼該字段沒有顯示。也許Xpath表達式? 謝謝。
男人要添加領域embaded形式不樹。你的目標是在樹中檢查答案。由@ShivaGuntuku給出。要查看該字段是否以讀取模式添加到表單中,請單擊該項目以查看是否已添加到表單中。 – Cherif