fixing model confirm

This commit is contained in:
Cayo Puigdefabregas 2021-04-22 11:11:23 +02:00
parent 2557cee84a
commit 865c9d5d07
1 changed files with 16 additions and 10 deletions

View File

@ -1447,25 +1447,31 @@ class TradeNote(JoinedTableMixin, ActionWithMultipleDevices):
class Confirm(JoinedTableMixin, ActionWithMultipleDevices): class Confirm(JoinedTableMixin, ActionWithMultipleDevices):
"""Users confirm the offer and change it to trade""" """Users confirm the offer and change it to trade"""
revoke = Column(Boolean, default=False, nullable=False)
revoke.comment = """Used for revoke and other confirm"""
user_id = db.Column(UUID(as_uuid=True), user_id = db.Column(UUID(as_uuid=True),
db.ForeignKey(User.id), db.ForeignKey(User.id),
nullable=False) nullable=False,
default=lambda: g.user.id)
user = db.relationship(User, primaryjoin=user_id == User.id) user = db.relationship(User, primaryjoin=user_id == User.id)
user_comment = """The user that accept the offer.""" user_comment = """The user that accept the offer."""
trade_id = db.Column(UUID(as_uuid=True), action_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('trade.id'), db.ForeignKey('action.id'),
nullable=False) nullable=False)
trade = db.relationship('Trade', action = db.relationship('Action',
backref=backref('acceptances', backref=backref('acceptances',
uselist=True, uselist=True,
lazy=True), lazy=True),
primaryjoin='Confirm.trade_id == Trade.id') primaryjoin='Confirm.action_id == Action.id')
def __repr__(self) -> str: def __repr__(self) -> str:
if self.action.t in ['Offer', 'Trade']:
origin = 'To' origin = 'To'
if self.user == self.trade.user_from: if self.user == self.action.user_from:
origin = 'From' origin = 'From'
return '<{0.t} {0.id} accepted by {1}>'.format(self, origin) return '<{0.t} {0.id} accepted by {1}>'.format(self, origin)
if self.action == 'Confirm':
return '<{0.t} {0.id} Revoke Confirm {0.action.id}>'.format(self)
class Trade(JoinedTableMixin, ActionWithMultipleDevices): class Trade(JoinedTableMixin, ActionWithMultipleDevices):