@@ -133,25 +133,50 @@ def api_post_task(
133133):
134134 if (customer_id is None and address_id is None ) or (customer_id is not None and address_id is not None ):
135135 return JSONResponse ({'status' : 'fail' , 'detail' : 'one of address_id or customer_id must be provided' }, 422 )
136- if reason is None or appeal_phone is None or appeal_type is None and type in (37 , 38 ):
137- return JSONResponse ({'status' : 'fail' , 'detail' : 'Reason, appeal_phone and appeal_type must be provided for task with type 37 or 38' }, 422 )
136+ if (reason is None or appeal_phone is None or appeal_type is None ) and type in (37 , 46 , 53 ):
137+ return JSONResponse ({'status' : 'fail' , 'detail' : 'Reason, appeal_phone and appeal_type must be provided for task with type 37, 46 or 53' }, 422 )
138+ if (appeal_phone is None ) and type == 60 :
139+ return JSONResponse ({'status' : 'fail' , 'detail' : 'Appeal_phone must be provided for task with type 60' }, 422 )
140+ if (reason is None or appeal_type is None ) and type == 38 :
141+ return JSONResponse ({'status' : 'fail' , 'detail' : 'Reason and appeal_type must be provided for task with type 38' }, 422 )
142+ if (reason is None or appeal_phone is None ) and type == 48 :
143+ return JSONResponse ({'status' : 'fail' , 'detail' : 'Reason and appeal_phone must be provided for task with type 48' }, 422 )
144+
138145
139146 list_divisions = str_to_list (divisions )
140- id = api_call (
141- 'task' , 'add' ,
142- f'work_typer={ type } &work_datedo={ get_current_time ()} &author_employee_id={ author_id } '
143- f'&address_id={ address_id } &opis={ description } &division_id={ list_to_str (list_divisions )} '
144- f'&deadline_hour=72&customer_id={ customer_id } '
145- )['Id' ]
146-
147- if type == 37 :
147+ params = [
148+ f'work_typer={ type } ' ,
149+ f'work_datedo={ get_current_time ()} ' ,
150+ f'deadline_hour=72' ,
151+ f'division_id={ list_to_str (list_divisions )} '
152+ ]
153+
154+ if author_id :
155+ params .append (f'author_employee_id={ author_id } ' )
156+ if address_id :
157+ params .append (f'address_id={ address_id } ' )
158+ if description :
159+ params .append (f'opis={ description } ' )
160+ if customer_id :
161+ params .append (f'customer_id={ customer_id } ' )
162+
163+ query_string = '&' .join (params )
164+ print (query_string )
165+
166+ id = api_call ('task' , 'add' , query_string )['Id' ]
167+
168+ if type in (37 , 46 , 53 ):
148169 set_additional_data (17 , 30 , id , reason )
149170 set_additional_data (17 , 29 , id , appeal_phone )
150171 set_additional_data (17 , 28 , id , appeal_type )
151- elif type == 38 :
152- set_additional_data (17 , 33 , id , reason )
172+ elif type == 60 :
153173 set_additional_data (17 , 29 , id , appeal_phone )
174+ elif type == 38 :
175+ set_additional_data (17 , 30 , id , reason )
154176 set_additional_data (17 , 28 , id , appeal_type )
177+ elif type == 48 :
178+ set_additional_data (17 , 30 , id , reason )
179+ set_additional_data (17 , 29 , id , appeal_phone )
155180
156181 if description :
157182 api_call ('task' , 'comment_add' , f'id={ id } &comment={ description } &employee_id={ author_id } ' )
0 commit comments