Home > Back-end >  Odoo 14 field does not get added to res.company
Odoo 14 field does not get added to res.company

Time:12-22

I simply want to add two new Binary fields to the res.company model

To achieve this, in my module, I have added a "company.py" file in the module/models folder

from odoo import models, fields

class Company(models.Model):
    _inherit = 'res.company'

    header = fields.Binary(string="Header")
    footer = fields.Binary(string="Footer")

and I have added a "company.xml" file in my module/views folder which looks like this

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="view_company_form_inherited" model="ir.ui.view">
            <field name="name">res.company.form.view.inherited</field>
            <field name="model">res.company</field>
            <field name="inherit_id" ref="base.view_company_form"/>
            <field name="arch" type="xml">
            <xpath expr="//field[@name='vat']" position="before">
                <field name="header"/>
                <field name="footer"/>
            </xpath>  
            </field>
        </record>
    </data>

</odoo> 

in the manifest.py file I have added views/company.xml in the data list. I have imported the company file in the init.py file like this:

# -*- coding: utf-8 -*-

from . import [other models], company, [other models]

unfortunately, when I try to load the module in odoo I get the following error:

Field "header" does not exist in model "res.company"

View name: res.company.form.view.inherited
Error context:
 view: ir.ui.view(1772,)
 xmlid: view_company_form_inherited
 view.model: res.company
 view.parent: ir.ui.view(107,)
 file: /PATH/TO/MODULE/views/company.xml

To me, this looks like the modified view works fine, but the py file somehow has not added the two fields 'header' and 'footer' to the 'res.company' model.

What am I doing wrong?

CodePudding user response:

When updating res tables like res.company you need to start your server with the -u your_module option to perform a succesful update.

  • Related