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.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_from_id'], [f'common.user.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_to_id'], [f'common.user.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_from_id'], ['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'),
|
||||
schema=f'{get_inv()}'
|
||||
)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('offer', schema=f'{get_inv()}')
|
||||
op.drop_table('trade', schema=f'{get_inv()}')
|
||||
op.create_table('trade',
|
||||
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,
|
||||
comment='The id of the invoice so they can be linked.'),
|
||||
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('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.ForeignKeyConstraint(['confirms_id'], [f'{get_inv()}.organize.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.events import AttributeEvents as Events
|
||||
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)
|
||||
from teal.enums import Country, Currency, Subdivision
|
||||
from teal.marshmallow import ValidationError
|
||||
|
@ -48,6 +48,7 @@ from ereuse_devicehub.resources.enums import AppearanceRange, BatteryHealth, Bio
|
|||
TestDataStorageLength
|
||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
# from ereuse_devicehub.resources.lot.models import Lot
|
||||
|
||||
|
||||
class JoinedTableMixin:
|
||||
|
@ -142,7 +143,7 @@ class Action(Thing):
|
|||
order_by=lambda: Component.id,
|
||||
collection_class=OrderedSet)
|
||||
components.comment = """The components that are affected by the action.
|
||||
|
||||
|
||||
When performing actions to parent devices their components are
|
||||
affected too.
|
||||
|
||||
|
@ -159,7 +160,7 @@ class Action(Thing):
|
|||
primaryjoin=parent_id == Computer.id)
|
||||
parent_id.comment = """For actions that are performed to components,
|
||||
the device parent at that time.
|
||||
|
||||
|
||||
For example: for a ``EraseBasic`` performed on a data storage, this
|
||||
would point to the computer that contained this data storage, if any.
|
||||
"""
|
||||
|
@ -1367,7 +1368,7 @@ class Live(JoinedWithOneDeviceMixin, ActionWithOneDevice):
|
|||
self.actions.reverse()
|
||||
|
||||
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"""
|
||||
for e in self.actions:
|
||||
if isinstance(e, Live) and e.created < self.created:
|
||||
|
@ -1462,23 +1463,24 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices):
|
|||
date = Column(db.TIMESTAMP(timezone=True))
|
||||
|
||||
|
||||
class ActionTrade(Trade):
|
||||
class Offer(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.comment = """The id of one document like invoice so they can be linked."""
|
||||
accepted_by_from = Column(Boolean)
|
||||
accepted_by_to = Column(Boolean)
|
||||
trade = db.Column(UUID(as_uuid=True),
|
||||
db.ForeignKey(Trade.id),
|
||||
nullable=True)
|
||||
lot = db.Column(UUID(as_uuid=True),
|
||||
db.ForeignKey(Trade.id),
|
||||
nullable=True)
|
||||
accepted_by_from = Column(Boolean, default=False)
|
||||
accepted_by_from_common = """Who do the Offer"""
|
||||
accepted_by_to = Column(Boolean, default=False)
|
||||
confirm_transfer = Column(Boolean, default=False)
|
||||
accepted_by_to_common = """Who recive the Offer"""
|
||||
trade_id = db.Column(UUID(as_uuid=True),
|
||||
db.ForeignKey(Trade.id),
|
||||
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):
|
||||
|
|
|
@ -478,12 +478,13 @@ class Trade(ActionWithMultipleDevices):
|
|||
data['user_from_id'] = user_to.id
|
||||
|
||||
|
||||
class OfferTrade(ActionWithMultipleDevices):
|
||||
class Offer(Trade):
|
||||
__doc__ = m.Trade.__doc__
|
||||
date = DateTime(data_key='date', required=False)
|
||||
document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False)
|
||||
price = Float(required=False, data_key='price')
|
||||
user_to = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=True)
|
||||
accepted_by_from = Boolean(missing=True, description=m.Offer.accepted_by_from.comment)
|
||||
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):
|
||||
|
|
|
@ -33,6 +33,7 @@ class Trading(State):
|
|||
from the facility. It does not mean end-of-life.
|
||||
"""
|
||||
Reserved = e.Reserve
|
||||
Offer = e.Offer
|
||||
Cancelled = e.CancelTrade
|
||||
Sold = e.Sell
|
||||
Donated = e.Donate
|
||||
|
|
Reference in a new issue