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

I'd like them to follow the general instructions found there for creating a simple columnar data dump of timesheet data with the following columns.

  • task name
  • task date
  • project name
  • employee name
  • hours
 
  • a single week's timesheet is selected
  • for a specified user
  • from within the time-tracking module.

I want to print timesheet ids in excel which has one to many relationship.

Here is my .py code

from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx

class PartnerXlsx(ReportXlsx):

    def generate_xlsx_report(self, workbook, data, partners):
        for obj in partners:
            report_name = obj.employee_id.name
        report_name = obj.timesheet_ids.date
        report_name = obj.timesheet_ids.name
        report_name = obj.timesheet_ids.hours
       
           
           
           
            # One sheet by partner
            sheet = workbook.add_worksheet(report_name[:31])
           
            bold = workbook.add_format({'bold': True})
           
            sheet.write('A1', 'Task Name', bold)
            sheet.write('B1', 'Task Date', bold)
            sheet.write('C1', 'Project Name', bold)
            sheet.write('D1', 'Employee Name', bold)
            sheet.write('E1', 'Hours', bold)

           
            sheet.write(1, 1, obj.timesheet_ids.date[0], bold)
       
           sheet.write(1, 0, obj.timesheet_ids.name, bold)
           
        sheet.write(1, 4, obj.timesheet_ids.hours, bold)
            sheet.write(1, 3, obj.employee_id.name, bold)
           

PartnerXlsx('report.hr_timesheet_sheet.sheet.xlsx',
            'hr_timesheet_sheet.sheet')


Xml Code is

<data>
<openerp>

<report
    id="partner_xlsx"
    model="hr_timesheet_sheet.sheet"
    string="Timesheet Report"
    report_type="xlsx"
    name="hr_timesheet_sheet.sheet.xlsx"
    file="hr_timesheet_sheet.sheet.xlsx"
    attachment_use="False"
/>
</openerp>
</data>

Please help me


Avatar
Discard

Hello you get any solution related to this problem ?

Best Answer

Loop through the child lines/records, and print the data...

In your case it is "timesheet_ids" of type One2many relation, which means it has many records, hence in order to access the data, you need to loop through each of those records.

Avatar
Discard
Author

Thank you I have used for loop like this

def generate_xlsx_report(self, workbook, data, partners):

for obj in partners:

report_name = obj.employee_id.name

for line in obj.timesheet_ids:

v = line.name

sheet = workbook.add_worksheet(report_name[:31])

bold = workbook.add_format({'bold': True})

sheet.write('A1', 'Task Name', bold)

sheet.write('B1', 'Task Date', bold)

sheet.write('C1', 'Project Name', bold)

sheet.write('D1', 'Employee Name', bold)

sheet.write('E1', 'Hours', bold)

sheet.write(1, 0, line.name, bold)

sheet.write(1, 3, obj.employee_id.name, bold)

but get excel sheet name error while printing the excel report