Odoo 10将字段添加到销售订单行

时间:2017-07-05 00:25:31

标签: openerp odoo-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)

但是当我打开报价/销售订单时,我收到此错误:

  

未捕获的TypeError:Type不是构造函数   http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119   回溯:TypeError:Type不是构造函数       在for_(http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2119:1208)       在http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:312       在函数。 .map。 .collect(http://localhost:8369/web/content/319-32fb078/web.assets_common.js:13:270)       at _。(匿名函数)[as map](http://localhost:8369/web/content/319-32fb078/web.assets_common.js:69:526)       在Class.setup_columns(http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2035:261)       在课堂上。 (http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2036:480)       在http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2099:11       在对象。 (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:3202:136)       在对象。 (http://localhost:8369/web/content/319-32fb078/web.assets_common.js:547:681)       在火(http://localhost:8369/web/content/319-32fb078/web.assets_common.js:541:299

2 个答案:

答案 0 :(得分:3)

只需像这样更改您的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 :(得分:2)

从树视图定义中删除<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>

希望这会对你有所帮助。