fixing schema offer

This commit is contained in:
Cayo Puigdefabregas 2021-04-03 17:47:30 +02:00
parent 1d6e0c9588
commit 84fac3f04a
3 changed files with 11 additions and 11 deletions

View file

@ -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):

View file

@ -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):

View file

@ -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()