drop tradeNotes

This commit is contained in:
Cayo Puigdefabregas 2021-04-29 11:25:17 +02:00
parent 4afa21d7d7
commit 76271ce430
3 changed files with 1 additions and 46 deletions

View File

@ -14,7 +14,7 @@ import citext
# revision identifiers, used by Alembic.
revision = '51439cf24be8'
down_revision = '8cb91ad1cc40'
down_revision = '8d34480c82c4'
branch_labels = None
depends_on = None
@ -80,16 +80,6 @@ def upgrade():
schema=f'{get_inv()}'
)
op.create_table('trade_note',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
sa.ForeignKeyConstraint(['trade_id'], [f'{get_inv()}.trade.id'], ),
sa.PrimaryKeyConstraint('id'),
schema=f'{get_inv()}'
)
# ## User
op.add_column('user', sa.Column('active', sa.Boolean(), default=True, nullable=True),
schema='common')
@ -104,7 +94,6 @@ def upgrade():
def downgrade():
op.drop_table('confirm', schema=f'{get_inv()}')
op.drop_table('trade_note', 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,

View File

@ -1433,18 +1433,6 @@ class CancelReservation(Organize):
"""The act of cancelling a reservation."""
class TradeNote(JoinedTableMixin, ActionWithMultipleDevices):
"""Note add to one trade"""
trade_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('trade.id'),
nullable=False)
trade = db.relationship('Trade',
backref=backref('notes',
uselist=True,
lazy=True),
primaryjoin='TradeNote.trade_id == Trade.id')
class Confirm(JoinedTableMixin, ActionWithMultipleDevices):
"""Users confirm the offer and change it to trade"""
user_id = db.Column(UUID(as_uuid=True),

View File

@ -15,7 +15,6 @@ from ereuse_devicehub.query import things_response
from ereuse_devicehub.resources.deliverynote.models import Deliverynote
from ereuse_devicehub.resources.device.models import Device, Computer
from ereuse_devicehub.resources.lot.models import Lot, Path
from ereuse_devicehub.resources.action.models import TradeNote
class LotFormat(Enum):
@ -225,32 +224,11 @@ class LotDeviceView(LotBaseChildrenView):
id = ma.fields.List(ma.fields.Integer())
def _post(self, lot: Lot, ids: Set[int]):
if lot.trade:
lot_device_ids = [d.id for d in lot.devices]
new_device_ids = {d for d in ids if not d in lot_device_ids}
devices = set(Device.query.filter(Device.id.in_(new_device_ids)).all())
txt = 'Adding new device in lot of trade {}'.format(lot.trade.id)
note = TradeNote(description=txt,
devices=devices,
trade=lot.trade)
db.session.add(note)
lot.devices.update(Device.query.filter(Device.id.in_(ids)))
if lot.trade:
lot.trade.devices = lot.devices
def _delete(self, lot: Lot, ids: Set[int]):
if lot.trade:
devices = set(Device.query.filter(Device.id.in_(ids)).all())
txt = 'Removing device from lot of trade {}'.format(lot.trade.id)
note = TradeNote(description=txt,
devices=devices,
trade=lot.trade)
db.session.add(note)
lot.devices.difference_update(Device.query.filter(Device.id.in_(ids)))
if lot.trade:
lot.trade.devices = lot.devices