Skip to Content
Menu
This question has been flagged
2 Replies
2999 Views

Best,


I'm trying to add a simple record to a existing module and visualize it in a form.

this fails and keeps returning "Field Does Not Exist Error"

What am I doing wrong ?
see added lines in bold.

K.R.

.py

# -*- coding: utf-8 -*-
# See LICENSE-DOC file for full copyright and licensing details
from odoo import models, fields, api, _

class SaleOrder(models.Model):
    _inherit = 'sale.order'
    margin_percentage = fields.Float(string='Margin (%)')
    margin_percentage2 = fields.Float(string='Margin (%)')
    def action_update_margin(self):
        for line in self:
            sale_margin_percentage = line.margin_percentage
            for rec in line.order_line:
#                 rec.margin_percentage = sale_margin_percentage
                rec.update({
                'margin_percentage': sale_margin_percentage,
                })
                rec.price_unit = (
                rec.product_id.standard_price
                + ((rec.margin_percentage * rec.product_id.standard_price) / 100)
            )

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    margin_percentage = fields.Float(string='Margin (%)')
    @api.onchange('margin_percentage', 'product_id')
    def onchange_margin_percentage(self):
        if self.margin_percentage and self.product_id.standard_price:
            self.price_unit = (
                self.product_id.standard_price
                + ((self.margin_percentage * self.product_id.standard_price) / 100)
            )

.xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_order_form_sale_margin" model="ir.ui.view">
  <field name="name">view.order.form.sale.margin</field>
  <field name="model">sale.order</field>
  <field name="inherit_id" ref="sale.view_order_form"/>
  <field name="arch" type="xml">
  
   <header>
        <button name="action_update_margin" string="Update Margin" type="object" class="btn-primary" attrs="{'invisible':[('state','in',['sale','done','cancel'])]}"/>
    </header>
  
    <field name="date_order" position="after">
      <field name="margin_percentage"/>
    </field>
    <field name="date_order" position="after">
      <field name="margin_percentage2"/>
    </field>

    <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">
      <field name="margin_percentage"/>
    </xpath>
    <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">
      <field name="margin_percentage"/>
    </xpath>
    <xpath expr="//page/field[@name='order_line']" position="attributes">
      <attribute name="context">
        {'default_margin_percentage': margin_percentage}
      </attribute>
    </xpath>
  </field>
</record>
</odoo>


Avatar
Discard

Post your log so that we can see what the error is telling

Author Best Answer

Hi Bah Abdourahamane Sank



See error log below

Fout:

Odoo Server Error


Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 394, in _check_xml
    self.postprocess_and_fields(view.model, view_doc, view.id)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 987, in postprocess_and_fields
    self.raise_view_error(message, view_id)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 614, in raise_view_error
    raise ValueError(message)
ValueError: Veld 'margin_percentage2' bestaat niet
Fout context:
Weergave`view.order.form.sale.margin`
[view_id: 2953, xml_id: sales_global_margin.view_order_form_sale_margin, model: sale.order, parent_id: 1324]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 712, in parse
    self._tag_root(de)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 674, in _tag_root
    f(rec)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 577, in _tag_record
    record = model._load_records([data], self.mode == 'update')
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4053, in _load_records
    data['record']._load_records_write(data['values'])
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1374, in _load_records_write
    super(View, self)._load_records_write(values)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3991, in _load_records_write
    self.write(values)
  File "/usr/lib/python3/dist-packages/odoo/addons/website_theme_install/models/theme_models.py", line 224, in write
    res = super(IrUiView, other_views).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_ui_view.py", line 51, in write
    return super(View, self).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 493, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3569, in write
    fields[0].determine_inverse(real_recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1114, in determine_inverse
    getattr(records, self.inverse)()
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 299, in _inverse_arch
    view.write(data)
  File "/usr/lib/python3/dist-packages/odoo/addons/website_theme_install/models/theme_models.py", line 224, in write
    res = super(IrUiView, other_views).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_ui_view.py", line 51, in write
    return super(View, self).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 493, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3564, in write
    real_recs._validate_fields(set(vals) - set(inverse_fields))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 1176, in _validate_fields
    check(self)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 396, in _check_xml
    raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.exceptions.ValidationError: ("Fout bij valideren weergave\n\nVeld 'margin_percentage2' bestaat niet\n\nFout context:\nWeergave`view.order.form.sale.margin`\n[view_id: 2953, xml_id: sales_global_margin.view_order_form_sale_margin, model: sale.order, parent_id: 1324]", None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1326, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1314, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 387, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 374, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/addons/quick_module_upgrade/models/ir_module.py", line 8, in button_immediate_upgrade
    res = super(IRMOdule,self).button_immediate_upgrade()
  File "<decorator-gen-65>", line 2, in button_immediate_upgrade
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 72, in check_and_log
    return method(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 634, in button_immediate_upgrade
    return self._button_immediate_function(type(self).button_upgrade)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function
    modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 86, in new
    odoo.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 419, in load_modules
    force, status, report, loaded_modules, update_module, models_to_check)
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 315, in load_marked_modules
    perform_checks=perform_checks, models_to_check=models_to_check
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 225, in load_module_graph
    load_data(cr, idref, mode, kind='data', package=package, report=report)
  File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 68, in load_data
    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 736, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 803, in convert_xml_import
    obj.parse(doc.getroot())
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 721, in parse
    exc_info[2]
  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 13, in reraise
    raise value.with_traceback(tb)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 712, in parse
    self._tag_root(de)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 674, in _tag_root
    f(rec)
  File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 577, in _tag_record
    record = model._load_records([data], self.mode == 'update')
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4053, in _load_records
    data['record']._load_records_write(data['values'])
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 1374, in _load_records_write
    super(View, self)._load_records_write(values)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3991, in _load_records_write
    self.write(values)
  File "/usr/lib/python3/dist-packages/odoo/addons/website_theme_install/models/theme_models.py", line 224, in write
    res = super(IrUiView, other_views).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_ui_view.py", line 51, in write
    return super(View, self).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 493, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3569, in write
    fields[0].determine_inverse(real_recs)
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1114, in determine_inverse
    getattr(records, self.inverse)()
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 299, in _inverse_arch
    view.write(data)
  File "/usr/lib/python3/dist-packages/odoo/addons/website_theme_install/models/theme_models.py", line 224, in write
    res = super(IrUiView, other_views).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/website/models/ir_ui_view.py", line 51, in write
    return super(View, self).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 493, in write
    res = super(View, self).write(self._compute_defaults(vals))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3564, in write
    real_recs._validate_fields(set(vals) - set(inverse_fields))
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 1176, in _validate_fields
    check(self)
  File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_ui_view.py", line 396, in _check_xml
    raise ValidationError("%s\n\n%s" % (_("Error while validating view"), tools.ustr(e)))
odoo.tools.convert.ParseError: "Fout bij valideren weergave
Veld 'margin_percentage2' bestaat niet
Fout context:
Weergave`view.order.form.sale.margin`
[view_id: 2953, xml_id: sales_global_margin.view_order_form_sale_margin, model: sale.order, parent_id: 1324]
None" while parsing /opt/odoo/addons/sales_global_margin/views/sale_order_views.xml:2, near
<odoo>
<record id="view_order_form_sale_margin" model="ir.ui.view">
  <field name="name">view.order.form.sale.margin</field>
  <field name="model">sale.order</field>
  <field name="inherit_id" ref="sale.view_order_form"/>
  <field name="arch" type="xml">
  
   <data><header>
        <button name="action_update_margin" string="Update Margin" type="object" class="btn-primary" attrs="{'invisible':[('state','in',['sale','done','cancel'])]}"/>
    </header>
  
    <field name="date_order" position="after">
      <field name="margin_percentage"/>
    </field>
    <field name="date_order" position="after">
      <field name="margin_percentage2"/>
    </field>
    <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">
      <field name="margin_percentage"/>
    </xpath>
    <xpath expr="//page/field[@name='order_line']/form/group/group/field[@name='price_unit']" position="before">
      <field name="margin_percentage"/>
    </xpath>
    <xpath expr="//page/field[@name='order_line']" position="attributes">
      <attribute name="context">
        {'default_margin_percentage': margin_percentage}
      </attribute>
    </xpath>
  </data></field>
</record>
</odoo>
Avatar
Discard

Have you restarted the server and updated your module?