Odoo Help


How can I add custom fields that calculate a combination of other fields? Like Sales Margin as a percentage? Without a module.

Ray Carnes
on 9/17/16, 8:04 PM 2,574 views

I know I can write code and create a module to add custom fields to Odoo.

I also know that custom fields can be added via the User Interface easily.  Is it possible to create a new field that gets it value automatically (by a calculation) from another set of fields?


Ray Carnes

--Ray Carnes--
| 9 7 9
Keyport, United States
--Ray Carnes--

Senior ERP Analyst

OpenERP 6.1, 7.0; Odoo 8.0, 9.0, 10.0 and 11.0.

Completed Odoo Functional and Technical Training.

Functional Areas:

  • CRM/Sales

  • Inventory

  • Manufacturing

  • Accounting

  • Purchasing

Major Skills:

  • Business Process Reengineering

  • Efficiency Consulting

  • User Needs and GAP Analysis;

  • Functional and Technical Design;

  • Prototyping and Proof of Concepts;

  • Requirements Specifications;

  • Agile Implementation;

  • Data Migration;

  • Configuration & Customization (UI and code);

  • Integration - Odoo and non Odoo Applications and Services;

  • Training and Knowledge Transfer;

  • Go Live Support;

  • Helpdesk;

  • Version Upgrades and Migration.

  • Accounting Expert.

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. 

I am a skilled Communicator and I only take the serious things seriously!

Ray Carnes
On 9/17/16, 8:25 PM

1.  Enable the option to show Margins on Sales Orders:

       Sales --> Configuration --> Settings  


2.  Add the field via the User Interface:

      Settings --> Technical --> Database Structure --> Fields



The code for the Compute section is:

for record in self:
    if record['amount_total'] > 0: 
record['x_margin_percentage'] = record['margin'] / record['amount_total']

3. Add the field to the User Interface, by creating a view that inherits and overrides the Odoo Sales Order Form view that adds the margin field:

      Settings --> Technical --> User Interface --> Views



The XML for the Architecture field is:

<field name="margin" position="after">    
<field name="x_margin_percentage">

Finished Customization:

Note: You may also want to use amount_untaxed instead of amount_total if you don't want tax included in the margin calculation

Ray Carnes
on 10/24/16, 10:11 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

3 follower(s)


Asked: 9/17/16, 8:04 PM
Seen: 2574 times
Last updated: 2/17/18, 10:30 AM