diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py index f437b0cd..6709ea08 100644 --- a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -27,6 +27,9 @@ def get_inv(): def upgrade(): op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') + op.alter_column('deliverynote', 'deposit', new_column_name='amount') + op.alter_column('computer', 'deposit', new_column_name='amount') + op.alter_column('lot', 'deposit', new_column_name='amount') op.drop_column('computer', 'deliverynote_address', schema=f'{get_inv()}') op.drop_column('lot', 'deliverynote_address', schema=f'{get_inv()}') op.drop_table('proof_function', schema=f'{get_inv()}') @@ -41,6 +44,9 @@ def upgrade(): def downgrade(): op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') + op.alter_column('deliverynote', 'amount', new_column_name='deposit') + op.alter_column('computer', 'amount', new_column_name='deposit') + op.alter_column('lot', 'amount', new_column_name='deposit') op.add_column('computer', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') op.create_table('proof', diff --git a/ereuse_devicehub/resources/deliverynote/models.py b/ereuse_devicehub/resources/deliverynote/models.py index 5b56312e..57eefe08 100644 --- a/ereuse_devicehub/resources/deliverynote/models.py +++ b/ereuse_devicehub/resources/deliverynote/models.py @@ -36,7 +36,7 @@ class Deliverynote(Thing): receiver = db.relationship(User, primaryjoin=lambda: Deliverynote.receiver_address == User.email) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date.comment = 'The date the DeliveryNote initiated' - deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) + amount = db.Column(db.Integer, check_range('amount', min=0, max=100), default=0) # The following fields are supposed to be 0:N relationships # to SnapshotDelivery entity. # At this stage of implementation they will treated as a @@ -54,14 +54,14 @@ class Deliverynote(Thing): lazy=True, primaryjoin=Lot.id == lot_id) - def __init__(self, document_id: str, deposit: str, date, + def __init__(self, document_id: str, amount: str, date, supplier_email: str, expected_devices: Iterable, transfer_state: TransferState) -> None: """Initializes a delivery note """ super().__init__(id=uuid.uuid4(), - document_id=document_id, deposit=deposit, date=date, + document_id=document_id, amount=amount, date=date, supplier_email=supplier_email, expected_devices=expected_devices, transfer_state=transfer_state) diff --git a/ereuse_devicehub/resources/deliverynote/models.pyi b/ereuse_devicehub/resources/deliverynote/models.pyi index d428a7cd..1a5714f9 100644 --- a/ereuse_devicehub/resources/deliverynote/models.pyi +++ b/ereuse_devicehub/resources/deliverynote/models.pyi @@ -24,7 +24,7 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column owner = ... # type: relationship transfer_state = ... # type: Column diff --git a/ereuse_devicehub/resources/deliverynote/schemas.py b/ereuse_devicehub/resources/deliverynote/schemas.py index 60854991..f0dbecdc 100644 --- a/ereuse_devicehub/resources/deliverynote/schemas.py +++ b/ereuse_devicehub/resources/deliverynote/schemas.py @@ -19,8 +19,8 @@ class Deliverynote(Thing): supplier = NestedOn(s_user.User, dump_only=True) receiver = NestedOn(s_user.User, dump_only=True) date = f.DateTime('iso', required=True) - deposit = f.Integer(validate=f.validate.Range(min=0, max=100), - description=m.Deliverynote.deposit.__doc__) + amount = f.Integer(validate=f.validate.Range(min=0, max=100), + description=m.Deliverynote.amount.__doc__) expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index da1c0888..d5503d13 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -472,7 +472,7 @@ class Computer(Device): It is a subset of the Linux definition of DMI / DMI decode. """ ethereum_address = Column(CIText(), unique=True, default=None) - deposit = Column(Integer, check_range('deposit', min=0, max=100), default=0) + amount = Column(Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False, diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 6b3b8dc4..ba1e2fd8 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -141,7 +141,7 @@ class DisplayMixin: class Computer(DisplayMixin, Device): components = ... # type: Column chassis = ... # type: Column - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column transfer_state = ... # type: Column receiver_address = ... # type: Column diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 512c11bb..ac2d117d 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -124,8 +124,8 @@ class Computer(Device): collection_class=set, description=m.Computer.privacy.__doc__) ethereum_address = SanitizedStr(validate=f.validate.Length(max=42)) - deposit = Integer(validate=f.validate.Range(min=0, max=100), - description=m.Computer.deposit.__doc__) + amount = Integer(validate=f.validate.Range(min=0, max=100), + description=m.Computer.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') owner_id = UUID(data_key='ownerID') transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 4be0678b..5022b24e 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -63,7 +63,7 @@ class Lot(Thing): """All devices, including components, inside this lot and its descendants. """ - deposit = db.Column(db.Integer, check_range('deposit', min=0, max=100), default=0) + amount = db.Column(db.Integer, check_range('amount', min=0, max=100), default=0) owner_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False, diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index 0ba97058..f70078c7 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -24,7 +24,7 @@ class Lot(Thing): description = ... # type: Column all_devices = ... # type: relationship parents = ... # type: relationship - deposit = ... # type: Column + amount = ... # type: Column owner_address = ... # type: Column owner = ... # type: relationship transfer_state = ... # type: Column diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index c30f3890..72e49efe 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -19,8 +19,8 @@ class Lot(Thing): children = NestedOn('Lot', many=True, dump_only=True) parents = NestedOn('Lot', many=True, dump_only=True) url = URL(dump_only=True, description=m.Lot.url.__doc__) - deposit = f.Integer(validate=f.validate.Range(min=0, max=100), - description=m.Lot.deposit.__doc__) + amount = f.Integer(validate=f.validate.Range(min=0, max=100), + description=m.Lot.amount.__doc__) # author_id = NestedOn(s_user.User,only_query='author_id') owner_id = f.UUID(data_key='ownerID') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index d2b827e5..e9395ff5 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -41,11 +41,11 @@ class LotView(View): def patch(self, id): patch_schema = self.resource_def.SCHEMA(only=( - 'name', 'description', 'transfer_state', 'receiver_address', 'deposit', 'devices', + 'name', 'description', 'transfer_state', 'receiver_address', 'amount', 'devices', 'owner_address'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() - device_fields = ['transfer_state', 'receiver_address', 'deposit', 'owner_address'] + device_fields = ['transfer_state', 'receiver_address', 'amount', 'owner_address'] computers = [x for x in lot.all_devices if isinstance(x, Computer)] for key, value in l.items(): setattr(lot, key, value) @@ -142,9 +142,9 @@ class LotView(View): if path: cls._p(node['nodes'], path) - def get_lot_deposit(self, l: Lot): - """Return lot deposit value""" - return l.deposit + def get_lot_amount(self, l: Lot): + """Return lot amount value""" + return l.amount def change_state(self): """Change state of Lot""" diff --git a/tests/test_deliverynote.py b/tests/test_deliverynote.py index 2f4bcb74..9940e14f 100644 --- a/tests/test_deliverynote.py +++ b/tests/test_deliverynote.py @@ -26,7 +26,7 @@ def test_simple_deliverynote(user: UserClient, app: Devicehub): }] note = {'date': datetime(2020, 2, 14, 23, 0, tzinfo=tzutc()), 'documentID': 'DocBBE001', - 'deposit': 0, + 'amount': 0, 'transfer_state': "Initial", 'expectedDevices': inventory, 'supplierEmail': user.user['email']} diff --git a/tests/test_device.py b/tests/test_device.py index e7810542..fa6de215 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -125,7 +125,7 @@ def test_physical_properties(): } assert pc.physical_properties == { 'chassis': ComputerChassis.Tower, - 'deposit': 0, + 'amount': 0, 'ethereum_address': None, 'manufacturer': 'bar', 'model': 'foo', @@ -251,7 +251,7 @@ def test_sync_execute_register_desktop_existing_no_tag(): **conftest.file('pc-components.db')['device']) # Create a new transient non-db object # 1: device exists on DB db_pc = Sync().execute_register(pc) - pc.deposit = 0 + pc.amount = 0 pc.owner_id = db_pc.owner_id pc.transfer_state = TransferState.Initial assert pc.physical_properties == db_pc.physical_properties