rent with assigned concept

This commit is contained in:
Cayo Puigdefabregas 2020-11-17 19:21:32 +01:00
parent e0b338b414
commit 69368a8ca3
2 changed files with 27 additions and 11 deletions

View File

@ -460,8 +460,12 @@ class Transferred(ActionWithMultipleDevices):
class Assigned(ActionWithMultipleDevices):
__doc__ = m.Assigned.__doc__
shipping_date = DateTime(data_key='shippingDate')
invoice_number = SanitizedStr(validate=Length(max=STR_SIZE), data_key='invoiceNumber')
price = NestedOn(Price)
to = NestedOn(s_agent.Agent, only_query='id', required=True, comment=m.Trade.to_comment)
confirms = NestedOn(Organize)
agent = NestedOn(s_agent.Agent, only_query='id', required=False, comment=m.Trade.to_comment)
description = SanitizedStr(default='', description=m.Action.description.comment)
start_time = DateTime(data_key='startTime', description=m.Action.start_time.comment)
end_time = DateTime(data_key='endTime', description=m.Action.end_time.comment)
assigned = SanitizedStr(validate=Length(min=1, max=STR_BIG_SIZE),
required=False,
description='The code of the agent to assigned.')
n_beneficiaries = Integer(validate=[Range(min=1, error="Value must be greater than 0")],
required=True)

View File

@ -1,25 +1,34 @@
import uuid
# from typing import Callable, Iterable, Tuple
# from flask import g
from flask import g, request
# from flask.json import jsonify
from teal.resource import View
from ereuse_devicehub import auth
from ereuse_devicehub.db import db
from ereuse_devicehub.query import things_response
from ereuse_devicehub.resources.action.models import Assigned
class RentingView(View):
@auth.Auth.requires_auth
def get(self, id):
def get(self, id: uuid.UUID) -> Assigned:
return super().get(id)
@auth.Auth.requires_auth
def post(self):
""" Create one rent """
return super().get(id)
# return jsonify('ok')
res_json = request.get_json()
assigned = Assigned(**res_json)
db.session.add(assigned)
db.session().final_flush()
ret = self.schema.jsonify(assigned)
ret.status_code = 201
db.session.commit()
return ret
def find(self, args: dict):
rents = Assigned.query.filter() \
rents = Assigned.query.filter_by(author=g.user) \
.order_by(Assigned.created.desc()) \
.paginate(per_page=200)
return things_response(
@ -27,4 +36,7 @@ class RentingView(View):
rents.page, rents.per_page, rents.total, rents.prev_num, rents.next_num
)
def one(self, id: uuid.UUID):
"""Gets one action."""
assigned = Assigned.query.filter_by(id=id, author=g.user).one()
return self.schema.jsonify(assigned, nested=2)