Tuesday, 17 May 2016

How to Add Field Odoo


https://dedyyuristiawan.blogspot.co.id/


Hello world. Today i am gonna show you " how to add field or inherit field Odoo ". Before we add field, i can tell what's Odoo? " Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management etc ", you can check in their web www.odoo.com . So first thing if you want to add field Odoo you must know What's inheritance? if you don't know about it, you can read this post. After that you can follow my steps.

In this tutorial i use odoo 9 community, and i will show you how to add field in product view. This is my view in product. And now i will add field after "Product Type" field. Just follow my steps.

https://dedyyuristiawan.blogspot.co.id
View Product Odoo


1. Activate the Developer Mode

Open help menu - about - activate the developer mode

https://dedyyuristiawan.blogspot.co.id
Activate Developer Mode


2. Find Field Name Want You Put your new Field

After you activate the developer mode, we can know name of the field, and the way to know name of filed is just put your cursor to field.

https://dedyyuristiawan.blogspot.co.id
Find Field Name

3. Find Parent Object and Parent View

Remember in this tutorial i will put my new field, after Product Type field. To find parent object and parent view just click Open debug menu (top right corner) - Edit form view and you will see view like this.

https://dedyyuristiawan.blogspot.co.id
View Edit Form View Odoo

As you can see product.template is parent object and product.product_template_only_form_view is parent view. After you know name field, parent object and parent view we can begin with the code.

4. Create Folder and 4 File inside the folder

i just create folder and give name dedy_custom_field, 4 file is __init__.py , __openerp__.py , add_field_product_view.xml , add_field_product.py.

__init__.py 

import add_field_product # Name file py

Its just import file py that your have created.

 __openerp__.py

{
    'name'          : 'Dedy Custom Fields Product',     # Name App
    'version'       : 'v.1.0',                                           # No Version
    'summary'       : 'Dedy Custom Fields Product', # Name Sumary
    'sequence'      : 1,                                                # No App
    'author'        : 'Dedy Yuristiawan',                      # Name Author
    'description'   : """                            
 
                        author : Dedy Y
                     
                        v.1.0 : \n
                        This module for add additional fields in Product\n
                     
         
                      """,                                                # Name description
    'category'      : 'field',                                      # Name category
    'depends'       : ['base','product'],                    # Name point parent
    'data'          : [
                        'add_field_product_view.xml',
                      ],                                                  # Name file xml
    'installable'   : True,                  
    'application'   : True,
    'auto_install'  : False
}
The point from this file is depends (from parent object), data (file xml), and name app.  

add_field_product.py

add_field_product.py

from openerp import tools
from openerp import models, fields, api
from pygments.lexer import _inherit

class AddFieldProduct (models.Model):# Name class
    _inherit = "product.template"    # Name parent object
 
    info = fields.Char('Info')       # Name field want you show to your xml with char type
The point from this file is name parent object and variable field

add_field_product_view.xml


<openerp>
    <data>
   
     <record model="ir.ui.view" id="add_field_product_tree">              
     # For the tree view and id field (whatever)
         <field name="name">add.field.product.tree</field>  
         # Name field (whatever)
         <field name="model">product.template</field>     
         # Parent object
         <field name="inherit_id" ref="product.product_template_tree_view"/>
         # Parent View
         <field name="arch" type="xml">
     <xpath expr="//field[@name='type']" position="after"> 
     # Name field and Position (after)
       <field name="info"/>         
       # Your new Field
             </xpath>
         </field>
     </record>
   
     <record model="ir.ui.view" id="add_field_product_form">    
     # For the tree view and id field (whatever)
      <field name="name">add.field.product.form</field>    
      # Name field (whatever)
      <field name="model">product.template</field>     
      # Parent object
      <field name="inherit_id" ref="product.product_template_only_form_view"/>
      # Parent View
      <field name="arch" type="xml">
      <xpath expr="//field[@name='type']" position="after"> 
  # Name field and Position (after)
        <field name="info"/>         
         # Your new Field
   </xpath>
      </field>
     </record>  
   
    </data>
</openerp>


 The point from this file is name (its whatever), model (from parent object), inherit_id (from parent view), Name field from odoo (@name='type') and name field that you already created.

After you already create 4 file and then put into folder addons odoo.

5. Update App List

App - Update App List

6. Find Your App

Apps - Apps

https://dedyyuristiawan.blogspot.co.id
View Apps Odoo


choose your app (Dedy Custom Field Product) that your already created. and then install.

7. See What's Happen

And now we done with this one, we success for add field into or modification Odoo. 

The conclusion is if you want to add field you must know parent object, parent view, and field nearest. After you know it, you can modification odoo. next post i will share about position want you put your field. 

If you have any question just write comment, i will help if i can help you. Don't forget to be happy world. Thanks
Share:
Lokasi: Semarang, Semarang City, Central Java, Indonesia

15 comments:

  1. Wah masnya hebat.. pasti karyawan PCI wkwk

    ReplyDelete
  2. Thank you such a good blog on odoo. It give a good information on how to create field in odoo form.

    ReplyDelete
    Replies
    1. Your welcome, I love learn and share each other :-P

      Delete
  3. broo kalo saya mau rubah tampilan report di customer invoice, gimana tuh? yg harus di inherit apaa? trus skalian mau rubah ukuran kertasnya gimana caranya??

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Good article .also check my blog guys mainly about odoo http://akhmadkresna.github.io

    ReplyDelete
  6. Thanks a lot man! You are awesome! Very easy and helpful for us. Please keep doing this blog about odoo. Your tutorials is good and much informative.

    ReplyDelete
  7. Probado en versiĆ³n 11 y OK.

    ReplyDelete
  8. Thanks for posting this info regarding odoo. I just want to let you know that I have checked out your site and I found it very interesting and informative.

    Odoo development

    ReplyDelete
  9. Thank you for sharing this article I was searching this for a long time.
    Odoo development company.

    ReplyDelete
  10. Great Article!!!!

    Thank you so much for sharing such an amazing piece of information with us regarding Odoo. It is very unique and informational. Keep sharing.Odoo e-Commerce

    ReplyDelete
  11. Informative and helpful Article. Really good work. Appreciate it. You might be looking for Open Source Software Solutions in Bangalore

    ReplyDelete
  12. Very informative article! Thanks for sharing this informative article. Looking for the best AR App Developers in Australia? Reach IDYA Technology.

    ReplyDelete
  13. Great guide on adding fields in Odoo! Super helpful for any odoo development companylooking to customize their modules and improve workflow efficiency.

    ReplyDelete


<br>


Advice for contacting me at dedyy54@gmail.com