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

Openerp Odoo 10将字段添加到销售订单行,openerp,odoo-10,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&l

我试图编写一个模块,在每个销售订单行中为报价提供一个标记单元格(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)
#-*-编码:utf-8-*-
从odoo导入api、字段、模型
将odoo.addons.decimal\u精度导入为dp
类别SaleOrderLine(models.Model):
_inherit=“sale.order.line”
markup=fields.Float(compute=''计算标记',digits=dp.get\u精度('.2f%'),store=False,readonly=True)
markup_per=fields.Float(compute='''u compute_markup_per',digits=dp.get_precision('.2f%')、store=False、readonly=False)
@api.取决于(‘价格单位’、‘采购价格’)
定义计算标记(自):
请自行记录:
如果记录.price\u单位和记录.purchase\u价格:
record.markup=record.price\u unit-record.purchase\u price
@api.取决于(‘价格单位’、‘采购价格’)
每个(自身)的定义计算标记:
请自行记录:
如果record.purchase\u price>0:
record.markup\u per=100.0*(record.price\u unit-record.purchase\u price)/record.purchase\u price
@api.onchange('markup\u per')
定义更改标记(自我):
如果self.u per:
如果self.markup_per>-9999.99和self.markup_per<9999.99:
self.price\u unit=self.purchase\u price*(1+self.markup\u per/100.0)
但是,当我打开报价单/销售订单时,会出现以下错误:

未捕获的TypeError:类型不是构造函数 回溯:类型错误:类型不是构造函数 at for_u389;() 在 在函数处..映射..收集() at u40;匿名函数)[作为映射]() 在Class.setup\u列() 在课堂上。() 在 反对。() 反对。() 失火()

从树视图定义中删除
。使用属性
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>

销售、订单、表格、加价
销售订单
希望这将对您有所帮助。

从树视图定义中删除
。使用属性
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>

销售、订单、表格、加价
销售订单

希望这对您有所帮助。

只需像这样更改您的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>

销售、订单、表格、加价
销售订单

只需像这样更改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>

销售、订单、表格、加价
销售订单