diff --git a/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py b/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py index f6c2b57d..c1b4b284 100644 --- a/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py +++ b/ereuse_devicehub/migrations/versions/51439cf24be8_change_trade_action.py @@ -26,32 +26,13 @@ def get_inv(): return INV def upgrade(): - user_from_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False, - default=lambda: g.user.id) - user_from = db.relationship(User, primaryjoin=user_from_id == User.id) - user_from_comment = """The user that offers the device due this deal.""" - user_to_id = db.Column(UUID(as_uuid=True), - db.ForeignKey(User.id), - nullable=False, - default=lambda: g.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.""" - price = Column(Float(decimal_return_scale=2), nullable=True) - date = Column(db.TIMESTAMP(timezone=True)) - user_to_string = Column(CIText()) - user_from_string = Column(CIText()) -++++ - + op.drop_table('trade', schema=f'{get_inv()}') op.create_table('trade', sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True), - sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('user_from_string', citext.CIText(), nullable=True), - sa.Column('user_to_string', citext.CIText(), nullable=True), sa.Column('price', sa.Float(decimal_return_scale=4), nullable=True), + 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.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ), sa.ForeignKeyConstraint(['from_id'], [f'common.user.id'], ), @@ -62,4 +43,4 @@ def upgrade(): def downgrade(): - pass + op.drop_table('trade', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 704df56c..f90c7e52 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1452,16 +1452,12 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices): default=lambda: g.user.id) user_from = db.relationship(User, primaryjoin=user_from_id == User.id) user_from_comment = """The user that offers the device due this deal.""" - user_from_string = Column(CIText()) - user_from_string_comment = """The user outsite of devicehub that offers the device.""" user_to_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False, default=lambda: g.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_string = Column(CIText()) - user_to_string_comment = """The user outsite of devicehub that offers the device.""" price = Column(Float(decimal_return_scale=2), nullable=True) date = Column(db.TIMESTAMP(timezone=True)) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index d80dc3cf..ee92d840 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -460,7 +460,7 @@ class Trade(ActionWithMultipleDevices): shipping_date = DateTime(data_key='shippingDate') invoice_number = SanitizedStr(validate=Length(max=STR_SIZE), data_key='invoiceNumber') price = NestedOn(Price) - to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.to_comment) + to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.user_to_comment) confirms = NestedOn(Organize)