Search code examples
odooodoo-10odoo-11odoo-view

Field does not exist ODOO


I am using Odoo 11 and get the below error when installing a custom module. This is a module that is working in Odoo 10. I cant figure out where I am going wrong.

Field `custom_discount_product_id2` does not exist

Error context:
View `pos.config.custom.discount.form.view`
[view_id: 1029, xml_id: pos_custom.view_pos_config_form_custom_discount, model: pos.config, parent_id: 730]
None" while parsing /odoo/custom/addons/pos_custom/views/pos_custom_sale_view.xml:22, near
<record model="ir.ui.view" id="view_pos_config_form_custom_discount">
            <field name="name">pos.config.custom.discount.form.view</field>
            <field name="model">pos.config</field>
            <field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
            <field name="arch" type="xml">
                    <xpath expr="//div[@id='title']" position="after">
                    <group string="Custom Discount">
                        <field name="custom_discount_product_id2"/>
                    </group>
                </xpath>
            </field>
        </record>

Here is my sale.py file

from odoo import api, fields, models


class PosConfig(models.Model):
    _inherit = 'pos.config'

    custom_discount_product_id2 = fields.Many2one('product.product', string='Custom Discount Product')

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

And here is the view file.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>

        <record model="ir.ui.view" id="view_pos_config_form_custom_discount">
            <field name="name">pos.config.custom.discount.form.view</field>
            <field name="model">pos.config</field>
            <field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//div[@id='title']" position="after">
                    <group string="Custom Discount">
                        <field name="custom_discount_product_id2" />
                    </group>
                </xpath>
            </field>
        </record>
    </data>
</openerp>

I've checked other modules, restarted server, but for some reason the field is not created.


Solution

  • Make sure <your_module>/__init__.py contains:

    from . import models
    

    and that <your_module>/models/__init__.py contains:

    from . import sale