Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

OpenERP form onload [Closed]

By
priyankahdp
on 3/20/13, 2:51 AM 2,214 views

The Question has been closed

by
priyankahdp
on 04/20/2013 03:33:51

I need to create form which related to Employee registration details. my requirement is like this.. when user click the create button it need to load current employee number+1 for emp no field. I need to clarify how to call method '_form_onload()'. Means where is the place to call my function.?

here is my code now

def create(self, cr, uid, vals, context=None):
    vals['register_no'] =self.pool.get('ir.sequence').get(cr, uid, 'bpl.worker')
    worker_reg_seq = super(bpl_worker_registration, self).create(cr, uid, vals, context=context)
    return worker_reg_seq



<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data noupdate="1">
        <record id="seq_bpl_worker_registration" model="ir.sequence.type">
            <field name="name">bpl_worker_registration</field>
            <field name="code">bpl.worker</field>
        </record>

        <record id="seq_bpl_worker_registration" model="ir.sequence">
            <field name="name">bpl_worker_registration</field>
            <field name="code">bpl.worker</field>
            <field name="prefix">BPL</field>
            <field name="padding">5</field>
            <field name="number_next">1</field>
            <field name="number_increment">1</field>
            <field name="company_id" eval="False"/>
        </record>
    </data>
</openerp>

xml added in data section __openerp__.py

on create what exact you want to do ? are you wanted to create auto generate number ?

test
on 3/20/13, 5:21 AM

yes.thats my requirment

priyankahdp
on 3/20/13, 7:41 AM
2

priyankahdp

--priyankahdp--
1089
| 5 5 6
Colombo, Sri Lanka
--priyankahdp--
Java Developer ORACLE Python J2EE Spring Hibernate Struts & Jquery............. :-)
priyankahdp
On 3/20/13, 6:03 AM

For this purpose you have to create sequence and on default when create then call the sequence. It will automatically +1 sequence when ever you create new record.

Example: purchase_sequence.xml put this xml file in openerp.py file in data.

   <record id="seq_type_purchase_order" model="ir.sequence.type">
        <field name="name">Purchase Order</field>
        <field name="code">purchase.order</field>
    </record>
    <record id="seq_purchase_order" model="ir.sequence">
        <field name="name">Purchase Order</field>
        <field name="code">purchase.order</field>
        <field name="prefix">PO</field>
        <field name="padding">5</field>
        <field name="company_id" eval="False"/>
    </record> 



def create(self, cr, uid, vals, context=None):
     if vals.get('name','/')=='/':
        vals['name'] = self.pool.get('ir.sequence').get(cr, uid, 'purchase.order') or '/'
        order =  super(purchase_order, self).create(cr, uid, vals, context=context)
        return order

So same thing you have to create for you employee number : prefix is what you starting point of sequence for you it will be "EMP": padding is how much long you number upto 5 or 10 what ever Hope this help you

Many Thanks & Credits need to go user1576199 @ Stackoverflow

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/20/13, 2:51 AM
Seen: 2214 times
Last updated: 3/16/15, 8:10 AM