From 8389ffeb54facdcbce71c146744c1a586ec383a9 Mon Sep 17 00:00:00 2001 From: "jordi.nadeu" Date: Thu, 12 Dec 2019 21:17:35 +0100 Subject: [PATCH] add change in Lot and Actions views --- ereuse_devicehub/resources/action/models.py | 30 +++----------------- ereuse_devicehub/resources/action/models.pyi | 8 +++--- ereuse_devicehub/resources/action/schemas.py | 13 +++------ ereuse_devicehub/resources/action/views.py | 9 +++++- ereuse_devicehub/resources/lot/models.py | 11 ------- ereuse_devicehub/resources/lot/views.py | 12 ++++++++ 6 files changed, 32 insertions(+), 51 deletions(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 2302983f..8c04d708 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.""" @@ -1448,32 +1452,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 3293b46a..61010fc8 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 @@ -533,10 +537,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 34108633..bb23f7b2 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -401,6 +401,10 @@ class Trade(ActionWithMultipleDevices): confirms = NestedOn(Organize) +class InitTransfer(Trade): + __doc__ = m.InitTransfer.__doc__ + + class Sell(Trade): __doc__ = m.Sell.__doc__ @@ -438,15 +442,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 30c35633..0c098352 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) @@ -103,3 +106,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 53b634b4..bc1a4aa9 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 3e50070d..c6a6015f 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -129,6 +129,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