Hii,
I am making an excel report by exporting Payslips Batches to excel file.
Requirement is to show employee payroll records group by department in excel file.
I can show employee and its payslip in one line in excel but how to group it by department....
Here is my python code
def generate_xlsx_report(self, workbook, data, payslips):
for payslip_run in payslips:
report_name = payslip_run.name
# One sheet by Payslip Batches
sheet = workbook.add_worksheet('Payroll '+report_name)
row_format = workbook.add_format({'bold': False, 'bg_color': '#808080'})
# =========Header Row============
sheet.write(0, 0, 'Employee ID', row_format)
sheet.write(0, 1, 'Employee Name', row_format)
sheet.write(0, 2, 'No. Of Working Days', row_format)
sheet.write(0, 3, 'Total Salary', row_format)
sheet.write(0, 4, 'Basic Salary', row_format)
line_number = 1
for payslip in payslip_run.slip_ids: # How to apply group by department here
# Here I want to show employee department
if payslip.employee_id.department_id: # or here
row_format_dept = workbook.add_format({'bold': False, 'bg_color': '#CCCCCC'})
sheet.write(line_number, 0, payslip.employee_id.department_id.name, row_format_dept)
line_number += 1
Can we group by or order by in filtered(lambda) or . search in for loop??
for payslip in payslip_run.slip_ids: group by or order by in this loop buy filtered or search?
if you check the odoo code itself, you can see the usage of
from itertools import groupby , try with this ,,,,
Thanks Niyas, could you please explain with some example,....could'nt get your point.
This is also not working
for payslip in payslip_run.slip_ids.sorted(key=lambda r: r.employee_id.department_id.name):
i need groupby on for payslip in payslip_run.slip_ids