Friday, 29 July 2016

How to Inherit Function Odoo ?



https://dedyyuristiawan.blogspot.co.id


Hello wold. Today i got inspiration from my comment's. He just started develop Odoo. You know, actually i am so appreciate that, maybe we feel difficult to learn something new, and we don't have person to help us, just world wide web. I know, because for first time I learn Odoo, i feel so disappointed for myself, I just think 'i can't do it'. But i keep learn Odoo, cause i am still work with company use Odoo aha. But huyaa for time by time i can learn the process Odoo, new syntax from python, qweb, or maybe js, css, etc cause my background its not from website. And you know, now i am realise that how's can develop Odoo is easy, i am so realise that. Just little bit share my misery. Lol

So just go ahead right? today i am gonna share about how to inherit function Odoo, for example in this post i will inherit function create. Just for note, function create is automatically create when we develop view form or tree. Aha you know function create in base Odoo, it always have the name 'create'. And usually have one parameter is self or two parameter is self, vals (variable that we have). For example in Odoo base, we have create like this.

@api.model
def create(self, vals):
    .
    .
    .
    .
    return A

As you can see create have two variable, self and vals. And now i want to inherit that. see my code.

class AddFieldProduct (models.Model):
    _inherit = "product.template"    
 
    info = fields.Char('Info') 

    @api.model
    def create(self, vals):
        if self.info :
            self.info = 'is a field info'
        return super(AddFieldProduct, self).create(vals)

as you can see, the requirement is :

1. We need to create file something like me, i create file inherit_function.py and then we need to create class like 'class inherit_function (models.Model)' and type class 'model'.

2. Declaration class with _inherit = "product.template", it mean we want to inherit model product.product.

3. Write name and parameter, similar with function, see def create(self, vals) and add @api.model above the function.

4. Add what you what you want need. Like this one i just want to set field info is 'is a field info'. if self.info : self.info = 0

5. And last add return with super like this one, return super(inherit_function, self).create(vals). inherit_function is a my class, see on the top.

7. When we inherit create like that, we put there condition on the function, field info will save 'is a field info' in database. trust me.

6. That's it, easy right? 

So the conclusion is Semangat!! like my boss always say to me, when i got problem with my code. Lol


Share:

Wednesday, 27 July 2016

How to add or Ihherit Action on Odoo ?



https://dedyyuristiawan.blogspot.com
Action Odoo


Hello world. Today i've new knowledge about develop Odoo. do you ever see action in odoo, some thing like picture on top, beside print? its action, and now i will share how to inherit or add action on odoo. let's do this.

Actually its very simple, like you inherit field or another view. in this case, i just add xml file that inherit to parent. This is my xml file.

<record model="ir.values" id="set_efaktur">
    <field name="name">My Action</field>
    <field name="value" 
    eval="'ir.actions.act_window,' + str(ref('wizard_action'))" />
    <field name="key">action</field>
    <field name="model">dedy.yuristiawan</field>
</record>

You can read this description :

1. As you can see i set record in the ir.values. and then i put name My Action.
2. And then in the value i just set value, and eval ("'ir.actions.act_window,' + str(ref('wizard_action'))") it will be show my wizard. wizard_action is name of wizard template.
3. Next line i just declaration key with action.
4. And the last, this is really important, i put my action in the my custom model dedy.yuristiawan.
5. Just it

Huya, simple right? so this is post about inherit or add new action in Odoo, if you still confuse about my code you can fill comment bellow. I hope this is can help you. See yaa
Share:

Monday, 25 July 2016

How to make sequence name Odoo



http://dedyyuristiawan.blogspot.com


Hello world. Today i am gonna share about little trick in Odoo, this is a how to make field name sequence. Actually its basic from Odoo, but i just know when i got task like that. Lol. So just follow my step by step.

1. Declaration code for sequence

For declaration sequence i create xml file like this. the code is test.dedy.yuristiawan, prefix DY, padding is 5, and it would be like this 'DY00001'. Prefix is for first char (DY) and padding is for long number (00001). You can call this sequence with test.dedy.yuristiawan. See this code

  <?xml version="1.0" encoding="utf-8"?>  
  <openerp>  
    <data noupdate="1">  
      <record id="seq_test_dedy_yuristiawan" model="ir.sequence">  
        <field name="name">Test Dedy Yuristiawan</field>  
        <field name="code">test.dedy.yuristiawan</field>  
        <field name="prefix">DY</field>  
        <field name="padding">5</field>  
        <field eval="1" name="number_increment"/>  
      </record>  
    </data>  
  </openerp>  

and then i put this code in test_dedy_yuristiawan.xml

2. Override Function set Field Name, before Create.

Yap, now i override create function like this. This code i set field name readonly=True (anybody can't change) and call  self.env['ir.sequence'].next_by_code('test.input.machine') that i create in xml file. If you don't know about override function i will create specially post for How to Override Function in Odoo in the next post.

name = fields.Char('Code Dedy', readonly=True)

@api.model
def create(self, vals):
    print "+++++++++++++++++++++++++++++++++++++++++++++++++"
    print "prepare inherit create function"
    print "change the name TI with sequence"
    vals['name'] = self.env['ir.sequence'].next_by_code('test.input.machine')
    print "Inherit complete"
    print "+++++++++++++++++++++++++++++++++++++++++++++++++"
    return super(test_input_machine, self).create(vals)


3. Declaration xml file into __openerp__.py

Last step don't forget to declaration xml file to __openerp__.py

'data'          : [
                         'data/test_dedy_yuristiawan.xml',

That it, i hope this is can help you little bit, so if you still confuse about my code, you fill comment bellow and i will try to help you later. Thanks.



Share:

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