简体   繁体   English

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

[英]Odoo 10 adding field to sale order line

I am trying to code a module to provide a markup cell in each sale order line for quotes (Odoo 10). 我正在尝试编写一个模块,以便在每个销售订单行中为报价提供一个标记单元格(Odoo 10)。 But I consistently get an error while loading the quote/sale order. 但是在加载报价/销售订单时,我始终遇到错误。 Any help is welcomed. 欢迎任何帮助。

This is the view: 这是视图:

<?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>

And the model: 和模型:

# -*- 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)

But I am getting this error when I open a quote/sales order: 但是,当我打开报价/销售订单时出现此错误:

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. 未捕获到的TypeError:类型不是构造函数http:// localhost:8369 / web / content / 365-ad86b81 / web.assets_backend.js:2119追溯 :TypeError:类型不是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 _.(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. .collect( http:// localhost:8369 / web / content / 319-32fb078 / web.assets_common.js:13:270 )在_。(匿名函数)[作为地图]( 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 ) at http://localhost:8369/web/content/365-ad86b81/web.assets_backend.js:2099:11 at Object. 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在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:3202:136 )在对象处。 ( 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 ) 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

Just change your xml view like this. 只需像这样更改您的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>

Remove <label> from tree view definition. 从树视图定义中删除<label> Use attribute string to change label. 使用属性string更改标签。

Try below code. 尝试下面的代码。

 <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>

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM