Seperated Spares and added working missing table

This commit is contained in:
FrederikBaerentsen 2024-03-02 03:02:37 -05:00
parent edaaf910ca
commit 74f19611ea
3 changed files with 63 additions and 6 deletions

4
app.py
View File

@ -24,18 +24,20 @@ def save_number(tmp):
data2 = request.form.get('brick.color.name')
data3 = request.form.get('index')
number = request.form.get('numberInput')
is_spare = request.form.get('is_spare')
if number is not None:
print(data1)
print(data2)
print(number)
print(is_spare)
with open('./info/'+tmp+'.json') as info:
json_file = json.loads(info.read())
print(json_file['count'])
data = '{"brick" : {"ID":"' + data1 + '","color_name": "' + data2 + '","amount":"' + number + '"}}'
data = '{"brick" : {"ID":"' + data1 + '","is_spare": "' + is_spare + '","color_name": "' + data2 + '","amount":"' + number + '"}}'
json_file['unit'][int(data3)]['bricks']['missing'].append(json.loads(data))

View File

@ -70,7 +70,7 @@ else:
logging.error('set_img_url: ' + set_num)
# set inventory
response = json.loads(rebrick.lego.get_set_elements(set_num).read())
response = json.loads(rebrick.lego.get_set_elements(set_num,page_size=20000).read())
with open(set_path+'inventory.json', 'w', encoding='utf-8') as f:
json.dump(response, f, ensure_ascii=False, indent=4)

View File

@ -1,7 +1,8 @@
{% extends "base.html" %}
{% block content %}
<table id="data" class="table table-striped">
<h1>Inventory</h1>
<table id="data" class="table table-striped">
<thead>
<tr>
<th>img</th>
@ -11,7 +12,6 @@
<th>color.id</th>
<th>color</th>
<th>qty</th>
<th>is_spare</th>
{% for i in json_file['unit'] %}
<th>Missing ({{ loop.index }})</th>
{% endfor %}
@ -19,6 +19,7 @@
</thead>
<tbody>
{% for brick in inventory_file.results %}
{% if brick.is_spare == False %}
<tr>
<td><img src="{{ '/static/parts/'+brick.element_id+'.jpg' }}" style="height: 50px; width: auto;"></td>
<td>{{ brick.element_id }}</td>
@ -27,7 +28,6 @@
<td>{{ brick.color.id }}</td>
<td>{{ brick.color.name }}</td>
<td>{{ brick.quantity }}</td>
<td>{{ brick.is_spare }}</td>
{% for i in json_file['unit'] %}
<td>
@ -36,9 +36,64 @@
<input type="hidden" name="brick.part.part_num" value="{{ brick.part.part_num }}">
<input type="hidden" name="count" value="{{ i }}">
<input type="hidden" name="index" value="{{ loop.index0 }}">
<input type="hidden" name="is_spare" value="{{ brick.is_spare }}">
<input type="hidden" name="brick.color.name" value="{{ brick.color.name }}">
{% for j in json_file['unit'][loop.index0]['bricks']['missing'] %}
{% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name %}
{% if j['brick']['is_spare']|lower == brick.is_spare|lower %}
{% set ns.count = j['brick']['amount'] %}
{% endif %}
{% endif %}
{% endfor %}
<input type="text" style="height:auto;width:40px" id="numberInput" name="numberInput" value={{ ns.count }}><button type="submit"><i class="fa fa-save"></i></button>
</form>
</td>
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
<h1>Spares</h1>
<table id="data" class="table table-striped">
<thead>
<tr>
<th>img</th>
<th>element_id</th>
<th>part_num</th>
<th>name</th>
<th>color</th>
<th>qty</th>
{% for i in json_file['unit'] %}
<th>Missing ({{ loop.index }})</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for brick in inventory_file.results %}
{% if brick.is_spare == True %}
<tr>
<td><img src="{{ '/static/parts/'+brick.element_id+'.jpg' }}" style="height: 50px; width: auto;"></td>
<td>{{ brick.element_id }}</td>
<td>{{ brick.part.part_num }}</td>
<td>{{ brick.part.name }}</td>
<td>{{ brick.color.name }}</td>
<td>{{ brick.quantity }}</td>
{% for i in json_file['unit'] %}
<td>
{% set ns = namespace(count='') %}
<form action="/{{ tmp }}/saveNumber" method="post">
<input type="hidden" name="brick.part.part_num" value="{{ brick.part.part_num }}">
<input type="hidden" name="count" value="{{ i }}">
<input type="hidden" name="index" value="{{ loop.index0 }}">
<input type="hidden" name="is_spare" value="{{ brick.is_spare }}">
<input type="hidden" name="brick.color.name" value="{{ brick.color.name }}">
{% for j in json_file['unit'][loop.index0]['bricks']['missing'] %}
{% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name and j['brick']['is_spare']|lower == brick.is_spare|lower %}
{% set ns.count = j['brick']['amount'] %}
{% endif %}
{% endfor %}
@ -47,8 +102,8 @@
</td>
{% endfor %}
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endblock %}