Skip to content

Commit 98822ed

Browse files
committed
tisknutelny seznam výroby
1 parent eaf2cdd commit 98822ed

4 files changed

Lines changed: 152 additions & 36 deletions

File tree

src/OpenIntranet/plugins/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ def get_template_namespace(self):
260260

261261
return ns
262262

263+
def get_company_info(self):
264+
return list(self.mdb.intranet.find({'_id': 'company_info'}))[0]
265+
263266
def get_warehouseses(self):
264267
return list(self.mdb.warehouse.find().sort([('code', 1)]))
265268

@@ -532,7 +535,7 @@ def component_get_positions(self, id, stock=None, primary=False):
532535
'''
533536
q = [{"$match": {"_id": id}},
534537
{"$unwind": "$position"},
535-
{"$lookup": {"from": "store_positions", "localField": 'position.posid', "foreignField": '_id',
538+
{"$lookup": {"from": "store_positions_complete", "localField": 'position.posid', "foreignField": '_id',
536539
"as": "position.info"}},
537540
{"$project": {"pos": 1, "position": 1}},
538541
{"$replaceRoot": {"newRoot": "$position"}

src/OpenIntranet/plugins/production.py

Lines changed: 141 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,67 @@
1515
import pandas as pd
1616
from fpdf import FPDF
1717
from enum import Enum
18+
import math
19+
20+
21+
class round_fpdf(FPDF):
22+
def rounded_cell(self, w, h=0, txt='', border=0, ln=0, align='', fill=False, link='', radius = 1, corners = (1,2,3,4), cellspacing = 1):
23+
style = 'S'
24+
if fill and border:
25+
style = 'FD'
26+
elif fill:
27+
style = 'F'
28+
self.rounded_rect(self.get_x() + (cellspacing / 2.0),
29+
self.get_y() + (cellspacing / 2.0),
30+
w - cellspacing, h, radius, corners, style)
31+
self.cell(w, h + cellspacing, txt, 0, ln, align, False, link)
32+
33+
def rounded_rect(self, x, y, w, h, r, corners = (1,2,3,4), style = ''):
34+
k = self.k
35+
hp = self.h
36+
if style == 'F':
37+
op = 'f'
38+
elif style=='FD' or style == 'DF':
39+
op='B'
40+
else:
41+
op='S'
42+
my_arc = 4/3 * (math.sqrt(2) - 1)
43+
self._out('%.2F %.2F m' % ((x+r)*k,(hp-y)*k ))
44+
xc = x+w-r
45+
yc = y+r
46+
self._out('%.2F %.2F l' % (xc*k,(hp-y)*k ))
47+
if 2 not in corners:
48+
self._out('%.2F %.2F l' % ((x+w)*k,(hp-y)*k ))
49+
else:
50+
self._arc(xc + r*my_arc, yc - r, xc + r, yc - r*my_arc, xc + r, yc)
51+
xc = x+w-r
52+
yc = y+h-r
53+
self._out('%.2F %.2F l' % ((x+w)*k,(hp-yc)*k))
54+
if 3 not in corners:
55+
self._out('%.2F %.2F l' % ((x+w)*k,(hp-(y+h))*k))
56+
else:
57+
self._arc(xc + r, yc + r*my_arc, xc + r*my_arc, yc + r, xc, yc + r)
58+
xc = x+r
59+
yc = y+h-r
60+
self._out('%.2F %.2F l' % (xc*k,(hp-(y+h))*k))
61+
if 4 not in corners:
62+
self._out('%.2F %.2F l' % ((x)*k,(hp-(y+h))*k))
63+
else:
64+
self._arc(xc - r*my_arc, yc + r, xc - r, yc + r*my_arc, xc - r, yc)
65+
xc = x+r
66+
yc = y+r
67+
self._out('%.2F %.2F l' % ((x)*k,(hp-yc)*k ))
68+
if 1 not in corners:
69+
self._out('%.2F %.2F l' % ((x)*k,(hp-y)*k ))
70+
self._out('%.2F %.2F l' % ((x+r)*k,(hp-y)*k ))
71+
else:
72+
self._arc(xc - r, yc - r*my_arc, xc - r*my_arc, yc - r, xc, yc - r)
73+
self._out(op)
74+
75+
def _arc(self, x1, y1, x2, y2, x3, y3):
76+
h = self.h
77+
self._out('%.2F %.2F %.2F %.2F %.2F %.2F c ' % (x1*self.k, (h-y1)*self.k,x2*self.k, (h-y2)*self.k, x3*self.k, (h-y3)*self.k))
78+
1879

1980

2081
class ComponentStatus(Enum):
@@ -751,10 +812,12 @@ def get(self, name):
751812
'_id': {'UST_ID': '$components.UST_ID',
752813
'Value': '$components.Value',
753814
'Footprint': '$components.Footprint',
754-
'Distributor': '$components.Distributor',
755-
'Datasheet': '$components.Datasheet',
756-
'stock_count': '$components.stock_count',
757-
'note': '$components.note'},
815+
'status': '$components.status',
816+
#'Distributor': '$components.Distributor',
817+
#'Datasheet': '$components.Datasheet',
818+
#'stock_count': '$components.stock_count',
819+
#'note': '$components.note'
820+
},
758821
'Ref': {'$push': '$components.Ref'},
759822
'category': {'$push': '$components.category'},
760823
'count': {'$sum': 1},
@@ -770,10 +833,32 @@ def get(self, name):
770833
"localField": 'cUST_ID',
771834
"foreignField": '_id',
772835
"as": 'stock'
773-
}}
836+
}},
837+
{"$lookup":{
838+
"from": 'packets_count_complete',
839+
"localField": 'cUST_ID',
840+
"foreignField": '_id',
841+
"as": 'packets'
842+
}},
843+
{"$lookup":{
844+
"from": 'packets_count_complete',
845+
"localField": 'cUST_ID',
846+
"foreignField": '_id',
847+
"as": 'packets'
848+
}},
849+
# {"$lookup":{ # tohle nefunguje jak by melo..
850+
# "from": 'category_complete',
851+
# "localField": 'components.stock.category',
852+
# "foreignField": '_id',
853+
# "as": 'components.stock.category_complete'
854+
# }},
855+
{"$sort": {'Ref':1}}
774856
]))
775857

776-
pdf = FPDF('P', 'mm', format='A4')
858+
859+
pdf = round_fpdf('P', 'mm', format='A4')
860+
pdf.set_line_width(0.1)
861+
pdf.set_draw_color(0,0,0);
777862
pdf.set_auto_page_break(False)
778863
pdf.add_font('pt_sans', '', 'static/pt_sans/PT_Sans-Web-Regular.ttf', uni=True)
779864
pdf.add_font('pt_sans-bold', '', 'static/pt_sans/PT_Sans-Web-Bold.ttf', uni=True)
@@ -794,18 +879,19 @@ def get(self, name):
794879
pdf.cell(0, 5, str(datetime.datetime.now())[:16], border=0)
795880
if pdf.page_no() == 1:
796881
pdf.set_xy(170, 9)
797-
pdf.cell(0, 5, str("Sklad: {}".format('nazev')), border=0)
882+
pdf.cell(0, 5, "Sklad: {}".format(self.get_warehouse()['name']), border=0)
798883
pdf.set_xy(10, 13)
799884
pdf.cell(0, 5, str(name), border=0)
800885

801886
pdf.set_xy(10, 3)
802-
pdf.cell(0, 5, "Universal Scientific Technologies s.r.o.")
887+
pdf.cell(0, 5, "OpenIntranet: {}".format(self.get_company_info()['name']))
803888

804889

805890
row = []
806891
used = []
807892

808893
rowh = 9+8
894+
rowy = 20
809895
first_row = 28
810896
pdf.set_xy(10, 28)
811897

@@ -846,14 +932,17 @@ def get(self, name):
846932

847933
try:
848934
name = component.get('stock')[0]['name']
849-
category = component.get('stock')[0]['category']
935+
#category = component.get('stock')[0]
936+
#print(".....CAT", component)
850937
except Exception as e:
938+
print("chyba", e)
851939
name = ''
852940
category = []
853941

854942
j += 1
855-
if j > 28-14:
943+
if rowy > 260:
856944
j = 0
945+
rowy = 10
857946
first_row = 10
858947
print("New page...")
859948
pdf.add_page()
@@ -874,56 +963,75 @@ def get(self, name):
874963

875964
pdf.set_font('pt_sans', '', 8)
876965

877-
pdf.set_xy(10, first_row+j*rowh)
966+
pdf.set_xy(10, rowy)
878967
pdf.cell(0, 5, str(i)+'.', border=0)
879968

880-
881-
# placement = ""
882-
# for k, place in enumerate(item_places):
883-
# if k > 0:
884-
# placement += ", "
885-
# placement += place['info'][0]['name']
886-
887-
pdf.set_xy(15, first_row+j*rowh + 3.5)
969+
pdf.set_xy(15, rowy + 3.5)
888970
pdf.cell(0, 5, place_str)
889971

890-
891-
pdf.set_xy(15, first_row+j*rowh + 11)
892-
pdf.cell(0, 5, str(', '.join(component['Ref'])), border=0)
893-
894-
pdf.set_xy(163, first_row+j*rowh)
972+
pdf.set_xy(163, rowy)
895973
pdf.cell(0, 5, str(component['_id'].get('UST_ID', '--')))
896974

897-
pdf.set_xy(90, first_row+j*rowh + 3.5)
975+
pdf.set_xy(90, rowy + 3.5)
898976
pdf.cell(0, 5, component['_id'].get('Footprint', '--')[:30])
899977

900-
pdf.set_xy(90, first_row+j*rowh + 7.5)
978+
pdf.set_xy(90, rowy + 7.5)
901979
pdf.cell(0, 5, str(component['_id'].get('note', '--')))
902980

903981
pdf.set_font('pt_sans-bold', '', 7.5)
904982

905-
pdf.set_xy(90, first_row+j*rowh)
983+
pdf.set_xy(90, rowy)
906984
pdf.cell(0, 5, component['_id'].get('Value', '--')[:30])
907985

908986
pdf.set_font('pt_sans-bold', '', 9)
909987

910-
pdf.set_xy(15, first_row+j*rowh)
988+
pdf.set_xy(15, rowy+3.5)
911989
pdf.cell(0, 5, name)
912990

913-
pdf.set_xy(10, first_row+j*rowh + 3.5)
991+
pdf.set_font('pt_sans-bold', '', 8)
992+
993+
pdf.set_xy(15, rowy-0.7)
994+
pdf.cell(0, 5, str(', '.join(component['Ref'])), border=0)
995+
996+
pdf.set_xy(10, rowy + 3.5)
914997
pdf.cell(0, 5, str(component['count'])+'x', border=0)
915998

916999
pdf.set_font('pt_sans', '', 8)
9171000

9181001

919-
pdf.set_xy(15, first_row+j*rowh + 7)
1002+
pdf.set_xy(15, rowy + 7)
9201003
#pdf.cell(0, 5, str(', '.join(str(category))), border=0)
921-
pdf.cell(0, 5, str(category), border=0)
1004+
#pdf.cell(0, 5, str(category), border=0)
1005+
1006+
1007+
packet_rount = 0
1008+
for packets in component.get('packets', []):
9221009

1010+
pdf.set_line_width(0.1)
1011+
pdf.set_draw_color(110,110,110)
1012+
pdf.set_text_color(110,110,110)
1013+
1014+
for packet_i, packet in enumerate(packets.get('packets', [])):
1015+
packet_rount += 1
1016+
1017+
print(" ")
1018+
print("packet>", packet)
1019+
pdf.set_xy(13, rowy+15+packet_i*4)
1020+
pdf.cell(40, 5, str(packet['packets']['_id']))
1021+
if len(packet['packets']['position'][0]['path_string']):
1022+
pdf.cell(90, 5, str(packet['packets']['position'][0]['warehouse']['code']) + " / " + str(packet['packets']['position'][0]['path_string'][0]) + " / " + str(packet['packets']['position'][0]['name']) + " ("+str(packet['packets']['position'][0].get('text', ''))+")")
1023+
else:
1024+
pdf.cell(90, 5, str(packet['packets']['position'][0]['warehouse']['code']) + " / " + str(packet['packets']['position'][0]['name']) + " ("+str(packet['packets']['position'][0].get('text', ''))+")")
1025+
pdf.cell(10, 5, str(packet['packet_count'])+ " ks")
9231026

1027+
pdf.rounded_rect(13, rowy+15, 185, 5+packet_i*4, 1)
1028+
pdf.set_line_width(0.01)
1029+
pdf.set_draw_color(0,0,0)
1030+
pdf.set_text_color(0,0,0)
9241031

925-
pdf.line(10,first_row+j*rowh + 16, 200, first_row+j*rowh + 16)
926-
print("===================Value==========================================")
1032+
rowy = rowy + (17 + 6*packet_rount)
1033+
pdf.line(10,rowy-1, 200, rowy-1)
1034+
print("===================Value==========================================", packet_rount)
9271035

9281036
pdf.alias_nb_pages()
9291037
pdf.output("static/production.pdf")

src/OpenIntranet/templates/base.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<a href="/"><img src="/storage/logo.png" alt="Logo" style="height:4em;"></a>
127127

128128
<span>
129-
{%if current_user %}<span class="current_cart"></span> <i class="material-icons">account_circle</i>{{current_user['user']}} <a href="/logout">Odhlásit</a><br> Sklad: {% if current_user['param']['warehouse_info']%} {{current_user['param']['warehouse_info']['name']}} {%else%} Nic {%end%}{%else%} <a href="/login">přihlásit se</a>{%end%}
129+
{%if current_user %}<span class="current_cart"></span> <i class="material-icons">account_circle</i>{{current_user['user']}} <a href="/logout">Odhlásit</a><br> Sklad: {% if current_user['param']['warehouse_info']%} {{current_user['param']['warehouse_info']['name']}} {%else%} Sklad není vybrán {%end%}{%else%} <a href="/login">přihlásit se</a>{%end%}
130130
<i class="material-icons barcode-icon">remove</i>
131131
</span>
132132

src/OpenIntranet/templates/production.bom_table.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@
4444

4545
<div>
4646
{%try%}
47-
{% if not len(row['packets']) %}
47+
{% if not valid %}
48+
<div>
49+
<i class="bi bi-x-square"></i> Součástka není přiřazena
50+
<span unit_required="{{len(row['Ref'])}}" unit_available="0" class="count_validation"></span>
51+
</div>
52+
{% elif not len(row['packets']) %}
4853
<div>
4954
<i class="bi bi-exclamation-square"></i> Není ve skladu
5055
<span unit_required="{{len(row['Ref'])}}" unit_available="0" class="count_validation"></span>

0 commit comments

Comments
 (0)