add export devices lots
This commit is contained in:
parent
e332cd2d43
commit
49062d9944
|
@ -478,6 +478,7 @@ class ExportsView(View):
|
||||||
'devices': self.devices_list,
|
'devices': self.devices_list,
|
||||||
'certificates': self.erasure,
|
'certificates': self.erasure,
|
||||||
'lots': self.lots_export,
|
'lots': self.lots_export,
|
||||||
|
'devices_lots': self.devices_lots_export,
|
||||||
}
|
}
|
||||||
|
|
||||||
if export_id not in export_ids:
|
if export_id not in export_ids:
|
||||||
|
@ -613,14 +614,6 @@ class ExportsView(View):
|
||||||
receiver_note = lot.transfer and lot.transfer.receiver_note or ''
|
receiver_note = lot.transfer and lot.transfer.receiver_note or ''
|
||||||
wb_devs = 0
|
wb_devs = 0
|
||||||
placeholders = 0
|
placeholders = 0
|
||||||
type_transfer = ''
|
|
||||||
if lot.transfer:
|
|
||||||
if lot.transfer.user_from == g.user:
|
|
||||||
type_transfer = 'Outgoing'
|
|
||||||
if lot.transfer.user_to == g.user:
|
|
||||||
type_transfer = 'Incoming'
|
|
||||||
else:
|
|
||||||
type_transfer = 'Temporary'
|
|
||||||
|
|
||||||
for dev in lot.devices:
|
for dev in lot.devices:
|
||||||
snapshots = [e for e in dev.actions if e.type == 'Snapshot']
|
snapshots = [e for e in dev.actions if e.type == 'Snapshot']
|
||||||
|
@ -634,7 +627,7 @@ class ExportsView(View):
|
||||||
row = [
|
row = [
|
||||||
lot.id,
|
lot.id,
|
||||||
lot.name,
|
lot.name,
|
||||||
type_transfer,
|
lot.type_transfer(),
|
||||||
lot.transfer and (lot.transfer.closed and 'Closed' or 'Open') or '',
|
lot.transfer and (lot.transfer.closed and 'Closed' or 'Open') or '',
|
||||||
lot.transfer and lot.transfer.code or '',
|
lot.transfer and lot.transfer.code or '',
|
||||||
lot.transfer and lot.transfer.date or '',
|
lot.transfer and lot.transfer.date or '',
|
||||||
|
@ -657,6 +650,43 @@ class ExportsView(View):
|
||||||
|
|
||||||
return self.response_csv(data, "lots_export.csv")
|
return self.response_csv(data, "lots_export.csv")
|
||||||
|
|
||||||
|
def devices_lots_export(self):
|
||||||
|
data = StringIO()
|
||||||
|
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
||||||
|
head = [
|
||||||
|
'DHID',
|
||||||
|
'Lot Id',
|
||||||
|
'Lot Name',
|
||||||
|
'Lot Type',
|
||||||
|
'Transfer Status',
|
||||||
|
'Transfer Code',
|
||||||
|
'Transfer Date',
|
||||||
|
'Transfer Creation Date',
|
||||||
|
'Transfer Update Date'
|
||||||
|
]
|
||||||
|
cw.writerow(head)
|
||||||
|
|
||||||
|
for dev in self.find_devices():
|
||||||
|
for lot in dev.lots:
|
||||||
|
type_transfer = lot.type_transfer()
|
||||||
|
if type_transfer in ['Temporary', '']:
|
||||||
|
continue
|
||||||
|
|
||||||
|
row = [
|
||||||
|
dev.devicehub_id,
|
||||||
|
lot.id,
|
||||||
|
lot.name,
|
||||||
|
type_transfer,
|
||||||
|
lot.transfer and (lot.transfer.closed and 'Closed' or 'Open') or '',
|
||||||
|
lot.transfer and lot.transfer.code or '',
|
||||||
|
lot.transfer and lot.transfer.date or '',
|
||||||
|
lot.transfer and lot.transfer.created or '',
|
||||||
|
lot.transfer and lot.transfer.updated or '',
|
||||||
|
]
|
||||||
|
cw.writerow(row)
|
||||||
|
|
||||||
|
return self.response_csv(data, "Devices_Incoming_and_Outgoing_Lots_Spreadsheet.csv")
|
||||||
|
|
||||||
|
|
||||||
class SnapshotListView(GenericMixin):
|
class SnapshotListView(GenericMixin):
|
||||||
template_name = 'inventory/snapshots_list.html'
|
template_name = 'inventory/snapshots_list.html'
|
||||||
|
|
|
@ -151,6 +151,16 @@ class Lot(Thing):
|
||||||
"""Gets the lots that are not under any other lot."""
|
"""Gets the lots that are not under any other lot."""
|
||||||
return cls.query.join(cls.paths).filter(db.func.nlevel(Path.path) == 1)
|
return cls.query.join(cls.paths).filter(db.func.nlevel(Path.path) == 1)
|
||||||
|
|
||||||
|
def type_transfer(self):
|
||||||
|
# Used in reports lots_export.csv
|
||||||
|
if not self.transfer:
|
||||||
|
return 'Temporary'
|
||||||
|
if self.transfer.user_from == g.user:
|
||||||
|
return 'Outgoing'
|
||||||
|
if self.transfer.user_to == g.user:
|
||||||
|
return 'Incoming'
|
||||||
|
return ''
|
||||||
|
|
||||||
def add_children(self, *children):
|
def add_children(self, *children):
|
||||||
"""Add children lots to this lot.
|
"""Add children lots to this lot.
|
||||||
|
|
||||||
|
|
Reference in New Issue