From 4ca818933f6a710d397bcd3bfcafb57571cdba8f Mon Sep 17 00:00:00 2001
From: remi_filament <remi@le-filament.com>
Date: Mon, 13 Nov 2017 12:01:39 +0100
Subject: [PATCH] Fix calculation of hours spent

---
 models/project.py | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/models/project.py b/models/project.py
index 3f15c05..99888ac 100644
--- a/models/project.py
+++ b/models/project.py
@@ -40,28 +40,26 @@ class FilamentProjet(models.Model):
 
 	@api.one
 	def _total_heures_prospection(self):
-		res = 0.0
 		project = self.id		
+		self.lf_heures_prospection = 0.0
 		## Calcul heures   
-		self.env.cr.execute("select sum(aal.unit_amount) from account_analytic_line aal, project_task pt where aal.project_id=%s and pt.name='Prospection' and pt.id=aal.task_id;", (project, ) )
-		heures_prospection = self.env.cr.fetchone()[0]
-		if heures_prospection:
-			self.lf_heures_prospection = heures_prospection
-		else:
-			self.lf_heures_prospection = 0.0
+		if self.use_prospection:
+			self.env.cr.execute("select sum(aal.unit_amount) from account_analytic_line aal, project_task pt where aal.project_id=%s and pt.name like 'Prospection' and pt.id=aal.task_id;", (project, ) )
+			heures_prospection = self.env.cr.fetchone()[0]
+			if heures_prospection:
+				self.lf_heures_prospection = heures_prospection
 
 	@api.one
 	def _total_heures_passees(self):
-		res = 0.0
-		project = self.id		
+		project = self.id
+		self.lf_heures_passees = 0.0		
 		## Calcul heures   
 		self.env.cr.execute("select sum(unit_amount) from account_analytic_line where project_id=%s;", (project, ) )
 		heures_passees = self.env.cr.fetchone()[0]
 		if heures_passees:
 			self.lf_heures_passees = heures_passees
-		else:
-			self.lf_heures_passees = 0.0
-
+			if self.use_prospection:
+				self.lf_heures_passees -= self.lf_heures_prospection
 
 	@api.one
 	def _total_heures_planifiees(self):
-- 
GitLab