Merge pull request #116 from eReuse/change/#115-monir-changes-deliverynote
Change/#115 monir changes deliverynote
This commit is contained in:
commit
a2b0d0c02f
|
@ -273,8 +273,3 @@ class MigrateToDef(ActionDef):
|
|||
class MigrateFromDef(ActionDef):
|
||||
VIEW = None
|
||||
SCHEMA = schemas.MigrateFrom
|
||||
|
||||
|
||||
class TransferredDef(ActionDef):
|
||||
VIEW = None
|
||||
SCHEMA = schemas.Transferred
|
||||
|
|
|
@ -1628,8 +1628,3 @@ def update_parent(target: Union[EraseBasic, Test, Install], device: Device, _, _
|
|||
|
||||
class InvalidRangeForPrice(ValueError):
|
||||
pass
|
||||
|
||||
|
||||
class Transferred(ActionWithMultipleDevices):
|
||||
"""Transferred through blockchain."""
|
||||
pass
|
||||
|
|
|
@ -534,7 +534,3 @@ class MigrateTo(Migrate):
|
|||
|
||||
class MigrateFrom(Migrate):
|
||||
pass
|
||||
|
||||
|
||||
class Transferred(ActionWithMultipleDevices):
|
||||
pass
|
||||
|
|
|
@ -511,7 +511,3 @@ class MigrateTo(Migrate):
|
|||
|
||||
class MigrateFrom(Migrate):
|
||||
__doc__ = m.MigrateFrom.__doc__
|
||||
|
||||
|
||||
class Transferred(ActionWithMultipleDevices):
|
||||
__doc__ = m.Transferred.__doc__
|
||||
|
|
|
@ -16,7 +16,7 @@ class DeliverynoteView(View):
|
|||
dn = request.get_json()
|
||||
dlvnote = Deliverynote(**dn)
|
||||
# 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)
|
||||
dlvnote.lot_id = new_lot.id
|
||||
db.session.add(new_lot)
|
||||
|
|
|
@ -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'] = ''
|
||||
|
|
|
@ -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
|
@ -118,4 +118,4 @@ def test_api_docs(client: Client):
|
|||
'scheme': 'basic',
|
||||
'name': 'Authorization'
|
||||
}
|
||||
assert len(docs['definitions']) == 118
|
||||
assert len(docs['definitions']) == 117
|
||||
|
|
|
@ -35,4 +35,4 @@ def test_simple_deliverynote(user: UserClient, app: Devicehub):
|
|||
db_note = Deliverynote.query.filter_by(id=deliverynote['id']).one()
|
||||
|
||||
assert deliverynote['documentID'] == note['documentID']
|
||||
assert user.user['email'] in db_note.lot.name
|
||||
assert deliverynote['documentID'] in db_note.lot.name
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in a new issue