Skip to content

Commit 9108f80

Browse files
committed
feat(task): get customer name (fixes #33)
1 parent fb7cb30 commit 9108f80

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

routers/inventory.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ def api_get_inventory(
2626

2727
for item in items:
2828
name = [name for name in names if name['id'] == item['inventory_type_id']][0]
29-
print(name)
30-
print(item)
3129
named_items.append({
3230
'id': item['id'],
3331
'type_id': item['inventory_type_id'], # mean model (e.g VSOLVA74) # equals item['catalog_id']

routers/task.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from fastapi.responses import JSONResponse
55

66
from api import api_call, set_additional_data
7-
from utils import get_current_time, normalize_items, str_to_list, list_to_str
7+
from utils import get_current_time, normalize_items, str_to_list, list_to_str, remove_sn
88

99
router = APIRouter(prefix='/task')
1010

@@ -13,6 +13,10 @@ def api_get_task(id: int, get_employee_names: bool = True):
1313
task = api_call('task', 'show', f'id={id}').get('data')
1414
if task is None:
1515
return JSONResponse({'status': 'fail', 'detail': 'task not found'}, 404)
16+
17+
customer = api_call('customer', 'get_data', f'id={task["customer"][0]}')['data'] if 'customer' in task else None
18+
19+
1620
return {
1721
'status': 'success',
1822
'data': {
@@ -80,7 +84,10 @@ def api_get_task(id: int, get_employee_names: bool = True):
8084
'apartment': unescape(task['address']['apartment'])
8185
if task['address'].get('apartment') else None
8286
},
83-
'customer': task['customer'][0] if 'customer' in task else None,
87+
'customer': {
88+
'id': customer['id'],
89+
'name': remove_sn(customer['full_name'])
90+
} if customer else None,
8491
'employees': list(task.get('staff', {}).get('employee', {}).values()),
8592
'divisions': list(task.get('staff', {}).get('division', {}).values()),
8693
}
@@ -165,6 +172,7 @@ def api_get_tasks(
165172
tasks_data = []
166173
if get_data:
167174
for task in normalize_items(api_call('task', 'show', f'id={list_to_str(tasks)}')):
175+
customer = api_call('customer', 'get_data', f'id={task["customer"][0]}')['data'] if 'customer' in task else None
168176
tasks_data.append({
169177
'id': task['id'],
170178
'comments': [
@@ -230,7 +238,10 @@ def api_get_tasks(
230238
'apartment': unescape(task['address']['apartment'])
231239
if task['address'].get('apartment') else None
232240
},
233-
'customer': task['customer'][0] if 'customer' in task else None,
241+
'customer': {
242+
'id': customer['id'],
243+
'name': remove_sn(customer['full_name'])
244+
} if customer else None,
234245
'employees': list(task.get('staff', {}).get('employee', {}).values()),
235246
'divisions': list(task.get('staff', {}).get('division', {}).values()),
236247
})

0 commit comments

Comments
 (0)