Adding Offer action
This commit is contained in:
parent
a66ddc8390
commit
edf3700fde
|
@ -35,25 +35,47 @@ def upgrade():
|
||||||
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
|
||||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
sa.ForeignKeyConstraint(['user_from_id'], [f'common.user.id'], ),
|
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id'], ),
|
||||||
sa.ForeignKeyConstraint(['user_to_id'], [f'common.user.id'], ),
|
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id'),
|
||||||
|
schema=f'{get_inv()}'
|
||||||
|
)
|
||||||
|
|
||||||
|
op.create_table('offer',
|
||||||
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('document_id', citext.CIText(), nullable=True),
|
||||||
|
sa.Column('accepted_by_from', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('accepted_by_to', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('confirm_transfer', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
|
|
||||||
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.trade.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['trade_id'], [f'{get_inv()}.trade.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
schema=f'{get_inv()}'
|
schema=f'{get_inv()}'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
op.drop_table('offer', schema=f'{get_inv()}')
|
||||||
op.drop_table('trade', schema=f'{get_inv()}')
|
op.drop_table('trade', schema=f'{get_inv()}')
|
||||||
op.create_table('trade',
|
op.create_table('trade',
|
||||||
sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True,
|
sa.Column('shipping_date', sa.TIMESTAMP(timezone=True), nullable=True,
|
||||||
comment='When are the devices going to be ready \n for shipping?\n '),
|
comment='When are the devices going to be ready \n \
|
||||||
|
for shipping?\n '),
|
||||||
sa.Column('invoice_number', citext.CIText(), nullable=True,
|
sa.Column('invoice_number', citext.CIText(), nullable=True,
|
||||||
comment='The id of the invoice so they can be linked.'),
|
comment='The id of the invoice so they can be linked.'),
|
||||||
sa.Column('price_id', postgresql.UUID(as_uuid=True), nullable=True,
|
sa.Column('price_id', postgresql.UUID(as_uuid=True), nullable=True,
|
||||||
comment='The price set for this trade. \n If no price is set it is supposed that the trade was\n not payed, usual in donations.\n '),
|
comment='The price set for this trade. \n \
|
||||||
|
If no price is set it is supposed that the trade was\n \
|
||||||
|
not payed, usual in donations.\n '),
|
||||||
sa.Column('to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('to_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column('confirms_id', postgresql.UUID(as_uuid=True), nullable=True,
|
sa.Column('confirms_id', postgresql.UUID(as_uuid=True), nullable=True,
|
||||||
comment='An organize action that this association confirms. \n \n For example, a ``Sell`` or ``Rent``\n can confirm a ``Reserve`` action.\n '),
|
comment='An organize action that this association confirms. \
|
||||||
|
\n \n For example, a ``Sell`` or ``Rent``\n \
|
||||||
|
can confirm a ``Reserve`` action.\n '),
|
||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['confirms_id'], [f'{get_inv()}.organize.id'], ),
|
sa.ForeignKeyConstraint(['confirms_id'], [f'{get_inv()}.organize.id'], ),
|
||||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
|
|
|
@ -32,7 +32,7 @@ from sqlalchemy.ext.orderinglist import ordering_list
|
||||||
from sqlalchemy.orm import backref, relationship, validates
|
from sqlalchemy.orm import backref, relationship, validates
|
||||||
from sqlalchemy.orm.events import AttributeEvents as Events
|
from sqlalchemy.orm.events import AttributeEvents as Events
|
||||||
from sqlalchemy.util import OrderedSet
|
from sqlalchemy.util import OrderedSet
|
||||||
from teal.db import (CASCADE_OWN, INHERIT_COND, IP, POLYMORPHIC_ID,
|
from teal.db import (CASCADE_OWN, INHERIT_COND, IP, POLYMORPHIC_ID,
|
||||||
POLYMORPHIC_ON, StrictVersionType, URL, check_lower, check_range, ResourceNotFound)
|
POLYMORPHIC_ON, StrictVersionType, URL, check_lower, check_range, ResourceNotFound)
|
||||||
from teal.enums import Country, Currency, Subdivision
|
from teal.enums import Country, Currency, Subdivision
|
||||||
from teal.marshmallow import ValidationError
|
from teal.marshmallow import ValidationError
|
||||||
|
@ -48,6 +48,7 @@ from ereuse_devicehub.resources.enums import AppearanceRange, BatteryHealth, Bio
|
||||||
TestDataStorageLength
|
TestDataStorageLength
|
||||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
# from ereuse_devicehub.resources.lot.models import Lot
|
||||||
|
|
||||||
|
|
||||||
class JoinedTableMixin:
|
class JoinedTableMixin:
|
||||||
|
@ -142,7 +143,7 @@ class Action(Thing):
|
||||||
order_by=lambda: Component.id,
|
order_by=lambda: Component.id,
|
||||||
collection_class=OrderedSet)
|
collection_class=OrderedSet)
|
||||||
components.comment = """The components that are affected by the action.
|
components.comment = """The components that are affected by the action.
|
||||||
|
|
||||||
When performing actions to parent devices their components are
|
When performing actions to parent devices their components are
|
||||||
affected too.
|
affected too.
|
||||||
|
|
||||||
|
@ -159,7 +160,7 @@ class Action(Thing):
|
||||||
primaryjoin=parent_id == Computer.id)
|
primaryjoin=parent_id == Computer.id)
|
||||||
parent_id.comment = """For actions that are performed to components,
|
parent_id.comment = """For actions that are performed to components,
|
||||||
the device parent at that time.
|
the device parent at that time.
|
||||||
|
|
||||||
For example: for a ``EraseBasic`` performed on a data storage, this
|
For example: for a ``EraseBasic`` performed on a data storage, this
|
||||||
would point to the computer that contained this data storage, if any.
|
would point to the computer that contained this data storage, if any.
|
||||||
"""
|
"""
|
||||||
|
@ -1367,7 +1368,7 @@ class Live(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
||||||
self.actions.reverse()
|
self.actions.reverse()
|
||||||
|
|
||||||
def last_usage_time_allocate(self):
|
def last_usage_time_allocate(self):
|
||||||
"""If we don't have self.usage_time_hdd then we need search the last
|
"""If we don't have self.usage_time_hdd then we need search the last
|
||||||
action Live with usage_time_allocate valid"""
|
action Live with usage_time_allocate valid"""
|
||||||
for e in self.actions:
|
for e in self.actions:
|
||||||
if isinstance(e, Live) and e.created < self.created:
|
if isinstance(e, Live) and e.created < self.created:
|
||||||
|
@ -1462,23 +1463,24 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
date = Column(db.TIMESTAMP(timezone=True))
|
date = Column(db.TIMESTAMP(timezone=True))
|
||||||
|
|
||||||
|
|
||||||
class ActionTrade(Trade):
|
class Offer(Trade):
|
||||||
"""ActionTrade Offer one lot for to do one Trade.
|
"""ActionTrade Offer one lot for to do one Trade.
|
||||||
"""
|
"""
|
||||||
shipping_date = Column(db.TIMESTAMP(timezone=True))
|
|
||||||
shipping_date.comment = """When are the devices going to be ready
|
|
||||||
for shipping?
|
|
||||||
"""
|
|
||||||
document_id = Column(CIText())
|
document_id = Column(CIText())
|
||||||
document_id.comment = """The id of one document like invoice so they can be linked."""
|
document_id.comment = """The id of one document like invoice so they can be linked."""
|
||||||
accepted_by_from = Column(Boolean)
|
accepted_by_from = Column(Boolean, default=False)
|
||||||
accepted_by_to = Column(Boolean)
|
accepted_by_from_common = """Who do the Offer"""
|
||||||
trade = db.Column(UUID(as_uuid=True),
|
accepted_by_to = Column(Boolean, default=False)
|
||||||
db.ForeignKey(Trade.id),
|
confirm_transfer = Column(Boolean, default=False)
|
||||||
nullable=True)
|
accepted_by_to_common = """Who recive the Offer"""
|
||||||
lot = db.Column(UUID(as_uuid=True),
|
trade_id = db.Column(UUID(as_uuid=True),
|
||||||
db.ForeignKey(Trade.id),
|
db.ForeignKey(Trade.id),
|
||||||
nullable=True)
|
nullable=True)
|
||||||
|
trade = db.relationship(Trade, primaryjoin=trade_id == Trade.id)
|
||||||
|
lot_id = db.Column(UUID(as_uuid=True),
|
||||||
|
db.ForeignKey(Trade.id),
|
||||||
|
nullable=True)
|
||||||
|
# lot = db.relationship(Lot, primaryjoin=lot_id == Lot.id)
|
||||||
|
|
||||||
|
|
||||||
class InitTransfer(Trade):
|
class InitTransfer(Trade):
|
||||||
|
|
|
@ -478,12 +478,13 @@ class Trade(ActionWithMultipleDevices):
|
||||||
data['user_from_id'] = user_to.id
|
data['user_from_id'] = user_to.id
|
||||||
|
|
||||||
|
|
||||||
class OfferTrade(ActionWithMultipleDevices):
|
class Offer(Trade):
|
||||||
__doc__ = m.Trade.__doc__
|
__doc__ = m.Trade.__doc__
|
||||||
date = DateTime(data_key='date', required=False)
|
|
||||||
document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False)
|
document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False)
|
||||||
price = Float(required=False, data_key='price')
|
accepted_by_from = Boolean(missing=True, description=m.Offer.accepted_by_from.comment)
|
||||||
user_to = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=True)
|
accepted_by_to = Boolean(missing=True, description=m.Offer.accepted_by_to.comment)
|
||||||
|
lot = NestedOn('Lot', dump_only=True)
|
||||||
|
trade = NestedOn('Trade', dump_only=True)
|
||||||
|
|
||||||
|
|
||||||
class InitTransfer(Trade):
|
class InitTransfer(Trade):
|
||||||
|
|
|
@ -33,6 +33,7 @@ class Trading(State):
|
||||||
from the facility. It does not mean end-of-life.
|
from the facility. It does not mean end-of-life.
|
||||||
"""
|
"""
|
||||||
Reserved = e.Reserve
|
Reserved = e.Reserve
|
||||||
|
Offer = e.Offer
|
||||||
Cancelled = e.CancelTrade
|
Cancelled = e.CancelTrade
|
||||||
Sold = e.Sell
|
Sold = e.Sell
|
||||||
Donated = e.Donate
|
Donated = e.Donate
|
||||||
|
|
Reference in New Issue