From bc69d194f4040e0630095de88f7ca5d8b6b8ed48 Mon Sep 17 00:00:00 2001 From: yiorgos marinellis Date: Fri, 27 Mar 2020 11:48:16 +0100 Subject: [PATCH] Make supplier_id, receiver_id optional for ProofReuse, fixes #21 --- ereuse_devicehub/resources/proof/models.py | 8 +++++--- ereuse_devicehub/resources/proof/schemas.py | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/proof/models.py b/ereuse_devicehub/resources/proof/models.py index ed8bd798..2562b446 100644 --- a/ereuse_devicehub/resources/proof/models.py +++ b/ereuse_devicehub/resources/proof/models.py @@ -137,12 +137,14 @@ class ProofReuse(JoinedTableMixin, Proof): id_receipt = Column(CIText(), default='', nullable=False) supplier_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), - nullable=False, - default=lambda: g.user.id) + # nullable=False, + # default=lambda: g.user.id) + nullable=True) supplier = db.relationship(User, primaryjoin=lambda: ProofReuse.supplier_id == User.id) receiver_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), - nullable=False) + # nullable=False) + nullable=True) receiver = db.relationship(User, primaryjoin=lambda: ProofReuse.receiver_id == User.id) price = Column(db.Integer) diff --git a/ereuse_devicehub/resources/proof/schemas.py b/ereuse_devicehub/resources/proof/schemas.py index a07fc524..de18a41f 100644 --- a/ereuse_devicehub/resources/proof/schemas.py +++ b/ereuse_devicehub/resources/proof/schemas.py @@ -57,8 +57,8 @@ class ProofReuse(Proof): __doc__ = m.ProofReuse.__doc__ receiver_segment = String(default='', data_key='receiverSegment', required=True) id_receipt = String(default='', data_key='idReceipt', required=True) - supplier_id = UUID(load_only=True, required=True, data_key='supplierID') - receiver_id = UUID(load_only=True, required=True, data_key='receiverID') + supplier_id = UUID(load_only=True, required=False, data_key='supplierID') + receiver_id = UUID(load_only=True, required=False, data_key='receiverID') price = Integer(required=True)