Wednesday, 24 August 2011

Making Sequence and Using default dictionary

showing date as default only year (if the year field is in integer format)

'year' : lambda *a: int(time.strftime('%Y')),

******************
making default date as system

'pay_date': lambda self, cr, uid, context: time.strftime('%Y-%m-%d'),

*******************
making default selection value 'basis' to show

'basis': 'order_booking', #no use of lambda here

*******************************
making Sequence field

'name': fields.char('Ls #', size=64, required=True, select=True),
#in default
'name':lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'ls.master'),

#in xml
<!-- Sequence -->
        <record id="seq_type_ls_master" model="ir.sequence.type">
            <field name="name">ls.master</field>
            <field name="code">ls.master</field>
        </record>

        <record id="seq_ls_master" model="ir.sequence">
            <field name="name">ls.master</field>
            <field name="code">ls.master</field>
            <field name="prefix">Ls</field>
            <field name="padding">3</field>
        </record>
       
_________________________________________________________________

Tuesday, 9 August 2011

Creating Openerp buttons

Buttons are declared in xml file like :
<button name=""
              string="Approve"
              type="object"
              icon="gtk-apply" />

it has 'name' attribute where you declare the name of the function which you want to call as you described in the python file.
The 'string' attribute use to declare the name of the button which you want to show.
The 'type' attribute has two (mainly used) values 'object' and 'action'.
The 'icon' attribute use to show different button icon labels.

Here is another example that contains 'special' attribute and no 'name' attribute
When the cancel button is pressed it will automatically close the window without saving.
<button   string="Cancel"
                special="cancel"
                type="object"
                icon="gtk-cancel"/>

In addition there are also other attributes like 'confirm' 'states' e.t.c

Making Wizard

Wizards describe interaction sequences between the client and the server.
A wizard is a succession of steps. A step is composed of several actions;
1. send a form to the client and some buttons
2. get the form result and the button pressed from the client
3. execute some actions
4. send a new action to the client (form, print, ...)

Specifically, wizards can be created just like normal forms, here i am telling the easiest way to experience it all you have to do is to make your python class inherited from (osv.osv_memory) declare all the fields normally as you do.
In the xml where you defined the action for the form just add
<field name="target">new</field>
it will open the wizard in a new window.

Mind it there is another way of creating wizards that use wizard.interface
which i will cover later