Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

which is the standard approach to add new fields to an odoo delivered model ?

By
T Star
on 10/15/15, 9:26 AM 524 views

Hi Team,

I am new to Odoo, could you please help me understand which is the standard approach to add new fields to an odoo delivered model.

Say, if I need to create two new additional fields (profession and hobby) to existing CRM_LEAD model.

I understand that the basic approach is to add those new fields to the _inherit object of CRM_LEAD model

class AddNewfield(models.Model):

_inherit = "crm.lead"

Profession = fields.Char('Profession', size=20, required=True)

Hobby = fields.Char('Hobby', size=20)

But I had come across article stating that its not advisable to add new fields to odoo delivered model, as this might impact future upgrade.

Then, should I have to build a new model adding these two fields and a many2one field to the parent table.

class AddNewModel(models.Model):

_name = "crm.AddNewModel"

Profession = fields.Char('Profession', size=20, required=True)

Hobby = fields.Char('Hobby', size=20)

lead_id = fields.Many2one('crm.lead', required=True)

Let me know if which is the right approach.

As well how will I be able to display the new fields from model crm_AddNewModel in the Leads standard form view.

1st approach is right one, but create a new module for do those changes don't do in "CRM" or any standard module.

Yogesh
on 10/18/15, 2:11 PM
0
Andrea Dalseno
On 10/18/15, 10:23 AM

Hi, if you use the _name attribute in your class you are inheriting the model creating a new (different) one. If you omit the _name, you will inherit from the model extending it. In the first case you will inherit the view definition, but not its design that must be recreated from scratch (or so its seems; I had o do that and have a question open on this matter), in the second case you will operate directly in the standard model/view.

To add a field follow the link given by Temur and read the docs. In the case of extension, i.e. without _name, you will simply need to create your extended view (an XML file, with the correct reference) and add the fields in the desired position with <field name="filedX" position ="before/after..."> or using an Xpath expression (if the name is not unique). You can find a good, simple and readable example in the Geo Localization module (that adds some fields to res.partner). To know the name of the fields you can activate the developer mode and the name of the fields will appear on the screen when you pass the mouse over a field.

This code will add my custom field (titolo) in res.partner view after the field "website" adding a label to the new field and a placeholder (a suggestion) for the field:

<!-- Custom Field -->

<label for="titolo" string="Titolo"/>

<xpath expr="//field[@name='website']" position="after">

<field name="titolo" placeholder="SPETTABILE STUDIO DENTISTICO" />

</xpath>

0

Ray Carnes

--Ray Carnes--
15677
| 9 7 9
Greater Los Angeles, United States
--Ray Carnes--

Senior Odoo Analyst

OpenERP 6.1, 7.0 and Odoo 8.0, 9.0 (Since 2012)

Completed Functional and Technical Training.

Major Skills:

  • Needs Discovery and Requirements Analysis;

  • Function and Technical Specifications;

  • Project Planning;

  • Prototyping and Proof of concepts;

  • Data migration;

  • Configuration & Customization (UI and modules);

  • Integration - data, business logic and service levels;

  • Training and Knowledge transfer;

  • Go Live support;

  • Help desk;

  • Version Migration.

I have over 20 years of experience empowering and enabling users with enterprise information systems that make a real and measurable difference in their ability to proactively manage their businesses and organizations. 

Ray Carnes
On 10/15/15, 1:30 PM

By stating:

_inherit = "crm.lead" 

You are in fact inheriting an Odoo model/class/object, and adding your fields to it.  This is the correct way.  You ARE creating your own model with this method. 

The CRM module from Odoo actually inherits and extends res_partner with new fields (although the the old API): 

https://github.com/odoo/odoo/blob/9.0/addons/crm/res_partner.py 

I agree with Temur, check out the documentation for a more detailed explanation.

0

Temur

--Temur--
2894
| 6 5 7
Tbilisi, Georgia
--Temur--
Programmer
Temur
On 10/15/15, 9:58 AM

I think you can start with the Odoo documentation "Building a Module" at https://www.odoo.com/documentation/8.0/howtos/backend.html

0
Mateo Tibaquira
On 10/15/15, 11:28 AM

I think a relation is too much hassle, you better check the Delegation Inheritance to "embed" your model into "crm.lead" but keeping your data on another table transparently.

About the Views, you may enable the debug mode (/web?debug=1) and manage the current view (Bug icon at the top-right) to see what's the one you need to inherit from and add your fields there.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 10/15/15, 9:26 AM
Seen: 524 times
Last updated: 10/18/15, 2:11 PM