change offer-trade for 2192 aproach
This commit is contained in:
parent
e884ced4d1
commit
47dd5b24d8
|
@ -27,32 +27,45 @@ def get_inv():
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.drop_table('trade', schema=f'{get_inv()}')
|
op.drop_table('trade', schema=f'{get_inv()}')
|
||||||
op.create_table('trade',
|
op.create_table('offer',
|
||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
|
||||||
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
|
sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True),
|
||||||
|
sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||||
|
sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True),
|
||||||
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=False),
|
sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||||
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.Column('document_id', citext.CIText(), nullable=True),
|
||||||
|
sa.Column('currency',
|
||||||
|
sa.Enum('AFN', 'ARS', 'AWG', 'AUD', 'AZN', 'BSD', 'BBD', 'BDT', 'BYR', 'BZD', 'BMD',
|
||||||
|
'BOB', 'BAM', 'BWP', 'BGN', 'BRL', 'BND', 'KHR', 'CAD', 'KYD', 'CLP', 'CNY',
|
||||||
|
'COP', 'CRC', 'HRK', 'CUP', 'CZK', 'DKK', 'DOP', 'XCD', 'EGP', 'SVC', 'EEK',
|
||||||
|
'EUR', 'FKP', 'FJD', 'GHC', 'GIP', 'GTQ', 'GGP', 'GYD', 'HNL', 'HKD', 'HUF',
|
||||||
|
'ISK', 'INR', 'IDR', 'IRR', 'IMP', 'ILS', 'JMD', 'JPY', 'JEP', 'KZT', 'KPW',
|
||||||
|
'KRW', 'KGS', 'LAK', 'LVL', 'LBP', 'LRD', 'LTL', 'MKD', 'MYR', 'MUR', 'MXN',
|
||||||
|
'MNT', 'MZN', 'NAD', 'NPR', 'ANG', 'NZD', 'NIO', 'NGN', 'NOK', 'OMR', 'PKR',
|
||||||
|
'PAB', 'PYG', 'PEN', 'PHP', 'PLN', 'QAR', 'RON', 'RUB', 'SHP', 'SAR', 'RSD',
|
||||||
|
'SCR', 'SGD', 'SBD', 'SOS', 'ZAR', 'LKR', 'SEK', 'CHF', 'SRD', 'SYP', 'TWD',
|
||||||
|
'THB', 'TTD', 'TRY', 'TRL', 'TVD', 'UAH', 'GBP', 'USD', 'UYU', 'UZS', 'VEF',
|
||||||
|
'VND', 'YER', 'ZWD', name='currency'), nullable=False,
|
||||||
|
comment='The currency of this price as for ISO 4217.'),
|
||||||
|
|
||||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.trade.id'], ),
|
||||||
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id'], ),
|
sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id'], ),
|
||||||
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id'], ),
|
sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id'], ),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
schema=f'{get_inv()}'
|
schema=f'{get_inv()}'
|
||||||
)
|
)
|
||||||
|
|
||||||
op.create_table('offer',
|
op.create_table('trade',
|
||||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
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_from', sa.Boolean(), nullable=False),
|
||||||
sa.Column('accepted_by_to', sa.Boolean(), nullable=False),
|
sa.Column('accepted_by_to', sa.Boolean(), nullable=False),
|
||||||
sa.Column('confirm_transfer', 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('offer_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(['id'], [f'{get_inv()}.action.id'], ),
|
||||||
sa.ForeignKeyConstraint(['trade_id'], [f'{get_inv()}.trade.id'], ),
|
sa.ForeignKeyConstraint(['offer_id'], [f'{get_inv()}.offer.id'], ),
|
||||||
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id'], ),
|
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
schema=f'{get_inv()}'
|
schema=f'{get_inv()}'
|
||||||
)
|
)
|
||||||
|
|
|
@ -1446,28 +1446,25 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
This class and its inheritors
|
This class and its inheritors
|
||||||
extend `Schema's Trade <http://schema.org/TradeAction>`_.
|
extend `Schema's Trade <http://schema.org/TradeAction>`_.
|
||||||
"""
|
"""
|
||||||
user_from_id = db.Column(UUID(as_uuid=True),
|
accepted_by_from = Column(Boolean, default=False)
|
||||||
db.ForeignKey(User.id),
|
accepted_by_from_comment = """Who do the Offer"""
|
||||||
nullable=False,
|
accepted_by_to = Column(Boolean, default=False)
|
||||||
default=lambda: g.user.id)
|
accepted_by_to_comment = """Who recive the Offer"""
|
||||||
user_from = db.relationship(User, primaryjoin=user_from_id == User.id)
|
confirm_transfer = Column(Boolean, default=False)
|
||||||
user_from_comment = """The user that offers the device due this deal."""
|
confirm_transfer_comment = """Transfer of the phisical devices it is confirmed"""
|
||||||
user_to_id = db.Column(UUID(as_uuid=True),
|
offer_id = db.Column(UUID(as_uuid=True),
|
||||||
db.ForeignKey(User.id),
|
db.ForeignKey('offer.id',
|
||||||
nullable=False,
|
user_alter=True,
|
||||||
default=lambda: g.user.id)
|
name='trade_offer'),
|
||||||
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
|
nullable=True)
|
||||||
user_to_comment = """The user that gets the device due this deal."""
|
offer = db.relationship('offer',
|
||||||
price = Column(Float(decimal_return_scale=2), nullable=True)
|
backref=db.backref('trade', uselist=False, lazy=True),
|
||||||
date = Column(db.TIMESTAMP(timezone=True))
|
primaryjoin='Trade.id == Offer.trade_id')
|
||||||
# offer = relationship("Offer", uselist=False, back_populates="Trade")
|
|
||||||
|
|
||||||
|
|
||||||
# class Offer(Trade):
|
|
||||||
class Offer(JoinedTableMixin, ActionWithMultipleDevices):
|
class Offer(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
"""ActionTrade Offer one lot for to do one Trade.
|
"""ActionTrade Offer one lot for to do one Trade.
|
||||||
"""
|
"""
|
||||||
# from ereuse_devicehub.resources.lot.models import Lot
|
|
||||||
user_from_id = db.Column(UUID(as_uuid=True),
|
user_from_id = db.Column(UUID(as_uuid=True),
|
||||||
db.ForeignKey(User.id),
|
db.ForeignKey(User.id),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
|
@ -1481,29 +1478,22 @@ class Offer(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
|
user_to = db.relationship(User, primaryjoin=user_to_id == User.id)
|
||||||
user_to_comment = """The user that gets the device due this deal."""
|
user_to_comment = """The user that gets the device due this deal."""
|
||||||
price = Column(Float(decimal_return_scale=2), nullable=True)
|
price = Column(Float(decimal_return_scale=2), nullable=True)
|
||||||
|
currency = Column(DBEnum(Currency), nullable=False, default='EUR')
|
||||||
|
currency.comment = """The currency of this price as for ISO 4217."""
|
||||||
date = Column(db.TIMESTAMP(timezone=True))
|
date = Column(db.TIMESTAMP(timezone=True))
|
||||||
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, 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),
|
lot_id = db.Column(UUID(as_uuid=True),
|
||||||
db.ForeignKey('information_schema.lot.id'),
|
db.ForeignKey('lot.id',
|
||||||
|
use_alter=True,
|
||||||
|
name='lot_offer'),
|
||||||
nullable=True)
|
nullable=True)
|
||||||
# lot = relationship("Lot", back_populates="offer")
|
lot = relationship('Lot',
|
||||||
# lot = db.relationship('Lot', primaryjoin='lot_id' == 'Lot.id')
|
backref=backref('offer',
|
||||||
# lot = relationship('Lot',
|
lazy=True,
|
||||||
# backref=backref('lot_one',
|
uselist=False,
|
||||||
# lazy=True,
|
cascade=CASCADE_OWN),
|
||||||
# cascade=CASCADE_OWN,
|
primaryjoin='Offer.lot_id == Lot.id')
|
||||||
# **_sorted_actions),
|
|
||||||
# primaryjoin=lot_id == 'Lot.id')
|
|
||||||
|
|
||||||
|
|
||||||
class InitTransfer(Trade):
|
class InitTransfer(Trade):
|
||||||
|
|
|
@ -458,10 +458,20 @@ class CancelReservation(Organize):
|
||||||
|
|
||||||
class Trade(ActionWithMultipleDevices):
|
class Trade(ActionWithMultipleDevices):
|
||||||
__doc__ = m.Trade.__doc__
|
__doc__ = m.Trade.__doc__
|
||||||
|
accepted_by_from = Boolean(missing=False, description=m.Offer.accepted_by_from.comment)
|
||||||
|
accepted_by_to = Boolean(missing=False, description=m.Offer.accepted_by_to.comment)
|
||||||
|
confirm_transfer = Boolean(missing=False, description=m.Offer.confirm_transfer.comment)
|
||||||
|
offer = NestedOn('Offer', dump_only=True)
|
||||||
|
|
||||||
|
|
||||||
|
class Offer(Trade):
|
||||||
|
__doc__ = m.Trade.__doc__
|
||||||
|
document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False)
|
||||||
date = DateTime(data_key='date', required=False)
|
date = DateTime(data_key='date', required=False)
|
||||||
price = Float(required=False, data_key='price')
|
price = Float(required=False, data_key='price')
|
||||||
user_to_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False)
|
user_to_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False)
|
||||||
user_from_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False)
|
user_from_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False)
|
||||||
|
lot = NestedOn('Lot', dump_only=True)
|
||||||
|
|
||||||
@validates_schema
|
@validates_schema
|
||||||
def validate_user_to_id(self, data: dict):
|
def validate_user_to_id(self, data: dict):
|
||||||
|
@ -481,18 +491,6 @@ class Trade(ActionWithMultipleDevices):
|
||||||
data['user_from_id'] = user_to.id
|
data['user_from_id'] = user_to.id
|
||||||
|
|
||||||
|
|
||||||
class Offer(Trade):
|
|
||||||
__doc__ = m.Trade.__doc__
|
|
||||||
document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False)
|
|
||||||
accepted_by_from = Boolean(missing=False, description=m.Offer.accepted_by_from.comment)
|
|
||||||
accepted_by_to = Boolean(missing=False, description=m.Offer.accepted_by_to.comment)
|
|
||||||
lot = NestedOn('Lot', dump_only=True)
|
|
||||||
trade = NestedOn('Trade', dump_only=True)
|
|
||||||
# lot = NestedOn('Lot',
|
|
||||||
# many=False,
|
|
||||||
# required=True,
|
|
||||||
# only_query='id')
|
|
||||||
|
|
||||||
|
|
||||||
class InitTransfer(Trade):
|
class InitTransfer(Trade):
|
||||||
__doc__ = m.InitTransfer.__doc__
|
__doc__ = m.InitTransfer.__doc__
|
||||||
|
|
Reference in New Issue