Monday, 23 May 2016

Add field with Position Odoo


Hello world. Today i am gonna show you how to add custom field with position odoo. The last post i just share about add field odoo 'after'. In this post i will show you how implementation position add field odoo. Now i still use odoo 9 and module  'Dedy Custom Fields Product' . lets code !!

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

1. Position = "before"
This is my form view product, now i will put my field before product type. i just use code like this. i will put my field before Product type.

<record id="add_field_product_form" model="ir.ui.view">  
     # 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="before">
  # Name field and Position (after)
        <field name="info">      
         # Your new Field
      </field></xpath>
      </field>
</field></record> 
similar like form view, i want change my tree view and just code like this 

<record id="add_field_product_tree" model="ir.ui.view">            
     # 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="before">
     # Name field and Position (after)
       <field name="info">      
       # Your new Field
             </field></xpath>
         </field>
     </field></record>
and finally my form and tree view like this

https://dedyyuristiawan.blogspot.co.id
View Add Position Before



2. Position = "replace"

This is my form view product, now i will put my field before product type. i just use code like this. . i will put my field replace internal reference.

<record id="add_field_product_form" model="ir.ui.view">  
     # 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='default_code']" position="replace">
  # Name field and Position (after)
        <field name="info">      
         # Your new Field
   </field></xpath>
      </field>
     </field></record> 
similar like form view, i want change standard price my tree view and just code like this 

<record id="add_field_product_tree" model="ir.ui.view">            
     # 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='standard_price']" position="replace">
     # Name field and Position (after)
       <field name="info">      
       # Your new Field
             </field></xpath>
         </field>
     </field></record>
and finally my form and tree view like this

https://dedyyuristiawan.blogspot.co.id
View Replace Field Odoo


And the conclusion is still like prev post you must know parent object, parent view, and position. you can use after, before, and replace. 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:

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:


<br>


Advice for contacting me at dedyy54@gmail.com