diff --git a/models/lefilament_tdb.py b/models/lefilament_tdb.py index aab398b9f291575ba9c66c551d03b31fc6888ca2..3a94c3bf1509a9f5098ac1a30bc1576a0158ba89 100644 --- a/models/lefilament_tdb.py +++ b/models/lefilament_tdb.py @@ -313,9 +313,9 @@ class LeFilamentTdb(models.Model): def _customer_detail(self, date_start=None, date_end=None): clause = "where 1=1 " if date_start: - clause += f"and line_date >= '{date_start}'" + clause += f"and line_date >= '{date_start}' " if date_end: - clause += f"and line_date <= '{date_end}'" + clause += f"and line_date <= '{date_end}' " query = """ select @@ -444,33 +444,60 @@ class LeFilamentTdb(models.Model): return result def _employee_time(self, date_start=None, date_end=None): - clause = "" + clause = "where 1=1 " if date_start: - clause += f"and aal.date >= '{date_start}'" + clause += f"and line_date >= '{date_start}' " if date_end: - clause += f"and aal.date <= '{date_end}'" + clause += f"and line_date <= '{date_end}' " query = """ select - e.name as "Personne", - 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 "Prod", - sum(case when aal.partner_id = 1 and aal.holiday_id is null then unit_amount else 0 end) as "Interne" - from - account_analytic_line aal - left join - hr_employee e on aal.employee_id = e.id - left join - hr_leave l on aal.holiday_id = l.id - left join - 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 - order by - 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) desc + employee as "Employé", + sum(production) as "Prod", + sum(internal) as "Interne", + sum(revenue) as "CA" + from + ( + select + p.name as employee, + 0 as production, + 0 as internal, + aal.amount as revenue, + aal.date as line_date + from + account_analytic_line aal + left join + account_analytic_account aa on aal.account_id = aa.id + left join + account_analytic_plan aap on aa.plan_id = aap.id + left join + res_partner p on aa.partner_id = p.id + where + aap.id = 3 + + 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 + from + account_analytic_line aal + left join + hr_employee e on aal.employee_id = e.id + left join + hr_leave l on aal.holiday_id = l.id + left join + 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) + ) query + %s + group by employee + order by sum(production) desc """ self.env.cr.execute(query, (AsIs(clause),)) diff --git a/templates/dashboard_detail.xml b/templates/dashboard_detail.xml index ba63bea49b2544f580a218b1469d5233f8a2cc86..c7b27a2d6f60d4bac521ae0600cfe60d695ebbb9 100644 --- a/templates/dashboard_detail.xml +++ b/templates/dashboard_detail.xml @@ -72,6 +72,7 @@ <t t-value="records.dashboard_detail_values()" t-set="init_data" /> <t t-value="init_data.get('customer')" t-set="customer" /> <t t-value="init_data.get('employee_time')" t-set="employee_time" /> + <t t-value="init_data.get('employee_revenue')" t-set="employee_revenue" /> <t t-call="lefilament_tdb.dashboard_detail_values" /> </div> </qweb> @@ -103,6 +104,11 @@ <t t-call="lefilament_tdb.dashboard_detail_table"> <t t-set="data" t-value="employee_time" /> </t> + <h3 class="text-uppercase py-2 mb-0 mt-5">CA par employé</h3> + <hr class="mt-0" /> + <t t-call="lefilament_tdb.dashboard_detail_table"> + <t t-set="data" t-value="employee_revenue" /> + </t> </div> </div> </div>