@@ -71,6 +71,14 @@ def _first_true(iterable, default=None, pred=None):
71
71
return next (filter (pred , iterable ), default )
72
72
73
73
74
+ def _hour_to_millisecond (hour : Optional [float ]) -> Optional [int ]:
75
+ return int (hour * 3600_000 ) if hour is not None else None
76
+
77
+
78
+ _ORGNIZATION_ID_FOR_AVAILABILITY = "___plannedWorktime___"
79
+ """予定稼働時間用の組織ID"""
80
+
81
+
74
82
class Wrapper :
75
83
"""
76
84
AnnofabApiのラッパー.
@@ -1971,10 +1979,171 @@ def _to_new_data(labor: Dict[str, Any]) -> Dict[str, Any]:
1971
1979
return labor
1972
1980
1973
1981
query_params = {
1974
- "organization_id" : "___plannedWorktime___" ,
1982
+ "organization_id" : _ORGNIZATION_ID_FOR_AVAILABILITY ,
1975
1983
"account_id" : account_id ,
1976
1984
"from" : from_date ,
1977
1985
"to" : to_date ,
1978
1986
}
1979
1987
labor_list , _ = self .api .get_labor_control (query_params )
1980
1988
return [_to_new_data (e ) for e in labor_list ]
1989
+
1990
+ def put_labor_control_actual_worktime (
1991
+ self ,
1992
+ organization_id : str ,
1993
+ project_id : str ,
1994
+ account_id : str ,
1995
+ date : str ,
1996
+ actual_worktime : Optional [float ],
1997
+ working_description : Optional [str ],
1998
+ ) -> Dict [str , Any ]:
1999
+ """
2000
+ 労務管理の実績作業時間を登録する。
2001
+
2002
+ Args:
2003
+ organization_id: 組織ID
2004
+ project_id: プロジェクトID
2005
+ account_id: account_id
2006
+ date: 登録対象日
2007
+ actual_worktime: 実績作業時間[hour]
2008
+ working_description: 実績に関するコメント
2009
+
2010
+ Returns:
2011
+ 登録後の労務管理データ
2012
+ """
2013
+ labor_list , _ = self .api .get_labor_control (
2014
+ query_params = {
2015
+ "organization_id" : organization_id ,
2016
+ "project_id" : project_id ,
2017
+ "account_id" : account_id ,
2018
+ "from" : date ,
2019
+ "to" : date ,
2020
+ }
2021
+ )
2022
+ target_working_time_by_user = {
2023
+ "description" : working_description ,
2024
+ "results" : _hour_to_millisecond (actual_worktime ),
2025
+ }
2026
+
2027
+ if len (labor_list ) > 0 :
2028
+ assert len (labor_list ) == 1 , "get_labor_control APIで取得した労務管理データが2件以上存在した。"
2029
+ labor = labor_list [0 ]
2030
+ request_body = labor
2031
+ request_body ["last_updated_datetime" ] = labor ["updated_datetime" ]
2032
+
2033
+ if "working_time_by_user" in request_body ["values" ]:
2034
+ request_body ["values" ]["working_time_by_user" ].update (target_working_time_by_user )
2035
+ else :
2036
+ request_body ["values" ]["working_time_by_user" ] = target_working_time_by_user
2037
+ else :
2038
+ request_body = {
2039
+ "organization_id" : organization_id ,
2040
+ "project_id" : project_id ,
2041
+ "account_id" : account_id ,
2042
+ "date" : date ,
2043
+ "values" : {"working_time_by_user" : target_working_time_by_user },
2044
+ }
2045
+ content , _ = self .api .put_labor_control (request_body = request_body )
2046
+ return content
2047
+
2048
+ def put_labor_control_plan_worktime (
2049
+ self ,
2050
+ organization_id : str ,
2051
+ project_id : str ,
2052
+ account_id : str ,
2053
+ date : str ,
2054
+ plan_worktime : Optional [float ],
2055
+ ) -> Dict [str , Any ]:
2056
+ """
2057
+ 労務管理の予定作業時間を登録する。
2058
+
2059
+ Args:
2060
+ organization_id: 組織ID
2061
+ project_id: プロジェクトID
2062
+ account_id: account_id
2063
+ date: 登録対象日
2064
+ plan_worktime: 予定作業時間[hour]
2065
+
2066
+ Returns:
2067
+ 登録後の労務管理データ
2068
+
2069
+ """
2070
+ labor_list , _ = self .api .get_labor_control (
2071
+ query_params = {
2072
+ "organization_id" : organization_id ,
2073
+ "project_id" : project_id ,
2074
+ "account_id" : account_id ,
2075
+ "from" : date ,
2076
+ "to" : date ,
2077
+ }
2078
+ )
2079
+ target_working_time_by_user = {"plans" : _hour_to_millisecond (plan_worktime )}
2080
+
2081
+ if len (labor_list ) > 0 :
2082
+ assert len (labor_list ) == 1 , "get_labor_control APIで取得した労務管理データが2件以上存在した。"
2083
+ labor = labor_list [0 ]
2084
+ request_body = labor
2085
+ request_body ["last_updated_datetime" ] = labor ["updated_datetime" ]
2086
+
2087
+ if "working_time_by_user" in request_body ["values" ]:
2088
+ request_body ["values" ]["working_time_by_user" ].update (target_working_time_by_user )
2089
+ else :
2090
+ request_body ["values" ]["working_time_by_user" ] = target_working_time_by_user
2091
+
2092
+ else :
2093
+ request_body = {
2094
+ "organization_id" : organization_id ,
2095
+ "project_id" : project_id ,
2096
+ "account_id" : account_id ,
2097
+ "date" : date ,
2098
+ "values" : {"working_time_by_user" : target_working_time_by_user },
2099
+ }
2100
+ content , _ = self .api .put_labor_control (request_body = request_body )
2101
+ return content
2102
+
2103
+ def put_labor_control_availability (
2104
+ self ,
2105
+ account_id : str ,
2106
+ date : str ,
2107
+ availability : Optional [float ],
2108
+ ) -> Dict [str , Any ]:
2109
+ """
2110
+ 労務管理の予定稼働時間を登録する
2111
+
2112
+ Args:
2113
+ account_id: account_id
2114
+ date: 登録対象日
2115
+ availability: 予定稼働時間[hour]
2116
+
2117
+ Returns:
2118
+ 登録後の労務管理データ
2119
+
2120
+ """
2121
+
2122
+ organization_id = _ORGNIZATION_ID_FOR_AVAILABILITY
2123
+
2124
+ labor_list , _ = self .api .get_labor_control (
2125
+ query_params = {"organization_id" : organization_id , "account_id" : account_id , "from" : date , "to" : date }
2126
+ )
2127
+ target_working_time_by_user = {"plans" : _hour_to_millisecond (availability )}
2128
+
2129
+ if len (labor_list ) > 0 :
2130
+ assert len (labor_list ) == 1 , "get_labor_control APIで取得した労務管理データが2件以上存在した。"
2131
+ labor = labor_list [0 ]
2132
+ request_body = labor
2133
+ request_body ["last_updated_datetime" ] = labor ["updated_datetime" ]
2134
+
2135
+ if "working_time_by_user" in request_body ["values" ]:
2136
+ request_body ["values" ]["working_time_by_user" ].update (target_working_time_by_user )
2137
+ else :
2138
+ request_body ["values" ]["working_time_by_user" ] = target_working_time_by_user
2139
+
2140
+ else :
2141
+ request_body = {
2142
+ "organization_id" : organization_id ,
2143
+ "account_id" : account_id ,
2144
+ "date" : date ,
2145
+ "values" : {"working_time_by_user" : target_working_time_by_user },
2146
+ }
2147
+
2148
+ content , _ = self .api .put_labor_control (request_body = request_body )
2149
+ return content
0 commit comments