adding trade in status actions

This commit is contained in:
Cayo Puigdefabregas 2021-11-05 12:35:10 +01:00
parent 56df40c81a
commit 5ebf4f48b5
4 changed files with 31 additions and 2 deletions

View File

@ -49,8 +49,21 @@ def upgrade():
nullable=False, comment='When Devicehub created this.'), nullable=False, comment='When Devicehub created this.'),
schema=f'{get_inv()}') schema=f'{get_inv()}')
op.add_column('action_status',
sa.Column('trade_id', postgresql.UUID(as_uuid=True), nullable=True),
schema=f'{get_inv()}')
op.create_foreign_key("fk_action_status_trade",
"action_status", "trade",
["trade_id"], ["id"],
ondelete="SET NULL",
source_schema=f'{get_inv()}',
referent_schema=f'{get_inv()}')
upgrade_data() upgrade_data()
def downgrade(): def downgrade():
op.drop_constraint("fk_action_status_trade", "action_status", type_="foreignkey", schema=f'{get_inv()}')
op.drop_column('action_device', 'created', schema=f'{get_inv()}') op.drop_column('action_device', 'created', schema=f'{get_inv()}')
op.drop_column('action_status', 'trade_id', schema=f'{get_inv()}')

View File

@ -1377,6 +1377,16 @@ class ActionStatus(JoinedTableMixin, ActionWithMultipleTradeDocuments):
default=lambda: g.user.id) default=lambda: g.user.id)
rol_user = db.relationship(User, primaryjoin=rol_user_id == User.id) rol_user = db.relationship(User, primaryjoin=rol_user_id == User.id)
rol_user_comment = """The user that .""" rol_user_comment = """The user that ."""
trade_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('trade.id'),
nullable=True)
trade = db.relationship('Trade',
backref=backref('status_changes',
uselist=True,
lazy=True,
order_by=lambda: Action.end_time,
collection_class=list),
primaryjoin='ActionStatus.trade_id == Trade.id')
class Recycling(ActionStatus): class Recycling(ActionStatus):

View File

@ -450,6 +450,7 @@ class ActionStatus(Action):
trade = [ac for ac in dev.actions if ac.t == 'Trade'][-1] trade = [ac for ac in dev.actions if ac.t == 'Trade'][-1]
if trade.user_to != g.user: if trade.user_to != g.user:
data['rol_user'] = trade.user_to data['rol_user'] = trade.user_to
data['trade'] = trade
class Recycling(ActionStatus): class Recycling(ActionStatus):

View File

@ -77,7 +77,6 @@ class Metrics(MetricsMix):
self.rows.append(row) self.rows.append(row)
return return
# import pdb; pdb.set_trace()
if self.last_trade['trade_supplier'] == self.act.author.email: if self.last_trade['trade_supplier'] == self.act.author.email:
self.last_trade['status_supplier'] = self.act.type self.last_trade['status_supplier'] = self.act.type
self.last_trade['status_supplier_created'] = self.act.created self.last_trade['status_supplier_created'] = self.act.created
@ -88,6 +87,10 @@ class Metrics(MetricsMix):
self.last_trade['status_receiver_created'] = self.act.created self.last_trade['status_receiver_created'] = self.act.created
return return
# import pdb; pdb.set_trace()
# necesitamos poder poner un cambio de estado de un trade mas antiguo que last_trade
# lo mismo con confirm
def get_snapshot(self): def get_snapshot(self):
""" """
If there are one snapshot get the last lifetime for to do a calcul of time of use. If there are one snapshot get the last lifetime for to do a calcul of time of use.
@ -164,7 +167,9 @@ class Metrics(MetricsMix):
row['status_receiver'] = self.status_receiver row['status_receiver'] = self.status_receiver
row['status_supplier'] = '' row['status_supplier'] = ''
row['trade_confirmed'] = self.get_confirms() row['trade_confirmed'] = self.get_confirms()
self.trades[self.act.created] = row # import pdb; pdb.set_trace()
created = self.act.actions_device[0].created
self.trades[created] = row
self.rows.append(row) self.rows.append(row)
def get_metrics(self): def get_metrics(self):