Skip to Content
Menu
This question has been flagged
1 Reply
5244 Views

I need to generate timesheets report for a given user in a given data range.
I also need to sum the timesheets hours by date so each row in the report has unique date.

I have simple report ready as well as wizard for picking particular user and dates. But I'm having trouble with passing data to the report. When I click the print button on my wizard I get this error:

ProgrammingError: relation "hr_timesheet_karty_wizard" does not exist
LINE 1: INSERT INTO "hr_timesheet_karty_wizard" ("id", "date_from", ...

I'm not really sure what to do with `records`. Should I put them in 'doc_ids' or 'doc_ids'?

I'm also not sure how to sum the records by date.

I'm using Odoo 8.


Here is my python code:

from openerp import api, models, fields
from datetime import datetime

class hr_timesheet_karty_wizard(models.AbstractModel):
    _name = 'hr.timesheet.karty.wizard'
    
    employee_id = fields.Many2one(comodel_name="hr.employee"required=True)
    date_from = fields.Date(default=fields.Datetime.now, required=True)
    date_to = fields.Date(default=fields.Datetime.now, required=True)

    @api.multi
    def print_report(selfdata=None):
        
        records = self.env['hr.analytic.timesheet'].search([('employee_id''='self.employee_id),('date_from''>='self.date_from),('date_to''<='self.date_to)])   
        # sum records hours if date is the same (group by date)

        report_obj = self.env['report']
        report = report_obj._get_report_from_name('hr_timesheet_karty.template_hr_timesheet_karty')
        docargs = {
            'doc_ids'self._ids,
            'doc_model': report.model,
            'docs': records,
        }
        return report_obj.render('hr_timesheet_karty.template_hr_timesheet_karty', docargs)



Here is my wizard:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>

    <record id="view_hr_timesheet_karty_wizard" model="ir.ui.view">
        <field name="name">hr.timesheet.karty.wizard.form</field>
        <field name="model">hr.timesheet.karty.wizard</field>
        <field name="arch" type="xml">
        <form string="Leaves by Department">
            <group>
                <field name="employee_id"/>
                <field name="date_from"/>
                <field name="date_to"/>
            </group>
            <footer>
                <button name="print_report" string="Print" type="object" class="oe_highlight"/> or
                <button string="Cancel" special="cancel" class="oe_link"/>
            </footer>
        </form>
        </field>
    </record>

    <record id="action_hr_timesheet_karty_wizard" model="ir.actions.act_window">
        <field name="name">Time sheet report</field>
        <field name="res_model">hr.timesheet.karty.wizard</field>
        <field name="view_type">form</field>
        <field name="view_mode">form</field>
        <field name="view_id" ref="view_hr_timesheet_karty_wizard"/>
        <field name="target">new</field>
    </record>

    <menuitem id="menu_hr_timesheet_karty_wizard"
        name="Time sheet report"
        parent="hr.menu_hr_reporting_timesheet"
        action="action_hr_timesheet_karty_wizard"
        sequence="1"
        icon="STOCK_PRINT"/>
        
  </data>
</openerp>



And here is my report:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
  <data>
    <report
        id="action_hr_timesheet_karty"
        string="Time sheet report"
        model="hr.analytic.timesheet"
        report_type="qweb-pdf"
        name="hr_timesheet_karty.template_report_hr_timesheet_karty"
    />
        
    <template id="template_hr_timesheet_karty">
        <t t-call="report.html_container">
            <t t-call="report.external_layout">
                <div class="page">

                    <table class="table table-condensed">
                        <thead>
                            <tr>
                                <th>User</th>
                                <th>Date</th>
                                <th>Time</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="docs" t-as="o">
                                <td><span t-field="o.user_id.name"/></td>
                                <td><span t-field="o.date"/></td>
                                <td class="text-right"><span t-field="o.unit_amount"/> h</td>
                            </tr>
                        </tbody>
                    </table>

                </div>

            </t>
        </t>
    </template>

  </data>
</openerp>



Please help


Avatar
Discard
Best Answer

Hello Andrzej,

In v8 , AbstractModel model define with osv.AbstractModel 

Please find following example of AbstractModel:

class hr_timesheet_karty_wizard(osv.AbstractModel)


For searching timesheet records, 

sheet_obj = self.pool['hr.analytic.timesheet']

sheet_ids = sheet_obj.search(cr, uid,

            [('employee_id', '=', self.employee_id),

            ('date_from', '>=', self.date_from),

           ('date_to', '<=', self.date_to)])

Can you please try above object for found timesheet records ?

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Related Posts Replies Views Activity
1
May 21
2865
1
Apr 20
2326
4
Oct 19
8647
1
Jan 18
7893
1
Feb 17
3901