diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 4e732ed2..72c29e70 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1377,6 +1377,10 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices): """ +class InitTransfer(Trade): + """The act of transfer ownership of devices between two agents""" + + class Sell(Trade): """The act of taking money from a buyer in exchange of a device.""" @@ -1445,32 +1449,6 @@ class Receive(JoinedTableMixin, ActionWithMultipleDevices): default=ReceiverRole.Intermediary) -class ShareDeliveryNote(JoinedTableMixin, ActionWithMultipleDevices): - """To share a DeliveryNote to between owners.""" - # New variables for DeliveryNote - supplier = db.Column() # String, nullable, ... - supplier.comment = """Name of the organization/agent that create DeliveryNote.""" - date_delivery_note = db.Column() - date_delivery_note.comment = """Date of note creation.""" - # Is the same of lot id?? - id_delivery_note = db.Column(UUID(as_uuid=True)) - id_delivery_note.comment = """Unique id of lot and delivery note.""" - deposit = db.Column() - deposit.comment = """Total amount of deposit devices in Lot.""" - address_note = db.Column(UUID(as_uuid=True)) - address_note.comment = """Address identifier in the blockchain.""" - - agent_id = Column(UUID(as_uuid=True), - ForeignKey(Agent.id), - nullable=False, - default=lambda: g.user.individual.id) - - -class ConfirmDeliveryNote(JoinedTableMixin, ActionWithMultipleDevices): - """To confirm a DeliveryNote that has been shared.""" - pass - - class Migrate(JoinedTableMixin, ActionWithMultipleDevices): """Moves the devices to a new database/inventory. Devices cannot be modified anymore at the previous database. diff --git a/ereuse_devicehub/resources/action/models.pyi b/ereuse_devicehub/resources/action/models.pyi index c7969094..42780ef0 100644 --- a/ereuse_devicehub/resources/action/models.pyi +++ b/ereuse_devicehub/resources/action/models.pyi @@ -493,6 +493,10 @@ class Trade(ActionWithMultipleDevices): self.confirms = ... # type: Organize +class InitTransfer(Trade): + pass + + class Sell(Trade): pass @@ -529,10 +533,6 @@ class Receive(ActionWithMultipleDevices): self.role = ... # type: ReceiverRole -class ShareDeliveryNote(ActionWithMultipleDevices): - pass - - class Migrate(ActionWithMultipleDevices): other = ... # type: Column diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index b8eeafcf..68fdebf9 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -397,6 +397,10 @@ class Trade(ActionWithMultipleDevices): confirms = NestedOn(Organize) +class InitTransfer(Trade): + __doc__ = m.InitTransfer.__doc__ + + class Sell(Trade): __doc__ = m.Sell.__doc__ @@ -430,15 +434,6 @@ class Receive(ActionWithMultipleDevices): role = EnumField(ReceiverRole) -class ShareDeliveryNote(ActionWithMultipleDevices): - __doc__ = m.ShareDeliveryNote.__doc__ - supplier = SanitizedStr(validate=Length(max=STR_SIZE), data_key='supplierName') - date_delivery_note = DateTime(data_key='dateDeliveryNote') - deposit = Integer(data_key='depositValue') - address_note = UUID(dump_only=True) - id_delivery_note = UUID(dump_only=True) - - class Migrate(ActionWithMultipleDevices): __doc__ = m.Migrate.__doc__ other = URL() diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index de6805b4..9a7b176c 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -8,7 +8,8 @@ from teal.marshmallow import ValidationError from teal.resource import View from ereuse_devicehub.db import db -from ereuse_devicehub.resources.action.models import Action, RateComputer, Snapshot, VisualTest +from ereuse_devicehub.resources.action.models import Action, RateComputer, Snapshot, VisualTest, \ + InitTransfer from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate from ereuse_devicehub.resources.device.models import Component, Computer from ereuse_devicehub.resources.enums import SnapshotSoftware @@ -31,6 +32,8 @@ class ActionView(View): if json['type'] == VisualTest.t: pass # TODO JN add compute rate with new visual test and old components device + if json['type'] == InitTransfer.t: + return self.transfer_ownership() Model = db.Model._decl_class_registry.data[json['type']]() action = Model(**a) db.session.add(action) @@ -101,3 +104,7 @@ class ActionView(View): ret.status_code = 201 db.session.commit() return ret + + def transfer_ownership(self): + """Perform a InitTransfer action to change author_id of device""" + pass diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index bb214f6f..d9a037d8 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -27,17 +27,6 @@ class Lot(Thing): closed = db.Column(db.Boolean, default=False, nullable=False) closed.comment = """A closed lot cannot be modified anymore.""" - # New variables for DeliveryNote - supplier = db.Column() # String, nullable, ... - supplier.comment = """Name of the organization/agent that create DeliveryNote.""" - date_delivery_note = db.Column() - date_delivery_note.comment = """Date of note creation.""" - # Is the same of lot id?? - id_delivery_note = db.Column(UUID(as_uuid=True)) - id_delivery_note.comment = """Unique id of lot and delivery note""" - # deposit = db.Column() - # deposit.comment = """Total amount of deposit devices in Lot.""" - devices = db.relationship(Device, backref=db.backref('lots', lazy=True, collection_class=set), secondary=lambda: LotDevice.__table__, diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 4e3a9f06..dca07061 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -43,6 +43,11 @@ class LotView(View): patch_schema = self.resource_def.SCHEMA(only=('name', 'description'), partial=True) l = request.get_json(schema=patch_schema) lot = Lot.query.filter_by(id=id).one() + if lot.transfer_state.name == 'Initial': + # Initial lot transfer state case + # deposit = self.get_lot_deposit(lot) + # Do something with deposit variable + pass for key, value in l.items(): setattr(lot, key, value) db.session.commit() @@ -123,6 +128,18 @@ 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 change_state(self): + """Change state of Lot""" + pass + + def transfer_ownership_lot(self): + """Perform a InitTransfer action to change author_id of lot""" + pass + class LotBaseChildrenView(View): """Base class for adding / removing children devices and