2017-07-05 4 views
1

私は、オーダー10の各販売注文ラインにマークアップセルを提供するモジュールをコーディングしようとしています。しかし、見積もり/売り注文を読み込んでいる間、一貫してエラーが発生します。どんな助けも歓迎されます。Odoo 10販売オーダーラインにフィールドを追加する

これは図である。

<?xml version="1.0"?> 
<odoo> 
    <record id="view_order_form_markup model" model="ir.ui.view"> 
     <field name="name">sale.order.form.markup</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"> 
       <label for="markup" string="Markup"/><field name="markup"/> 
       <label for="markup_per" string="Markup (%)"/><field name="markup_per"/> 
      </xpath> 
      <xpath expr='//field[@name="order_line"]/tree/field[@name="price_unit"]' position="before"> 
       <label for="markup" string="Markup"/><field name="markup"/> 
       <label for="markup_per" string="Markup (%)"/><field name="markup_per"/> 
      </xpath> 
     </field> 
    </record> 
</odoo> 

とモデル:

# -*- coding: utf-8 -*- 

from odoo import api, fields, models 
import odoo.addons.decimal_precision as dp 

class SaleOrderLine(models.Model): 
    _inherit = "sale.order.line" 

    markup = fields.Float(compute='_compute_markup', digits=dp.get_precision('.2f%'), store=False, readonly=True) 
    markup_per = fields.Float(compute='_compute_markup_per', digits=dp.get_precision('.2f%'), store=False, readonly=False) 


    @api.depends('price_unit', 'purchase_price') 
    def _compute_markup(self): 
     for record in self: 
      if record.price_unit and record.purchase_price: 
       record.markup = record.price_unit - record.purchase_price 

    @api.depends('price_unit', 'purchase_price') 
    def _compute_markup_per(self): 
     for record in self: 
      if record.purchase_price > 0: 
       record.markup_per = 100.0 * (record.price_unit - record.purchase_price)/record.purchase_price 

    @api.onchange('markup_per') 
    def _onchange_markup_per(self): 
      if self.markup_per: 
       if self.markup_per > -9999.99 and self.markup_per < 9999.99: 
        self.price_unit = self.purchase_price * (1 + self.markup_per/100.0) 

しかし、私は引用符/販売注文を開いたときに、私はこのエラーを取得しています:

Uncaught TypeError: Type is not a constructor http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119 Traceback: TypeError: Type is not a constructor at for_ (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119:1208) at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:312 at Function..map..collect (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:13:270) at _.(anonymous function) [as map] (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:69:526) at Class.setup_columns (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:261) at Class. (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2036:480) at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2099:11 at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:3202:136) at Object. (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:547:681) at fire (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:541:299)

答えて

1

このようにXMLビューを変更するだけです。

<?xml version="1.0"?> 
<odoo> 
    <record id="view_order_form_markup model" model="ir.ui.view"> 
     <field name="name">sale.order.form.markup</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"> 
       <label for="markup" string="Markup"/><field name="markup"/> 
       <label for="markup_per" string="Markup (%)"/><field name="markup_per"/> 
      </xpath> 
      <xpath expr='//field[@name="order_line"]/tree/field[@name="price_unit"]' position="before"> 
       <field name="markup" string="Markup"/> 
       <field name="markup_per" string="Markup (%)"/> 
      </xpath> 
     </field> 
    </record> 
</odoo> 
1

削除ツリービュー定義から<label>。属性stringを使用してラベルを変更します。

下記のコードを試してください。

<record id="view_order_form_markup_model" model="ir.ui.view"> 
     <field name="name">sale.order.form.markup</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"> 
       <label for="markup" string="Markup"/><field name="markup"/> 
       <label for="markup_per" string="Markup (%)"/><field name="markup_per"/> 
      </xpath> 
      <xpath expr='//field[@name="order_line"]/tree/field[@name="price_unit"]' position="after"> 
      <field name="markup"/> 
      <field name="markup_per" string="Markup (%)"/> 
      </xpath> 
     </field> 
    </record> 

希望すると、これが役に立ちます。

関連する問題