Skip to Content
Menu
This question has been flagged
1 Reply
12213 Views

Maybe, somebody could help... I am trying to get run a custom module with a new model inheriting from res_partner (example for keeping it short with only 1 additional field):

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

from odoo import models, fields

class FQ_Partner(models.Model):

_name = 'fq.partner'

_inherits = {'res.partner': 'partner_id'}

partner_id = fields.Many2one('res.partner', required=True, ondelete='cascade')

fq_id = fields.Char('FQ Nr.', size=30)   

So far so good. But if I do like that to get a new page in contact form:

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

<odoo>

<record id="personal_information" model="ir.ui.view">

<field name="name">Personal information page for contacts form</field>

<field name="model">res.partner</field>

<field name="inherit_id" ref="base.view_partner_form"/>

<field name="priority">2</field>

<field name="arch" type="xml">

<data>

<xpath expr="//page[@name='internal_notes']" position="after">

<page name="personal_information_page"

string="Personal Information"

attrs="{'invisible': [('is_company','=',True)]}">

<group name="personal_information_group"/>

</page>

</xpath>

</data>

</field>

</record>

</odoo>

The new page is displayed, but if I insert my new field from my new model above, I can not access it (an error message appears that the field does not exist). If I change the model from res.partner to fq.partner (my new model), I do not get the error message any more when installing / upgrading my module, but the page does not get displayed any more. What am I doing wrong? How can I add my new data to this page keeping it displayed?

Avatar
Discard
Best Answer

In Odoo/OpenERP we can inherit or use existing modules object/class/model and views. We can also inherit single field of existing modules. The question is why we need such inheritance.

The purpose of inheritance or why we need inheritance is given below:

  1. To change attributes of some fields which exists on existing/custom model (e.g. making fields readonly,invisible)

  2. To add/modify/delete old or new fields in existing/custom model (e.g. Product, Sales, HR, Fleet Management, Attendance modules model etc)

  3. We can also add buttons in already existing/custom model (form and tree) view by using inheritance

Get code and more explanation: http://learnopenerp.blogspot.com/2018/01/inheritance-in-models-and-views.html

Hope its helpful in your case.

Stay blessed

Thanks


Avatar
Discard