openerp下载考勤机

时间:2014-03-05 07:50:26

标签: openerp

请我解决这个问题。我正在使用openerp下载考勤机并将该数据插入到我的表中,但是我必须使用one2many字段将数据从机器查看到网格中,如何在下载此脚本后传递数据。我正在使用zkclock模块来获取数据。

hr_machinezem560.py

    ....
import zkclock
import from osv import osv, fields

....
class hr_machinezem560(osv.osv):
_name = "hr_machinezem560"
_columns = {
    'date_from':fields.date("Date From"),
    'date_to':fields.date("Date To"),
    'proses_id':fields.one2many('hr.machinezem560_details', 'proses_id', 'Prosess Download')
}

def action_download(self, cr, uid, ids, context=None):

    domain = {}

    params = self.browse(cr, uid, ids, context=context)[0]

    start_date = date_object = datetime.datetime.strptime(params.date_from, '%Y-%m-%d')
    end_date = date_object = datetime.datetime.strptime(params.date_to, '%Y-%m-%d')

    date_list = [dt.strftime("%Y-%m-%d") for dt in rrule(DAILY, dtstart=start_date, until=end_date)]

    host = '192.168.1.201'
    port = 4370
    password = ''

    s, r = zkclock.connect(host, port, password)
    r = zkclock.disable(s, r)

    r, userdata = zkclock.get_user_data(s, r)
    r, logdata = zkclock.get_log_data(s, r)

    r = zkclock.enable(s, r)
    r = zkclock.disconnect(s, r)


    if userdata and logdata:
         logdata = zkclock.assemble_log_data_from_packets(logdata)
         users = zkclock.unpack_users_to_dict(userdata)
    logging.debug(users)
    loglist = []

    while((len(logdata)/LOG_DATA_SIZE) >=1):
        loglist.append(logdata[:LOG_DATA_SIZE])
        logdata = logdata[LOG_DATA_SIZE:]

    logs = []

    for i in  loglist:
        log_entry = zkclock.unpack_log(i)
        timestamp = zkclock.decode_time(log_entry.time)
        verification_method = log_entry.decode_verified()
        try:
            user_name = users[log_entry.uid].name
        except KeyError:
            user_name = "Unknown user: %s" % log_entry.uid

        logs.append([timestamp,str(log_entry.uid), verification_method])

    attance_det = self.pool.get("hr.machinezem560_details")

    for log in logs:
        if log[0].strftime('%Y-%m-%d') in date_list:
            values = {
              'employee': log[1],
              'timesheet':  log[0],
              'status':log[2]
            }

            attance_det.create(cr, uid, values, context=context)

hr_machinezem560()

class hr_machinezem560_details(osv.osv):

    _name = "hr.machinezem560_details"

    _columns = {
                    'employee': fields.char("Employee Name", size=80),
                    'timesheet':fields.datetime("Time Sheet"),
                    'status': fields.char("Status", size=10),
                    'proses_id':fields.many2one('hr_machinezem560','Prosess Download')

                }

hr_machinezem560_details()

视图:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record id="hr_batch_machine_view_form" model="ir.ui.view">
            <field name="name">Attendance Machine Batch Process</field>
            <field name="model">hr_machinezem560</field>
            <field name="type">form</field>
            <field name="arch" type="xml">
                <form string="Download ZEM560 Data" version="7.0">
                    <group name="up">
                        <label for="date_from" string="Timesheet Period"/>
                        <div>
                            <field name="date_from" class="oe_inline"/> to <field name="date_to" class="oe_inline"/>
                            <div class="oe_right oe_button_box" name="right_top_button">
                                <button name="action_download" string="Download" type="object"/>
                            </div> 
                        </div>
                    </group>
                    <group name="down">
                      <field name="proses_id" colspan="3" nolabel="1" readonly="1">
                        <tree string="Attendance Data">
                            <field name="employee"/>
                            <field name="timesheet"/>
                            <field name="status"/>
                        </tree>
                      </field>
                    </group>
                </form>
            </field>
        </record>

        <record id="action_batch_hr_machine_view" model="ir.actions.act_window">
            <field name="name">Attendance Machine Batch Proses</field>
            <field name="res_model">hr_machinezem560</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="target">new</field>
        </record>

        <menuitem  
            id="menu_hr_absensiRoot" 
            name="Absensi" 
            sequence="3"
            parent="hr.menu_hr_root"
        />  
        <menuitem  
            id="menu_hr_mesin_Absensi" 
            name="Mesin Absensi ZEM560" 
            sequence="1"
            parent="menu_hr_absensiRoot"
            action="action_batch_hr_machine_view"
        />  
    </data>
</openerp>

0 个答案:

没有答案