adding documentId in csv of devices report
This commit is contained in:
parent
f80db15506
commit
1a0287f8f9
|
@ -84,4 +84,4 @@ class Deliverynote(Thing):
|
||||||
db.session.delete(self)
|
db.session.delete(self)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return '<Deliverynote {0.documentID}>'.format(self)
|
return '<Deliverynote {0.document_id}>'.format(self)
|
||||||
|
|
|
@ -32,9 +32,10 @@ class DeviceRow(OrderedDict):
|
||||||
d.SoundCard.t,
|
d.SoundCard.t,
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, device: d.Device) -> None:
|
def __init__(self, device: d.Device, document_ids: dict) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.device = device
|
self.device = device
|
||||||
|
self.document_id = document_ids.get(device.id, '')
|
||||||
snapshot = get_action(device, 'Snapshot')
|
snapshot = get_action(device, 'Snapshot')
|
||||||
software = ''
|
software = ''
|
||||||
if snapshot:
|
if snapshot:
|
||||||
|
@ -42,6 +43,7 @@ class DeviceRow(OrderedDict):
|
||||||
software=snapshot.software.name, version=snapshot.version)
|
software=snapshot.software.name, version=snapshot.version)
|
||||||
# General information about device
|
# General information about device
|
||||||
self['System ID'] = device.id
|
self['System ID'] = device.id
|
||||||
|
self['DocumentID'] = self.document_id
|
||||||
self['Public Link'] = '{url}{id}'.format(url=url_for('Device.main', _external=True),
|
self['Public Link'] = '{url}{id}'.format(url=url_for('Device.main', _external=True),
|
||||||
id=device.id)
|
id=device.id)
|
||||||
self['Tag 1 Type'] = self['Tag 1 ID'] = self['Tag 1 Organization'] = ''
|
self['Tag 1 Type'] = self['Tag 1 ID'] = self['Tag 1 Organization'] = ''
|
||||||
|
|
|
@ -19,6 +19,7 @@ from teal.resource import Resource, View
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.action import models as evs
|
from ereuse_devicehub.resources.action import models as evs
|
||||||
from ereuse_devicehub.resources.device import models as devs
|
from ereuse_devicehub.resources.device import models as devs
|
||||||
|
from ereuse_devicehub.resources.deliverynote.models import Deliverynote
|
||||||
from ereuse_devicehub.resources.device.views import DeviceView
|
from ereuse_devicehub.resources.device.views import DeviceView
|
||||||
from ereuse_devicehub.resources.documents.device_row import DeviceRow, StockRow, ActionRow
|
from ereuse_devicehub.resources.documents.device_row import DeviceRow, StockRow, ActionRow
|
||||||
from ereuse_devicehub.resources.lot import LotView
|
from ereuse_devicehub.resources.lot import LotView
|
||||||
|
@ -119,8 +120,9 @@ class DevicesDocumentView(DeviceView):
|
||||||
data = StringIO()
|
data = StringIO()
|
||||||
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
|
||||||
first = True
|
first = True
|
||||||
|
document_ids = self.get_documents_id()
|
||||||
for device in query:
|
for device in query:
|
||||||
d = DeviceRow(device)
|
d = DeviceRow(device, document_ids)
|
||||||
if first:
|
if first:
|
||||||
cw.writerow(d.keys())
|
cw.writerow(d.keys())
|
||||||
first = False
|
first = False
|
||||||
|
@ -132,6 +134,12 @@ class DevicesDocumentView(DeviceView):
|
||||||
output.headers['Content-type'] = 'text/csv'
|
output.headers['Content-type'] = 'text/csv'
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def get_documents_id(self):
|
||||||
|
# documentIds = {dev_id: document_id, ...}
|
||||||
|
deliverys = Deliverynote.query.all()
|
||||||
|
documentIds = {x.id: d.document_id for d in deliverys for x in d.lot.devices}
|
||||||
|
return documentIds
|
||||||
|
|
||||||
|
|
||||||
class ActionsDocumentView(DeviceView):
|
class ActionsDocumentView(DeviceView):
|
||||||
@cache(datetime.timedelta(minutes=1))
|
@cache(datetime.timedelta(minutes=1))
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -216,13 +216,13 @@ def test_export_basic_snapshot(user: UserClient):
|
||||||
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
||||||
fixture_csv = list(obj_csv)
|
fixture_csv = list(obj_csv)
|
||||||
|
|
||||||
assert isinstance(datetime.strptime(export_csv[1][17], '%c'), datetime), \
|
assert isinstance(datetime.strptime(export_csv[1][18], '%c'), datetime), \
|
||||||
'Register in field is not a datetime'
|
'Register in field is not a datetime'
|
||||||
|
|
||||||
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
||||||
assert fixture_csv[1][:17] == export_csv[1][:17], 'Computer information are not equal'
|
assert fixture_csv[1][:18] == export_csv[1][:18], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][18] == export_csv[1][18], 'Computer information are not equal'
|
assert fixture_csv[1][19] == export_csv[1][19], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][20:] == export_csv[1][20:], 'Computer information are not equal'
|
assert fixture_csv[1][21:] == export_csv[1][21:], 'Computer information are not equal'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -276,24 +276,24 @@ def test_export_extended(app: Devicehub, user: UserClient):
|
||||||
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
|
||||||
fixture_csv = list(obj_csv)
|
fixture_csv = list(obj_csv)
|
||||||
|
|
||||||
assert isinstance(datetime.strptime(export_csv[1][17], '%c'), datetime), \
|
assert isinstance(datetime.strptime(export_csv[1][18], '%c'), datetime), \
|
||||||
'Register in field is not a datetime'
|
'Register in field is not a datetime'
|
||||||
|
|
||||||
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
assert fixture_csv[0] == export_csv[0], 'Headers are not equal'
|
||||||
assert fixture_csv[1][:17] == export_csv[1][:17], 'Computer information are not equal'
|
assert fixture_csv[1][:18] == export_csv[1][:18], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][18] == export_csv[1][18], 'Computer information are not equal'
|
assert fixture_csv[1][19] == export_csv[1][19], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][20:79] == export_csv[1][20:79], 'Computer information are not equal'
|
assert fixture_csv[1][21:80] == export_csv[1][21:80], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][80] == export_csv[1][80], 'Computer information are not equal'
|
assert fixture_csv[1][81] == export_csv[1][81], 'Computer information are not equal'
|
||||||
assert fixture_csv[1][83:] == export_csv[1][83:], 'Computer information are not equal'
|
assert fixture_csv[1][84:] == export_csv[1][84:], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][:17] == export_csv[2][:17], 'Computer information are not equal'
|
assert fixture_csv[2][:18] == export_csv[2][:18], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][18] == export_csv[2][18], 'Computer information are not equal'
|
assert fixture_csv[2][19] == export_csv[2][19], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][20:79] == export_csv[2][20:79], 'Computer information are not equal'
|
assert fixture_csv[2][21:80] == export_csv[2][21:80], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][80] == export_csv[2][80], 'Computer information are not equal'
|
assert fixture_csv[2][81] == export_csv[2][81], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][83:103] == export_csv[2][83:103], 'Computer information are not equal'
|
assert fixture_csv[2][84:104] == export_csv[2][84:104], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][104] == export_csv[2][104], 'Computer information are not equal'
|
assert fixture_csv[2][105] == export_csv[2][105], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][107:127] == export_csv[2][107:127], 'Computer information are not equal'
|
assert fixture_csv[2][108:128] == export_csv[2][108:128], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][128] == export_csv[2][128], 'Computer information are not equal'
|
assert fixture_csv[2][129] == export_csv[2][129], 'Computer information are not equal'
|
||||||
assert fixture_csv[2][131:] == export_csv[2][131:], 'Computer information are not equal'
|
assert fixture_csv[2][132:] == export_csv[2][132:], 'Computer information are not equal'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
|
Reference in a new issue