change deposit for amount

This commit is contained in:
Cayo Puigdefabregas 2021-02-05 13:21:20 +01:00
parent 761e70b5e6
commit cb3f07eb5a
13 changed files with 28 additions and 22 deletions

View File

@ -27,6 +27,9 @@ def get_inv():
def upgrade(): def upgrade():
op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') 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('computer', 'deliverynote_address', schema=f'{get_inv()}')
op.drop_column('lot', '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()}') op.drop_table('proof_function', schema=f'{get_inv()}')
@ -41,6 +44,9 @@ def upgrade():
def downgrade(): def downgrade():
op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') 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('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.add_column('lot', sa.Column('deliverynote_address', citext.CIText(), nullable=True), schema=f'{get_inv()}')
op.create_table('proof', op.create_table('proof',

View File

@ -36,7 +36,7 @@ class Deliverynote(Thing):
receiver = db.relationship(User, primaryjoin=lambda: Deliverynote.receiver_address == User.email) receiver = db.relationship(User, primaryjoin=lambda: Deliverynote.receiver_address == User.email)
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
date.comment = 'The date the DeliveryNote initiated' 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 # The following fields are supposed to be 0:N relationships
# to SnapshotDelivery entity. # to SnapshotDelivery entity.
# At this stage of implementation they will treated as a # At this stage of implementation they will treated as a
@ -54,14 +54,14 @@ class Deliverynote(Thing):
lazy=True, lazy=True,
primaryjoin=Lot.id == lot_id) 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, supplier_email: str,
expected_devices: Iterable, expected_devices: Iterable,
transfer_state: TransferState) -> None: transfer_state: TransferState) -> None:
"""Initializes a delivery note """Initializes a delivery note
""" """
super().__init__(id=uuid.uuid4(), 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, supplier_email=supplier_email,
expected_devices=expected_devices, expected_devices=expected_devices,
transfer_state=transfer_state) transfer_state=transfer_state)

View File

@ -24,7 +24,7 @@ class Lot(Thing):
description = ... # type: Column description = ... # type: Column
all_devices = ... # type: relationship all_devices = ... # type: relationship
parents = ... # type: relationship parents = ... # type: relationship
deposit = ... # type: Column amount = ... # type: Column
owner_address = ... # type: Column owner_address = ... # type: Column
owner = ... # type: relationship owner = ... # type: relationship
transfer_state = ... # type: Column transfer_state = ... # type: Column

View File

@ -19,8 +19,8 @@ class Deliverynote(Thing):
supplier = NestedOn(s_user.User, dump_only=True) supplier = NestedOn(s_user.User, dump_only=True)
receiver = NestedOn(s_user.User, dump_only=True) receiver = NestedOn(s_user.User, dump_only=True)
date = f.DateTime('iso', required=True) date = f.DateTime('iso', required=True)
deposit = f.Integer(validate=f.validate.Range(min=0, max=100), amount = f.Integer(validate=f.validate.Range(min=0, max=100),
description=m.Deliverynote.deposit.__doc__) description=m.Deliverynote.amount.__doc__)
expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices')
transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices')
transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)

View File

@ -472,7 +472,7 @@ class Computer(Device):
It is a subset of the Linux definition of DMI / DMI decode. It is a subset of the Linux definition of DMI / DMI decode.
""" """
ethereum_address = Column(CIText(), unique=True, default=None) 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), owner_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id), db.ForeignKey(User.id),
nullable=False, nullable=False,

View File

@ -141,7 +141,7 @@ class DisplayMixin:
class Computer(DisplayMixin, Device): class Computer(DisplayMixin, Device):
components = ... # type: Column components = ... # type: Column
chassis = ... # type: Column chassis = ... # type: Column
deposit = ... # type: Column amount = ... # type: Column
owner_address = ... # type: Column owner_address = ... # type: Column
transfer_state = ... # type: Column transfer_state = ... # type: Column
receiver_address = ... # type: Column receiver_address = ... # type: Column

View File

@ -124,8 +124,8 @@ class Computer(Device):
collection_class=set, collection_class=set,
description=m.Computer.privacy.__doc__) description=m.Computer.privacy.__doc__)
ethereum_address = SanitizedStr(validate=f.validate.Length(max=42)) ethereum_address = SanitizedStr(validate=f.validate.Length(max=42))
deposit = Integer(validate=f.validate.Range(min=0, max=100), amount = Integer(validate=f.validate.Range(min=0, max=100),
description=m.Computer.deposit.__doc__) description=m.Computer.amount.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id') # author_id = NestedOn(s_user.User,only_query='author_id')
owner_id = UUID(data_key='ownerID') owner_id = UUID(data_key='ownerID')
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)

View File

@ -63,7 +63,7 @@ class Lot(Thing):
"""All devices, including components, inside this lot and its """All devices, including components, inside this lot and its
descendants. 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), owner_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id), db.ForeignKey(User.id),
nullable=False, nullable=False,

View File

@ -24,7 +24,7 @@ class Lot(Thing):
description = ... # type: Column description = ... # type: Column
all_devices = ... # type: relationship all_devices = ... # type: relationship
parents = ... # type: relationship parents = ... # type: relationship
deposit = ... # type: Column amount = ... # type: Column
owner_address = ... # type: Column owner_address = ... # type: Column
owner = ... # type: relationship owner = ... # type: relationship
transfer_state = ... # type: Column transfer_state = ... # type: Column

View File

@ -19,8 +19,8 @@ class Lot(Thing):
children = NestedOn('Lot', many=True, dump_only=True) children = NestedOn('Lot', many=True, dump_only=True)
parents = 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__) url = URL(dump_only=True, description=m.Lot.url.__doc__)
deposit = f.Integer(validate=f.validate.Range(min=0, max=100), amount = f.Integer(validate=f.validate.Range(min=0, max=100),
description=m.Lot.deposit.__doc__) description=m.Lot.amount.__doc__)
# author_id = NestedOn(s_user.User,only_query='author_id') # author_id = NestedOn(s_user.User,only_query='author_id')
owner_id = f.UUID(data_key='ownerID') owner_id = f.UUID(data_key='ownerID')
transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)

View File

@ -41,11 +41,11 @@ class LotView(View):
def patch(self, id): def patch(self, id):
patch_schema = self.resource_def.SCHEMA(only=( 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) 'owner_address'), partial=True)
l = request.get_json(schema=patch_schema) l = request.get_json(schema=patch_schema)
lot = Lot.query.filter_by(id=id).one() 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)] computers = [x for x in lot.all_devices if isinstance(x, Computer)]
for key, value in l.items(): for key, value in l.items():
setattr(lot, key, value) setattr(lot, key, value)
@ -142,9 +142,9 @@ class LotView(View):
if path: if path:
cls._p(node['nodes'], path) cls._p(node['nodes'], path)
def get_lot_deposit(self, l: Lot): def get_lot_amount(self, l: Lot):
"""Return lot deposit value""" """Return lot amount value"""
return l.deposit return l.amount
def change_state(self): def change_state(self):
"""Change state of Lot""" """Change state of Lot"""

View File

@ -26,7 +26,7 @@ def test_simple_deliverynote(user: UserClient, app: Devicehub):
}] }]
note = {'date': datetime(2020, 2, 14, 23, 0, tzinfo=tzutc()), note = {'date': datetime(2020, 2, 14, 23, 0, tzinfo=tzutc()),
'documentID': 'DocBBE001', 'documentID': 'DocBBE001',
'deposit': 0, 'amount': 0,
'transfer_state': "Initial", 'transfer_state': "Initial",
'expectedDevices': inventory, 'expectedDevices': inventory,
'supplierEmail': user.user['email']} 'supplierEmail': user.user['email']}

View File

@ -125,7 +125,7 @@ def test_physical_properties():
} }
assert pc.physical_properties == { assert pc.physical_properties == {
'chassis': ComputerChassis.Tower, 'chassis': ComputerChassis.Tower,
'deposit': 0, 'amount': 0,
'ethereum_address': None, 'ethereum_address': None,
'manufacturer': 'bar', 'manufacturer': 'bar',
'model': 'foo', '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 **conftest.file('pc-components.db')['device']) # Create a new transient non-db object
# 1: device exists on DB # 1: device exists on DB
db_pc = Sync().execute_register(pc) db_pc = Sync().execute_register(pc)
pc.deposit = 0 pc.amount = 0
pc.owner_id = db_pc.owner_id pc.owner_id = db_pc.owner_id
pc.transfer_state = TransferState.Initial pc.transfer_state = TransferState.Initial
assert pc.physical_properties == db_pc.physical_properties assert pc.physical_properties == db_pc.physical_properties