drop remove
This commit is contained in:
parent
03238acb9f
commit
283f869b4d
|
@ -1583,11 +1583,11 @@ class Revoke(Confirm):
|
||||||
"""Users can revoke one confirmation of one action trade"""
|
"""Users can revoke one confirmation of one action trade"""
|
||||||
|
|
||||||
|
|
||||||
class ConfirmRevoke(Confirm):
|
# class ConfirmRevoke(Confirm):
|
||||||
"""Users can confirm and accept one action revoke"""
|
# """Users can confirm and accept one action revoke"""
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
# def __repr__(self) -> str:
|
||||||
return '<{0.t} {0.id} accepted by {0.user}>'.format(self)
|
# return '<{0.t} {0.id} accepted by {0.user}>'.format(self)
|
||||||
|
|
||||||
|
|
||||||
class Trade(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
class Trade(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
||||||
|
|
|
@ -219,8 +219,9 @@ class RevokeView(ConfirmMixin):
|
||||||
if not data['devices']:
|
if not data['devices']:
|
||||||
raise ValidationError('Devices not exist.')
|
raise ValidationError('Devices not exist.')
|
||||||
|
|
||||||
|
lot = data['action'].lot
|
||||||
for dev in data['devices']:
|
for dev in data['devices']:
|
||||||
if not dev.trading == 'TradeConfirmed':
|
if not dev.trading(lot) == 'TradeConfirmed':
|
||||||
txt = 'Some of devices do not have enough to confirm for to do a revoke'
|
txt = 'Some of devices do not have enough to confirm for to do a revoke'
|
||||||
ValidationError(txt)
|
ValidationError(txt)
|
||||||
### End check ###
|
### End check ###
|
||||||
|
|
|
@ -301,11 +301,66 @@ class Device(Thing):
|
||||||
|
|
||||||
return history
|
return history
|
||||||
|
|
||||||
@property
|
def trading(self, lot):
|
||||||
def trading(self):
|
|
||||||
"""The trading state, or None if no Trade action has
|
"""The trading state, or None if no Trade action has
|
||||||
ever been performed to this device. This extract the posibilities for to do"""
|
ever been performed to this device. This extract the posibilities for to do"""
|
||||||
|
if not hasattr(lot, 'trade'):
|
||||||
|
return
|
||||||
|
|
||||||
|
Status = {0: 'Trade',
|
||||||
|
1: 'Confirm',
|
||||||
|
2: 'TradeConfirmed',
|
||||||
|
3: 'Revoke',
|
||||||
|
4: 'RevokeConfirmed'}
|
||||||
|
|
||||||
|
trade = lot.trade
|
||||||
|
user_from = trade.user_from
|
||||||
|
user_to = trade.user_to
|
||||||
|
user_from_confirm = False
|
||||||
|
user_to_confirm = False
|
||||||
|
user_from_revoke = False
|
||||||
|
user_to_revoke = False
|
||||||
|
status = 0
|
||||||
|
confirms = {}
|
||||||
|
revokes = {}
|
||||||
|
# acceptances = copy.copy(trade.acceptances)
|
||||||
|
# acceptances = sorted(acceptances, key=lambda x: x.created)
|
||||||
|
|
||||||
|
if not hasattr(ac, 'acceptances'):
|
||||||
|
return Status[status]
|
||||||
|
|
||||||
|
for ac in trade.acceptances:
|
||||||
|
if ac.user not in [user_from, user_to]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if ac.t == 'Confirm':
|
||||||
|
if ac.user == user_from:
|
||||||
|
user_from_confirm = True
|
||||||
|
elif ac.user == user_to:
|
||||||
|
user_to_confirm = True
|
||||||
|
|
||||||
|
if ac.t == 'Revoke':
|
||||||
|
if ac.user == user_from:
|
||||||
|
user_from_revoke = True
|
||||||
|
elif ac.user == user_to:
|
||||||
|
user_to_revoke= True
|
||||||
|
|
||||||
|
confirms = [user_from_confirm, user_to_confirm]
|
||||||
|
revokes = [user_from_revoke, user_to_revoke]
|
||||||
|
|
||||||
|
if any(confirms):
|
||||||
|
status = 1
|
||||||
|
if all(confirms):
|
||||||
|
status = 2
|
||||||
|
|
||||||
|
if any(revokes):
|
||||||
|
status = 3
|
||||||
|
if all(revokes):
|
||||||
|
status = 4
|
||||||
|
|
||||||
|
def trading2(self):
|
||||||
|
"""The trading state, or None if no Trade action has
|
||||||
|
ever been performed to this device. This extract the posibilities for to do"""
|
||||||
# trade = 'Trade'
|
# trade = 'Trade'
|
||||||
confirm = 'Confirm'
|
confirm = 'Confirm'
|
||||||
need_confirm = 'NeedConfirmation'
|
need_confirm = 'NeedConfirmation'
|
||||||
|
|
|
@ -280,7 +280,7 @@ def delete_from_trade(lot: Lot, ids: Set[int]):
|
||||||
# then can be revoked and deleted of the lot
|
# then can be revoked and deleted of the lot
|
||||||
# Confirm of dev.trading mean that there are only one confirmation
|
# Confirm of dev.trading mean that there are only one confirmation
|
||||||
# and the first user than put this device in trade is the actual g.user
|
# and the first user than put this device in trade is the actual g.user
|
||||||
if dev.trading == 'Confirm':
|
if dev.trading(lot) == 'Confirm':
|
||||||
without_confirms.add(dev)
|
without_confirms.add(dev)
|
||||||
dev.reset_owner()
|
dev.reset_owner()
|
||||||
|
|
||||||
|
@ -293,12 +293,16 @@ def delete_from_trade(lot: Lot, ids: Set[int]):
|
||||||
without_confirms = devices
|
without_confirms = devices
|
||||||
|
|
||||||
if without_confirms:
|
if without_confirms:
|
||||||
confirm_revoke = ConfirmRevoke(
|
phantom = lot.trade.user_to
|
||||||
action=revoke,
|
if lot.trade.user_to == g.user:
|
||||||
user=g.user,
|
phantom = lot.trade.user_from
|
||||||
|
|
||||||
|
phantom_revoke = Revoke(
|
||||||
|
action=lot.trade,
|
||||||
|
user=phantom,
|
||||||
devices=without_confirms
|
devices=without_confirms
|
||||||
)
|
)
|
||||||
db.session.add(confirm_revoke)
|
db.session.add(phantom_revoke)
|
||||||
|
|
||||||
lot.devices.difference_update(without_confirms)
|
lot.devices.difference_update(without_confirms)
|
||||||
lot.trade.devices = lot.devices
|
lot.trade.devices = lot.devices
|
||||||
|
|
Reference in New Issue