adding documentId in csv of devices report

This commit is contained in:
Cayo Puigdefabregas 2021-02-07 18:16:43 +01:00
parent f80db15506
commit 1a0287f8f9
6 changed files with 37 additions and 27 deletions

View File

@ -84,4 +84,4 @@ class Deliverynote(Thing):
db.session.delete(self)
def __repr__(self) -> str:
return '<Deliverynote {0.documentID}>'.format(self)
return '<Deliverynote {0.document_id}>'.format(self)

View File

@ -32,9 +32,10 @@ class DeviceRow(OrderedDict):
d.SoundCard.t,
]
def __init__(self, device: d.Device) -> None:
def __init__(self, device: d.Device, document_ids: dict) -> None:
super().__init__()
self.device = device
self.document_id = document_ids.get(device.id, '')
snapshot = get_action(device, 'Snapshot')
software = ''
if snapshot:
@ -42,6 +43,7 @@ class DeviceRow(OrderedDict):
software=snapshot.software.name, version=snapshot.version)
# General information about device
self['System ID'] = device.id
self['DocumentID'] = self.document_id
self['Public Link'] = '{url}{id}'.format(url=url_for('Device.main', _external=True),
id=device.id)
self['Tag 1 Type'] = self['Tag 1 ID'] = self['Tag 1 Organization'] = ''

View File

@ -19,6 +19,7 @@ from teal.resource import Resource, View
from ereuse_devicehub.db import db
from ereuse_devicehub.resources.action import models as evs
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.documents.device_row import DeviceRow, StockRow, ActionRow
from ereuse_devicehub.resources.lot import LotView
@ -119,8 +120,9 @@ class DevicesDocumentView(DeviceView):
data = StringIO()
cw = csv.writer(data, delimiter=';', lineterminator="\n", quotechar='"')
first = True
document_ids = self.get_documents_id()
for device in query:
d = DeviceRow(device)
d = DeviceRow(device, document_ids)
if first:
cw.writerow(d.keys())
first = False
@ -132,6 +134,12 @@ class DevicesDocumentView(DeviceView):
output.headers['Content-type'] = 'text/csv'
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):
@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

View File

@ -216,13 +216,13 @@ def test_export_basic_snapshot(user: UserClient):
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
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'
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][20:] == export_csv[1][20:], '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][21:] == export_csv[1][21:], 'Computer information are not equal'
@pytest.mark.mvp
@ -276,24 +276,24 @@ def test_export_extended(app: Devicehub, user: UserClient):
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
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'
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][20:79] == export_csv[1][20:79], 'Computer information are not equal'
assert fixture_csv[1][80] == export_csv[1][80], 'Computer information are not equal'
assert fixture_csv[1][83:] == export_csv[1][83:], '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][20:79] == export_csv[2][20:79], 'Computer information are not equal'
assert fixture_csv[2][80] == export_csv[2][80], '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][104] == export_csv[2][104], '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][128] == export_csv[2][128], 'Computer information are not equal'
assert fixture_csv[2][131:] == export_csv[2][131:], '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][21:80] == export_csv[1][21:80], 'Computer information are not equal'
assert fixture_csv[1][81] == export_csv[1][81], 'Computer information are not equal'
assert fixture_csv[1][84:] == export_csv[1][84:], '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][21:80] == export_csv[2][21:80], 'Computer information are not equal'
assert fixture_csv[2][81] == export_csv[2][81], '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][105] == export_csv[2][105], '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][129] == export_csv[2][129], 'Computer information are not equal'
assert fixture_csv[2][132:] == export_csv[2][132:], 'Computer information are not equal'
@pytest.mark.mvp