Adding Offer action

This commit is contained in:
Cayo Puigdefabregas 2021-03-19 11:53:04 +01:00
parent a66ddc8390
commit edf3700fde
4 changed files with 52 additions and 26 deletions

View File

@ -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'], ),

View File

@ -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:
@ -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),
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)
lot = db.Column(UUID(as_uuid=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):

View File

@ -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):

View File

@ -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