2017-06-27 186 views
2

我想爲銷售訂單(報價/銷售訂單)中的銷售訂單行添加計算字段「標記」。向銷售訂單中的銷售訂單行添加字段

enter image description here

我已經創建的模型:

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表達式? 謝謝。

+0

男人要添加領域embaded形式不樹。你的目標是在樹中檢查答案。由@ShivaGuntuku給出。要查看該字段是否以讀取模式添加到表單中,請單擊該項目以查看是否已添加到表單中。 – Cherif

回答

5

可能在sale.order查看price_unit獲得2倍,所以它是混亂的地方添加和銷售訂單視圖包括作爲formview和樹視圖銷售orderline.here是你可以在視圖中的代碼。 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> 
相關問題