new version of rent as asigned

This commit is contained in:
Cayo Puigdefabregas 2020-11-17 13:19:50 +01:00
parent 8acca4d2cf
commit 820e253a12
5 changed files with 50 additions and 30 deletions

View File

@ -1472,6 +1472,14 @@ class MigrateFrom(Migrate):
pass
class Assigned(JoinedTableMixin, ActionWithMultipleDevices):
"""The act of assigned one list of devices to one person of the system or not
"""
assigned = Column(CIText(), default='', nullable=True)
assigned.comment = """ This is a internal code for mainteing the secrets of the personal datas of the new holder """
n_beneficiaries = Column(Numeric(precision=4), check_range('n_beneficiaries', 0), nullable=False)
# Listeners
# Listeners validate values and keep relationships synced

View File

@ -457,3 +457,11 @@ class MigrateFrom(Migrate):
class Transferred(ActionWithMultipleDevices):
__doc__ = m.Transferred.__doc__
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)

View File

@ -1,34 +1,8 @@
from typing import Callable, Iterable, Tuple
from flask import g
from flask.json import jsonify
from ereuse_devicehub.resources import action as act
from ereuse_devicehub.resources.action.models import Rent
from ereuse_devicehub.resources.device.models import Device
from teal.resource import Converters, Resource, View
from ereuse_devicehub import auth
from ereuse_devicehub.query import things_response
class RentingView(View):
@auth.Auth.requires_auth
def get(self, id):
return super().get(id)
@auth.Auth.requires_auth
def post(self):
""" Create one rent """
return jsonify('ok')
def find(self, args: dict):
rents = Rent.query.filter() \
.order_by(Rent.created.desc()) \
.paginate(per_page=200)
return things_response(
self.schema.dump(rents.items, many=True, nested=0),
rents.page, rents.per_page, rents.total, rents.prev_num, rents.next_num
)
from ereuse_devicehub.resources.action import schemas
from teal.resource import Resource
from ereuse_devicehub.resources.rent.views import RentingView
class RentDef(Resource):
VIEW = RentingView
SCHEMA = act.schemas.Rent
SCHEMA = schemas.Assigned

View File

@ -0,0 +1,30 @@
# from typing import Callable, Iterable, Tuple
# from flask import g
# from flask.json import jsonify
from teal.resource import View
from ereuse_devicehub import auth
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):
return super().get(id)
@auth.Auth.requires_auth
def post(self):
""" Create one rent """
return super().get(id)
# return jsonify('ok')
def find(self, args: dict):
rents = Assigned.query.filter() \
.order_by(Assigned.created.desc()) \
.paginate(per_page=200)
return things_response(
self.schema.dump(rents.items, many=True, nested=0),
rents.page, rents.per_page, rents.total, rents.prev_num, rents.next_num
)