'Compute the attendances, analytic lines timesheets and differences
between them for all the days of a timesheet and the current day'

@api.depends('period_ids.total_attendance', 'period_ids.total_timesheet', 'period_ids.total_difference')
def _compute_total(self):

    if (len(self.ids) == 0):
        return
    self.env.cr.execute('\n                                                SELECT    sheet_id    as    id,\n                                                                            sum(total_attendance)    as    total_attendance,\n                                                                            sum(total_timesheet)    as    total_timesheet,\n                                                                            sum(total_difference)    as        total_difference\n                                                FROM    hr_timesheet_sheet_sheet_day\n                                                WHERE    sheet_id    IN    %s\n                                                GROUP    BY    sheet_id\n                                ', (tuple(self.ids),))
    for x in self.env.cr.dictfetchall():
        sheet = self.browse(x.pop('id'))
        sheet.total_attendance = x.pop('total_attendance')
        sheet.total_timesheet = x.pop('total_timesheet')
        sheet.total_difference = x.pop('total_difference')
