diff --git a/models/lefilament_tdb.py b/models/lefilament_tdb.py index 3a94c3bf1509a9f5098ac1a30bc1576a0158ba89..e6f6a8e06848fbc02f328554c5fac894c38f3172 100644 --- a/models/lefilament_tdb.py +++ b/models/lefilament_tdb.py @@ -444,11 +444,11 @@ class LeFilamentTdb(models.Model): return result def _employee_time(self, date_start=None, date_end=None): - clause = "where 1=1 " + clause = "" if date_start: - clause += f"and line_date >= '{date_start}' " + clause += f" and aal.date >= '{date_start}'" if date_end: - clause += f"and line_date <= '{date_end}' " + clause += f" and aal.date <= '{date_end}'" query = """ select @@ -456,14 +456,13 @@ class LeFilamentTdb(models.Model): sum(production) as "Prod", sum(internal) as "Interne", sum(revenue) as "CA" - from - ( + + from ( select p.name as employee, 0 as production, 0 as internal, - aal.amount as revenue, - aal.date as line_date + sum(aal.amount) as revenue from account_analytic_line aal left join @@ -474,15 +473,16 @@ class LeFilamentTdb(models.Model): res_partner p on aa.partner_id = p.id where aap.id = 3 + %s + group by p.name union select e.name as employee, - case when aal.partner_id != 1 or aal.partner_id is null and aal.holiday_id is null then unit_amount else 0 end as production, - case when aal.partner_id = 1 and aal.holiday_id is null then unit_amount else 0 end as internal, - 0 as revenue, - aal.date as line_date + sum(case when aal.partner_id != 1 or aal.partner_id is null and aal.holiday_id is null then unit_amount else 0 end) as production, + sum(case when aal.partner_id = 1 and aal.holiday_id is null then unit_amount else 0 end) as internal, + 0 as revenue from account_analytic_line aal left join @@ -493,13 +493,13 @@ class LeFilamentTdb(models.Model): hr_leave_type lt on l.holiday_status_id = lt.id where aal.project_id is not null - and (lt.active is true or lt.active is null) + %s + group by e.name ) query - %s group by employee order by sum(production) desc """ - self.env.cr.execute(query, (AsIs(clause),)) + self.env.cr.execute(query, (AsIs(clause), AsIs(clause),)) result = self.env.cr.dictfetchall() return result