Monday, 1 August 2016

How to Create Wizard on Odoo ?



https://dedyyuristiawan.blogspot.com/


Hello world. As i promise on this post How to Call Wizard from XML Button Odoo, i will share about wizard on Odoo. As you can see on previous post i just call wizard on the xml file. Now, i will share how to create wizard on Odoo. You know, wizard on Odoo is like pop up when in website, so in wizard data will save in memory, not in database Odoo. Usually we show wizard is for input additional data. So lets do it.

On this post, i just share wizard, if you want call wizard, you can read on this post How to Call Wizard From XML Button Odoo. So you can on my wizard.xml file bellow.

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="dedy_yuristiawan_wiz" model="ir.ui.view">
            <field name="name">dedy.yuristiawan.wizard.name</field>
            <field name="model">dedy.yuristiawan.wizard</field>
            <field name="arch" type="xml">
                <form string="Hi i am wizard">
                    <group>
                        <field name="name"/>
                    </group>
                    <footer>
                        <button name="create_request" 
                            string="Finished" type="object" 
                            class="btn-primary"/>
                        <button string="Cancel" 
                            class="btn-default" 
                            special="cancel" />
                    </footer>
                </form>
            </field>
        </record>

        <record id="action_view_wizard" model="ir.actions.act_window">
            <field name="name">Hi i am a wizard</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">dedy.yuristiawan.wizard</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="dedy_yuristiawan_wiz"/>
            <field name="target">new</field>
        </record>
    </data>
</openerp>

Ass you can see, just 2 record on my xml file. On the bottom record i have name, type, model, view type, view mode, view_id, and target. The important is :

1. Type ir.actions.act_window it mean will show window like from view usually.

2. Res_model dedy.yuristiawan.wizard it's my model.

3. Target new it will show as new form, you can set current, it mean will show your current form.

4. View Id dedy_yuristiawan_wiz it will call top record as you can see. You know Odoo its run from Top to Bottom, That's why i put dedy_yuristiawan_wiz on the top (it mean, i make declaration first before i call it). 

5. On the Top record at  it look like similar with bottom record, i just add field, that i create on python file, and two button, button Cancel will dismiss this wizard and button Finish will call function create_request on my python file.

And this one, i call it python file.

from openerp import models, fields, api, _
from openerp.exceptions import UserError, ValidationError, Warning


class DedyYuristiawan(models.TransientModel):
    _name = "dedy.yuristiawan.wizard"
    
    name = fields.Char('Name', required=True)
    
    @api.multi
    def create_request(self):
        print "You click finish"

        return True

As you can see, the class have name models.TransientModel it mean wizard. And then i create field name that i call in  my xml file <field name="name"/> . Last i create function def create_request(self). That's i told you before, if want to call this function i create button Finish with this syntax <button name="create_request" string="Finished" type="object" button with name and type object.

That's it. So if want make wizard you can read first, you can create code python first and then xml code. Aha i forget something, Usually these file (python and xml) i put on folder Wizard, and the i declare on the __init__.py with include python file and then on __openerp__.py with this 'wizard/split_wo_wizard.xml' put on the top.

It real that's it. Aha. Just read first, if you still confuse about my code, you can write comment bellow. Thanks.
Share:

Friday, 29 July 2016

How to Create Controller or Link Odoo Website ?



https://dedyyuristiawan.blogspot.com


Hello world. Today I got happy felling but i don't where it come from? Lol just for laugh. So today i am gonna share about controller in Odoo. Actually for the first time i hear that, i don't know what should i do? okay in this time, i will try to make definition from myself, you can make your definition too on the comment bellow, we make definition together.

Controller is class on Odoo that can use for us when we want to make link on website, and then show anything that what we want to show on your website. I hope like that, so i am not give you wrong way. So how to create controller on Odoo? Lets see.

This is my class controller, my function on cons.py file :

import logging
from openerp import SUPERUSER_ID
from openerp import http
from openerp.http import request
from openerp import models, api

class website_qty(http.Controller):
 
    @http.route(['/page/dedy'], type='http', auth="public", website="True")
    def index(self, **post):
        wcl = []
        dedy = request.env['dedy.yuristiawan']
        dy = dedy.search([], state='draft')
        return request.render('dedy_controller.index_assets_frontend_view', {              
            'dedy': dy,
        })

As you can see, i can make conclution for this code :

1. Name of the class, you can create name anything what you want, but in this class we need to declaration first. For declaration you can use this code.

http.Controller

2. Name of the function, as you can see you can create name anything what you want, but in the above of name function you need to declaration your url, some thing like this.

@http.route(['/page/dedy'], type='http', auth="public", website="True")

3. Return , actually for return its not really need similar with on python, but in controller you need to render for show data to xml view. something like this.

return request.render('dedy_controller.index_assets_frontend_view', {              
            'dedy': dy,
        })

dedy_controller is my module, index_assets_frontend_view is my id in xml file, and then the important id dedy is variable that we want to show in xml file or on website.

4. Inside of the function you can do anything what you want. like in my code, i just show data from my model dedy.yuristiawan, and then i set in return on variable dedy.

5. Just it.

And this one its my cons.xml file :

<template id="index_assets_frontend_view">
    <title>Test Input</title>
    <t t-call="website.layout">
        <t t-set="title">Dedy Yuristiawan</t>
            <div class="oe_structure">
                <div class="container">
                    <t t-foreach="dedy" t-as="value">
                        <td class="brctbl-col4 js_loc">
                            <p>
                                <t t-esc="value.name"/>
                            </p>
                        </td>
                    </t>
                </div>
            </div>
    </t>
</template>

As you can see, i can make conclution for this code :

1. Template id, its really important for controller, cause usually function on controller bring value to xml with calling template name. See my conclution cons.py file number three.

<template id="index_assets_frontend_view">

2. As you can see i do looping with variable dedy, this variable is from function controller that we set on return. You can see, my conclution cons.py file number 3.

<t t-foreach="dedy" t-as="value">

t-as, it means you can you put value dedy to variable value.

3. And last you had variable, you can do anything, show anything to website, with qweb sintax Odoo. like this looping, show field.

looping :

<t t-foreach="dedy" t-as="value">

show value :

<t t-esc="value.name"/>

4. Actually you can make link on xml code, you can use action on form or just (a href) and link will be the call controller function python.

<a t-att-href="'/page/dedy_next_view/" name="dedy_next_id" class="btn btn-default">Go to next link</a>

action="/page/test_input_view_form" method="post"

5. Last one, if you want to make post method, you need to add input like this one.

<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>

This is for security to protect our website, that we need get token from Odoo. This is rule for the Odoo 9.

That's it, you can write comment bellow if you still confuse about my code. i hope this can help you little bit. Ahha

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:


<br>


Advice for contacting me at dedyy54@gmail.com