add change in Lot and Actions views
This commit is contained in:
parent
225e018cdc
commit
8389ffeb54
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__,
|
||||
|
|
|
@ -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
|
||||
|
|
Reference in New Issue