Reputation: 5515
I am trying to code a module to provide a markup cell in each sale order line for quotes (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..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)
Upvotes: 1
Views: 1407
Reputation: 1524
Just change your xml view like this.
<?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>
Upvotes: 3
Reputation: 4174
Remove <label>
from tree view definition. Use attribute string
to change label.
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.
Upvotes: 2