@@ -329,40 +329,51 @@ def effective_costs(self, reporting_period=None):
329
329
"""
330
330
agreements = Agreement .objects .filter (task = self )
331
331
if reporting_period :
332
- work_objects = Work .objects .filter (task = self .id ,
333
- reporting_period = reporting_period )
332
+ all_work_in_task = Work .objects .filter (task = self .id ,
333
+ reporting_period = reporting_period )
334
334
else :
335
- work_objects = Work .objects .filter (task = self .id )
336
- sum_seconds = 0
337
- effort_in_seconds = 0
335
+ all_work_in_task = Work .objects .filter (task = self .id )
338
336
sum_costs = 0
337
+ work_with_agreement = list ()
338
+ work_without_agreement = list ()
339
+ work_calculated = list ()
339
340
human_resource_list = dict ()
340
- for work_object in work_objects :
341
- effort_in_seconds += work_object .effort_seconds ()
342
- sum_seconds += effort_in_seconds
341
+ for work_object in all_work_in_task :
343
342
if work_object .human_resource not in human_resource_list :
344
343
human_resource_list [work_object .human_resource ] = dict ()
345
344
for agreement in agreements :
346
- agreement_matches = True
347
- """agreement.matches_with(work_object)"""
345
+ agreement_matches = agreement .match_with_work (work_object )
348
346
if agreement_matches :
347
+ if work_object not in work_with_agreement :
348
+ work_with_agreement .append (work_object )
349
349
if agreement not in human_resource_list .get (work_object .human_resource ):
350
350
human_resource_list .get (work_object .human_resource )[agreement ] = list ()
351
351
human_resource_list .get (work_object .human_resource ).get (agreement ).append (work_object )
352
- covered_work = list ()
352
+ if work_object not in work_with_agreement :
353
+ work_without_agreement .append (work_object )
354
+
353
355
for human_resource_dict in human_resource_list :
354
356
agreement_list = Agreement .objects .filter (task = self , resource = human_resource_dict ).order_by ('costs__price' )
355
357
for agreement in agreement_list :
356
358
agreement_remaining_amount = agreement .amount
357
- for work in human_resource_list [human_resource_dict ].get (agreement ):
358
- if work not in covered_work :
359
- if (agreement_remaining_amount - work .worked_hours ) > 0 :
360
- agreement_remaining_amount -= work .worked_hours
361
- sum_costs += work .worked_hours * agreement .costs .price .price
362
- covered_work .append (work )
363
- for work in work_objects :
364
- if work not in covered_work :
365
- sum_costs += work .worked_hours * ResourcePrice .objects .get (work .human_resource ).price
359
+ if human_resource_list [human_resource_dict ].get (agreement ):
360
+ for work in human_resource_list [human_resource_dict ].get (agreement ):
361
+ if work in work_with_agreement :
362
+ if (agreement_remaining_amount - work .worked_hours ) > 0 :
363
+ agreement_remaining_amount -= work .worked_hours
364
+ sum_costs += work .worked_hours * agreement .costs .price
365
+ work_calculated .append (work )
366
+ for work in all_work_in_task :
367
+ if work not in work_calculated :
368
+ if work not in work_without_agreement :
369
+ work_without_agreement .append (work )
370
+ for work in work_without_agreement :
371
+ default_resource_price = ResourcePrice .objects .get (id = work .human_resource .id )
372
+ if default_resource_price :
373
+ sum_costs += work .worked_hours * default_resource_price .price
374
+ else :
375
+ sum_costs = "n/a"
376
+ break
366
377
return sum_costs .__str__ ()
367
378
effective_costs .short_description = _ ("Effective costs" )
368
379
effective_costs .tags = True
0 commit comments