@@ -37,6 +37,38 @@ def _resolve_date(self, value):
3737 parsed = datetime .strptime (value , r"%Y-%m-%d" ).date ()
3838
3939 return parsed
40+
41+ def _resolve_time (self , value ):
42+ _v = self .strip_hrs (value )
43+ _h = 0
44+ _m = 0
45+ _s = 0
46+ if _v .__contains__ ("pm" ):
47+ _v = _v .replace ("pm" ,"" )
48+ _h = int (_v .split (":" )[0 ])
49+ if _h < 12 :
50+ _h = _h + 12
51+ elif _h == 12 :
52+ _h = 0
53+ else :
54+ _h = int (_v .split (":" )[0 ])
55+ if _h > 99 :
56+ _h = int (_h / 100 )
57+ if _v .count (":" ) == 2 :
58+ _m = int (_v .split (":" )[1 ])
59+ _s = int (_v .split (":" )[2 ])
60+ elif _v .count (":" ) == 1 :
61+ _m = int (_v .split (":" )[1 ])
62+ value = "{:02d}:{:02d}:{:02d}" .format (_h , _m , _s )
63+ parsed = datetime .strptime (value , r"%H:%M:%S" ).time ()
64+ return parsed
65+
66+ def strip_hrs (self , value ):
67+ _hrs = ["am" , "uhr" , "hrs" , "hours" , "hour" ]
68+ retval = value .lower ().replace (" " ,"" ).replace ("." ,":" )
69+ for i in _hrs :
70+ retval = retval .replace (i , "" )
71+ return retval .strip ()
4072
4173 def get (self , path , data = None , flags = None , params = None , headers = None , not_json_response = None , trailing = None ):
4274 path_absolute = super ().url_joiner (self ._base_url , path )
@@ -573,6 +605,46 @@ def search_worklogs(self, dateFrom, dateTo, updatedFrom=None, authorIds=None, is
573605 url = f"/worklogs/search"
574606
575607 return self .post (url , params = params , data = data )
608+
609+ def create_worklog (self , accountId , issueId , dateFrom , timeSpentSeconds , billableSeconds = None , description = None ,
610+ remainingEstimateSeconds = None , startTime = None ):
611+ """
612+ Creates a new Worklog using the provided input and returns the newly created Worklog.
613+ :param accountId:
614+ :param issueId:
615+ :param dateFrom:
616+ :param timeSpentSeconds:
617+ :param billableSeconds:
618+ :param description:
619+ :param remainingEstimateSeconds:
620+ :param startTime:
621+ """
622+
623+ url = f"/worklogs"
624+
625+ data = {
626+ "authorAccountId" : str (accountId ),
627+ "issueId" : int (issueId ),
628+ "startDate" : self ._resolve_date (dateFrom ).isoformat (),
629+ "timeSpentSeconds" : int (timeSpentSeconds )
630+ }
631+
632+ if billableSeconds :
633+ data ["billableSeconds" ] = int (billableSeconds )
634+ if description :
635+ data ["description" ] = str (description )
636+ if remainingEstimateSeconds :
637+ data ["remainingEstimateSeconds" ] = int (remainingEstimateSeconds )
638+ if startTime :
639+ data ["startTime" ] = self ._resolve_time (startTime ).isoformat ()
640+
641+ return self .post (url , data = data )
642+
643+
644+
645+
646+ # Customer
647+
576648 def create_customer (self , key = None , name = None , data = None ):
577649 """
578650 Create customer
@@ -608,6 +680,8 @@ def update_customer(self, key=None, name=None, data=None):
608680
609681 return self .put (url , data = data )
610682
683+ # Account
684+
611685 def create_account (self , key = None , leadAccountId = None , name = None , status = None , categoryKey = None , contactAccountId = None , customerKey = None , externalContactName = None , isGlobal = None , data = None ):
612686 """
613687 Create account
0 commit comments