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

how to manage this 2 modules

By
jasper akira
on 4/8/14, 1:43 AM 774 views

hrdata.py

from openerp.osv import fields,osv from openerp import tools from dateutil.relativedelta import relativedelta from datetime import datetime """ Status Keluarga """ Status_Keluarga=[ ('tk','TK'), ('k0','K0'), ('k1','K1'), ('k2','K2'), ('k3','K3'),
] class hrdata_department(osv.osv): _name= "hrdata.department" _description="Daftar Departement" _columns = { 'name': fields.char('Departemen',size=64,required=True) } _sql_constraints = [ ('name', 'unique(name)', 'unique') ] _order = 'name asc' hrdata_department()

class hrdata_level(osv.osv): _name= "hrdata.level" _description="Daftar Level Jabatan" _columns = { 'name': fields.char('Level Jabatan',size=64,required=True) } _sql_constraints = [ ('name', 'unique(name)', 'unique') ] _order = 'name asc' hrdata_level()

class hrdata_bagian(osv.osv): _name= "hrdata.bagian" _description="Daftar Bagian Departemen" _columns = { 'name': fields.char('Bagian',size=64,required=True) } _sql_constraints = [ ('name', 'unique(name)', 'unique') ] _order = 'name asc' hrdata_bagian()

class hrdata_data(osv.osv): _name= "hrdata.data" _description="Data Karyawan"

def _compute_age(self, cr, uid, ids, field_name, arg, context={}):
    result = {}
    now = datetime.now()
    for r in self.browse(cr, uid, ids, context=context):
        if r.tgl_lahir:
            dob = datetime.strptime(r.tgl_lahir,'%Y-%m-%d')
            delta=relativedelta (now, dob)
            result[r.id] = str(delta.years) #if you only want date just give delta.years
        else:
            result[r.id] = 0
    return result

def _get_image(self, cr, uid, ids, name, args, context=None):
    result = dict.fromkeys(ids, False)
    for obj in self.browse(cr, uid, ids, context=context):
        result[obj.id] = tools.image_get_resized_images(obj.image)
    return result

def _set_image(self, cr, uid, ids, name, value, args, context=None):
    return self.write(cr, uid, [ids], {'image': tools.image_resize_image_big(value)}, context=context)

_columns = {
    'name': fields.char('NIK',size=15,required=True),
    'nama': fields.char('Nama',size=256,required=True),
    'jenis_kelamin':fields.selection([('male','Male'),('female','Female')],'Jenis Kelamin',required=True),
    'tgl_masuk': fields.date('Tanggal Masuk'),
    'tgl_keluar': fields.date('Tanggal Keluar'),
    'tgl_ktp': fields.date('Tanggal Berlaku KTP'),
    'kode':fields.many2one('hrjadwal','Jadwal',size=15),
    'department':fields.many2one('hrdata.department','Departemen',size=256),
    'bagian': fields.many2one('hrdata.bagian','Bagian',size=256),  
    'level': fields.many2one('hrdata.level','Level Jabatan',size=256),
    'lokasi':fields.selection([('tml','TML'),('kim','KIM')],'Lokasi',required=True),
    'kepesertaan_jamsostek':fields.date('Kepesertaan Jamsostek'),
    'status_karyawan': fields.selection([
        ('kontrak','Kontrak'),
        ('tetap','Tetap'),
        ('outsoucing','Outsourcing'),
        ],'Status Karyawan'),
    'ket':fields.text('Keterangan'),
    'agama': fields.selection([
        ('islam','Islam'),
        ('kristen','Kristen'),
        ('buddha','Buddha'),
        ('hindu','Hindu'),
        ],'Agama',readonly=False,select=True),
    'no_kpj':fields.char('No Jamsostek',size=15),
    'nama_kpj':fields.char('Nama Jamsostek',size=50),
    'status': fields.selection(Status_Keluarga,'Status',readonly=False,select=True),
    'alamat':fields.char('Alamat',size=50),                 
    'telepon':fields.char('Telepon',size=15),
    'no_ktp':fields.char('No KTP',size=20),
    'no_kk':fields.char('No Kartu Keluarga',size=50),
    'jumlah_anak':fields.char('Jumlah Anak',size=1),
    'tgl_lahir':fields.date('Tanggal Lahir'),   
    'usia' : fields.function(_compute_age, method=True, type='integer', size=32, string='Usia'),        
    'npwp':fields.char('NPWP'), 
    'no_sj':fields.char('No SJ'),   
    'grade':fields.char('Grade'),   
    # image: all image fields are base64 encoded and PIL-supported
    'image': fields.binary("Photo",
        help="This field holds the image used as photo for the employee, limited to 1024x1024px."),
    'image_medium': fields.function(_get_image, fnct_inv=_set_image,
        string="Medium-sized photo", type="binary", multi="_get_image",
        store = {
            'hrdata.data': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
        },
        help="Medium-sized photo of the employee. It is automatically "\
             "resized as a 128x128px image, with aspect ratio preserved. "\
             "Use this field in form views or some kanban views."),
    'image_small': fields.function(_get_image, fnct_inv=_set_image,
        string="Smal-sized photo", type="binary", multi="_get_image",
        store = {
            'hrdata.data': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
        },
        help="Small-sized photo of the employee. It is automatically "\
             "resized as a 64x64px image, with aspect ratio preserved. "\
             "Use this field anywhere a small image is required."),
    }

_sql_constraints = [
    ('name', 'unique(name)', 'unique'),
    ('nama','unique(nama)','unique'),
    ('no_sj','unique(no_sj)','unique'),
]

_order = 'name asc'

hrdata_data()

hrdata_view.xml

<openerp> <data>
<record id="view_hrjadwal" model="ir.ui.view"> <field name="name">hrjadwal.data.form</field> <field name="model">hrjadwal.data</field> <field name="arch" type="xml"> <form string="Data Jadwal Kehadiran" version="7.0"> <field name="name"/> <field name="masuk"/> <field name="pulang"/> <field name="msabtu"/> <field name="psabtu"/> </form> </field> </record>

<record id="hrjadwal_view_tree" model="ir.ui.view">
        <field name="name">Jadwal Kerja</field>
        <field name="model">hrjadwal.data</field>
        <field name="arch" type="xml">
            <tree string="Jadwal Kerja" editable="bottom">
                <field name="name"/>
                <field name="masuk"/>
                <field name="pulang"/>
                <field name="msabtu"/>
                <field name="psabtu"/>
            </tree>
        </field>
</record>


<record model="ir.actions.act_window" id="action_test">
    <field name="name">Jadwal Karyawan</field>
    <field name="res_model">hrjadwal.data</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<menuitem sequence="4" id="menu_jadwal" parent="hrdata.mnu_hrdata" name="Jadwal Kerja"/> <menuitem name="Jadwal" action="action_test" id="menu_jadwal" parent="hrdata.mnu_hrdata_config" sequence="2"/> </data>

</openerp>

hrjdwl.py

from openerp.osv import fields,osv

class hrjadwal_data(osv.osv): _name= "hrjadwal.data" _description="data" _columns = { 'name': fields.char('Jadwal',size=256,required=True), 'masuk':fields.char('Jam Masuk Hari Biasa', size=5,required=True), 'pulang':fields.char('Jam Pulang Hari Biasa', size=5,required=True), 'msabtu':fields.char('Jam Masuk Hari Sabtu', size=5,required=True), 'psabtu':fields.char('Jam Pulang Hari Sabtu', size=5,required=True), }

_sql_constraints = [
    ('name', 'unique(name)', 'unique'),
]
_order = 'name asc'

hrjadwal_data()

hrjdwl_view.xml

<openerp> <data>
<record id="view_hrjadwal" model="ir.ui.view"> <field name="name">hrjadwal.data.form</field> <field name="model">hrjadwal.data</field> <field name="arch" type="xml"> <form string="Data Jadwal Kehadiran" version="7.0"> <field name="name"/> <field name="masuk"/> <field name="pulang"/> <field name="msabtu"/> <field name="psabtu"/> </form> </field> </record>

<record id="hrjadwal_view_tree" model="ir.ui.view">
        <field name="name">Jadwal Kerja</field>
        <field name="model">hrjadwal.data</field>
        <field name="arch" type="xml">
            <tree string="Jadwal Kerja" editable="bottom">
                <field name="name"/>
                <field name="masuk"/>
                <field name="pulang"/>
                <field name="msabtu"/>
                <field name="psabtu"/>
            </tree>
        </field>
</record>


<record model="ir.actions.act_window" id="action_test">
    <field name="name">Jadwal Karyawan</field>
    <field name="res_model">hrjadwal.data</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree,form</field>
</record>

<menuitem sequence="4" id="menu_jadwal" parent="hrdata.mnu_hrdata" name="Jadwal Kerja"/> <menuitem name="Jadwal" action="action_test" id="menu_jadwal" parent="hrdata.mnu_hrdata_config" sequence="2"/> </data>

</openerp>

for the openerp.py

hrdata :

{ 'name': 'HR Data', 'version': '0.6', 'category': 'HRData', 'description': """This module is just for Data Karyawan.""", 'author': 'Jasper', 'depends': ['base','hrjdwl'], 'data': [ 'security/ir_rule.xml', 'security/ir.model.access.csv', 'hrdata_view.xml', 'hrdata_view_department.xml', 'hrdata_view_level.xml', 'hrdata_view_bagian.xml', ], 'installable': True,

}

hrjdwl.py

{ 'name': 'HR Jadwal', 'version': '0.5', 'category': 'HRData', 'description': """This module is just for Jadwal Data Karyawan.""", 'author': 'Jasper', 'depends': ['hrdata'], 'data': [ 'hrjadwal_view.xml', ], 'installable': True,

}

my problem is i want to take data from hrjadwal to a field name 'kode' in hrdata_data , but when i use many2one it's always failed to upgrade

thanks for your helps :)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

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

Question tools

1 follower(s)

Stats

Asked: 4/8/14, 1:43 AM
Seen: 774 times
Last updated: 3/16/15, 8:10 AM