Merge pull request #116 from eReuse/change/#115-monir-changes-deliverynote

Change/#115 monir changes deliverynote
This commit is contained in:
cayop 2021-02-11 13:30:19 +01:00 committed by GitHub
commit a2b0d0c02f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 39 additions and 47 deletions

View file

@ -273,8 +273,3 @@ class MigrateToDef(ActionDef):
class MigrateFromDef(ActionDef): class MigrateFromDef(ActionDef):
VIEW = None VIEW = None
SCHEMA = schemas.MigrateFrom SCHEMA = schemas.MigrateFrom
class TransferredDef(ActionDef):
VIEW = None
SCHEMA = schemas.Transferred

View file

@ -1628,8 +1628,3 @@ def update_parent(target: Union[EraseBasic, Test, Install], device: Device, _, _
class InvalidRangeForPrice(ValueError): class InvalidRangeForPrice(ValueError):
pass pass
class Transferred(ActionWithMultipleDevices):
"""Transferred through blockchain."""
pass

View file

@ -534,7 +534,3 @@ class MigrateTo(Migrate):
class MigrateFrom(Migrate): class MigrateFrom(Migrate):
pass pass
class Transferred(ActionWithMultipleDevices):
pass

View file

@ -511,7 +511,3 @@ class MigrateTo(Migrate):
class MigrateFrom(Migrate): class MigrateFrom(Migrate):
__doc__ = m.MigrateFrom.__doc__ __doc__ = m.MigrateFrom.__doc__
class Transferred(ActionWithMultipleDevices):
__doc__ = m.Transferred.__doc__

View file

@ -16,7 +16,7 @@ class DeliverynoteView(View):
dn = request.get_json() dn = request.get_json()
dlvnote = Deliverynote(**dn) dlvnote = Deliverynote(**dn)
# Create a lot # Create a lot
lot_name = dlvnote.supplier_email + "_" + datetime.datetime.utcnow().strftime("%B-%d-%Y") lot_name = dlvnote.document_id + "_" + datetime.datetime.utcnow().strftime("%Y-%m-%d")
new_lot = Lot(name=lot_name) new_lot = Lot(name=lot_name)
dlvnote.lot_id = new_lot.id dlvnote.lot_id = new_lot.id
db.session.add(new_lot) db.session.add(new_lot)

View file

@ -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'] = ''

View file

@ -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

View file

@ -118,4 +118,4 @@ def test_api_docs(client: Client):
'scheme': 'basic', 'scheme': 'basic',
'name': 'Authorization' 'name': 'Authorization'
} }
assert len(docs['definitions']) == 118 assert len(docs['definitions']) == 117

View file

@ -35,4 +35,4 @@ def test_simple_deliverynote(user: UserClient, app: Devicehub):
db_note = Deliverynote.query.filter_by(id=deliverynote['id']).one() db_note = Deliverynote.query.filter_by(id=deliverynote['id']).one()
assert deliverynote['documentID'] == note['documentID'] assert deliverynote['documentID'] == note['documentID']
assert user.user['email'] in db_note.lot.name assert deliverynote['documentID'] in db_note.lot.name

View file

@ -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