@@ -164,6 +164,8 @@ def find_all_entries(
164
164
conditions = conditions ,
165
165
custom_sql_conditions = custom_sql_conditions ,
166
166
custom_params = custom_params ,
167
+ max_count = kwargs .get ("max_count" , None ),
168
+ offset = kwargs .get ("offset" , 0 ),
167
169
)
168
170
return time_entries
169
171
@@ -173,6 +175,7 @@ def count(
173
175
conditions : dict = None ,
174
176
custom_sql_conditions : List [str ] = None ,
175
177
date_range : dict = None ,
178
+ ** kwargs ,
176
179
):
177
180
conditions = conditions if conditions else {}
178
181
custom_sql_conditions = (
@@ -424,7 +427,8 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
424
427
conditions .update ({"owner_id" : event_ctx .user_id })
425
428
426
429
custom_query = self .build_custom_query (
427
- is_admin = event_ctx .is_admin , conditions = conditions ,
430
+ is_admin = event_ctx .is_admin ,
431
+ conditions = conditions ,
428
432
)
429
433
date_range = self .handle_date_filter_args (args = conditions )
430
434
limit = conditions .get ("limit" , None )
@@ -437,14 +441,56 @@ def get_all(self, conditions: dict = None, **kwargs) -> list:
437
441
max_count = limit ,
438
442
)
439
443
444
+ def get_last_projects_worked (
445
+ self , conditions : dict = None , ** kwargs
446
+ ) -> list :
447
+ event_ctx = self .create_event_context ("read-many" )
448
+ conditions .update ({"owner_id" : event_ctx .user_id })
449
+ custom_query = self .build_custom_query (
450
+ is_admin = event_ctx .is_admin ,
451
+ conditions = conditions ,
452
+ )
453
+ date_range = self .handle_date_filter_args (args = conditions )
454
+
455
+ project_dao = projects_model .create_dao ()
456
+ projects = project_dao .get_all ()
457
+ projects_ids = [project .id for project in projects ]
458
+
459
+ activity_dao = activities_model .create_dao ()
460
+ activities = activity_dao .get_all (
461
+ visible_only = False ,
462
+ )
463
+
464
+ result = []
465
+ for id_project in projects_ids :
466
+ conditions .update ({"project_id" : id_project })
467
+
468
+ limit = 2
469
+ latest = self .repository .find_all_entries (
470
+ event_ctx ,
471
+ conditions = conditions ,
472
+ custom_sql_conditions = custom_query ,
473
+ date_range = date_range ,
474
+ max_count = limit ,
475
+ )
476
+
477
+ if len (latest ) >= 1 :
478
+ result .append (latest [0 ])
479
+
480
+ add_activity_name_to_time_entries (result , activities )
481
+ add_project_info_to_time_entries (result , projects )
482
+
483
+ return result
484
+
440
485
def get_all_paginated (self , conditions : dict = None , ** kwargs ) -> list :
441
486
get_all_conditions = dict (conditions )
442
487
get_all_conditions .pop ("length" )
443
488
get_all_conditions .pop ("start" )
444
489
event_ctx = self .create_event_context ("read-many" )
445
490
get_all_conditions .update ({"owner_id" : event_ctx .user_id })
446
491
custom_query = self .build_custom_query (
447
- is_admin = event_ctx .is_admin , conditions = get_all_conditions ,
492
+ is_admin = event_ctx .is_admin ,
493
+ conditions = get_all_conditions ,
448
494
)
449
495
date_range = self .handle_date_filter_args (args = get_all_conditions )
450
496
records_total = self .repository .count (
@@ -455,7 +501,8 @@ def get_all_paginated(self, conditions: dict = None, **kwargs) -> list:
455
501
)
456
502
conditions .update ({"owner_id" : event_ctx .user_id })
457
503
custom_query = self .build_custom_query (
458
- is_admin = event_ctx .is_admin , conditions = conditions ,
504
+ is_admin = event_ctx .is_admin ,
505
+ conditions = conditions ,
459
506
)
460
507
date_range = self .handle_date_filter_args (args = conditions )
461
508
length = conditions .get ("length" , None )
@@ -499,7 +546,11 @@ def update(self, id, data: dict, description=None):
499
546
time_entry = self .repository .find (id , event_ctx )
500
547
self .check_whether_current_user_owns_item (time_entry )
501
548
502
- return self .repository .partial_update (id , data , event_ctx ,)
549
+ return self .repository .partial_update (
550
+ id ,
551
+ data ,
552
+ event_ctx ,
553
+ )
503
554
504
555
def stop (self , id ):
505
556
event_ctx = self .create_event_context ("update" , "Stop time entry" )
@@ -509,7 +560,9 @@ def stop(self, id):
509
560
self .check_time_entry_is_not_stopped (time_entry )
510
561
511
562
return self .repository .partial_update (
512
- id , {'end_date' : current_datetime_str ()}, event_ctx ,
563
+ id ,
564
+ {'end_date' : current_datetime_str ()},
565
+ event_ctx ,
513
566
)
514
567
515
568
def restart (self , id ):
@@ -520,15 +573,18 @@ def restart(self, id):
520
573
self .check_time_entry_is_not_started (time_entry )
521
574
522
575
return self .repository .partial_update (
523
- id , {'end_date' : None }, event_ctx ,
576
+ id ,
577
+ {'end_date' : None },
578
+ event_ctx ,
524
579
)
525
580
526
581
def delete (self , id ):
527
582
event_ctx = self .create_event_context ("delete" )
528
583
time_entry = self .repository .find (id , event_ctx )
529
584
self .check_whether_current_user_owns_item (time_entry )
530
585
self .repository .delete (
531
- id , event_ctx ,
586
+ id ,
587
+ event_ctx ,
532
588
)
533
589
534
590
def find_running (self ):
0 commit comments