From 84fac3f04a791227d17f5d04447f6bde2b13c0eb Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 3 Apr 2021 17:47:30 +0200 Subject: [PATCH] fixing schema offer --- ereuse_devicehub/resources/action/models.py | 8 +++----- ereuse_devicehub/resources/action/schemas.py | 10 +++++++--- ereuse_devicehub/resources/action/views.py | 4 +--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 4f386813..a71dd7a2 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1453,13 +1453,11 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices): confirm_transfer = Column(Boolean, default=False) confirm_transfer_comment = """Transfer of the phisical devices it is confirmed""" offer_id = db.Column(UUID(as_uuid=True), - db.ForeignKey('offer.id', - user_alter=True, - name='trade_offer'), + db.ForeignKey('offer.id'), nullable=True) - offer = db.relationship('offer', + offer = db.relationship('Offer', backref=db.backref('trade', uselist=False, lazy=True), - primaryjoin='Trade.id == Offer.trade_id') + primaryjoin='Trade.offer_id == Offer.id') class Offer(JoinedTableMixin, ActionWithMultipleDevices): diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 748c8ecd..9e42438b 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -464,14 +464,18 @@ class Trade(ActionWithMultipleDevices): offer = NestedOn('Offer', dump_only=True) -class Offer(Trade): - __doc__ = m.Trade.__doc__ +class Offer(ActionWithMultipleDevices): + __doc__ = m.Offer.__doc__ document_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='documentID', required=False) date = DateTime(data_key='date', required=False) price = Float(required=False, data_key='price') user_to_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False) user_from_id = SanitizedStr(validate=Length(max=STR_SIZE), data_key='userTo', required=False) - lot = NestedOn('Lot', dump_only=True) + # lot = NestedOn('Lot', dump_only=True) + lot = NestedOn('Lot', + many=False, + required=True, # todo test ensuring len(devices) >= 1 + only_query='id') @validates_schema def validate_user_to_id(self, data: dict): diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index bb74493a..ce6446ed 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -251,11 +251,9 @@ class ActionView(View): # TODO JN add compute rate with new visual test and old components device if json['type'] == InitTransfer.t: return self.transfer_ownership() + # import pdb; pdb.set_trace() a = resource_def.schema.load(json) Model = db.Model._decl_class_registry.data[json['type']]() - import pdb; pdb.set_trace() - # a['lot_id'] = a['lot'].id - # a.pop('lot') action = Model(**a) db.session.add(action) db.session().final_flush()