fix bug #2841. Show lot and devices for all users involved in a trade
This commit is contained in:
parent
1e9b65e0b5
commit
6389956adc
|
@ -31,6 +31,8 @@ from ereuse_devicehub.resources.tag.model import Tag
|
||||||
from ereuse_devicehub.resources.tradedocument.models import TradeDocument
|
from ereuse_devicehub.resources.tradedocument.models import TradeDocument
|
||||||
from ereuse_devicehub.resources.user.exceptions import InsufficientPermission
|
from ereuse_devicehub.resources.user.exceptions import InsufficientPermission
|
||||||
from ereuse_devicehub.resources.user.models import User
|
from ereuse_devicehub.resources.user.models import User
|
||||||
|
from ereuse_devicehub.resources.action.models import Trade
|
||||||
|
from sqlalchemy import or_
|
||||||
|
|
||||||
|
|
||||||
class LotDeviceForm(FlaskForm):
|
class LotDeviceForm(FlaskForm):
|
||||||
|
@ -718,9 +720,14 @@ class TradeForm(NewActionForm):
|
||||||
self.user_from.render_kw['data-email'] = g.user.email
|
self.user_from.render_kw['data-email'] = g.user.email
|
||||||
self.user_to.render_kw['data-email'] = g.user.email
|
self.user_to.render_kw['data-email'] = g.user.email
|
||||||
self._lot = (
|
self._lot = (
|
||||||
Lot.query.filter(Lot.id == self.lot.data)
|
# Lot.query.filter(Lot.id == self.lot.data)
|
||||||
.filter(Lot.owner_id == g.user.id)
|
# .filter(Lot.owner_id == g.user.id)
|
||||||
.one()
|
# .one()
|
||||||
|
Lot.query.outerjoin(Trade)
|
||||||
|
.filter(Lot.id == self.lot.data)
|
||||||
|
.filter(or_(Trade.user_from == g.user,
|
||||||
|
Trade.user_to == g.user,
|
||||||
|
Lot.owner_id == g.user.id)).one()
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
|
|
|
@ -7,6 +7,7 @@ from flask import Blueprint, g, make_response, request, url_for
|
||||||
from flask.views import View
|
from flask.views import View
|
||||||
from flask_login import current_user, login_required
|
from flask_login import current_user, login_required
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
|
from sqlalchemy import or_
|
||||||
|
|
||||||
from ereuse_devicehub import messages
|
from ereuse_devicehub import messages
|
||||||
from ereuse_devicehub.inventory.forms import (
|
from ereuse_devicehub.inventory.forms import (
|
||||||
|
@ -42,7 +43,10 @@ class DeviceListMix(View):
|
||||||
# TODO @cayop adding filter
|
# TODO @cayop adding filter
|
||||||
# https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56
|
# https://github.com/eReuse/devicehub-teal/blob/testing/ereuse_devicehub/resources/device/views.py#L56
|
||||||
filter_types = ['Desktop', 'Laptop', 'Server']
|
filter_types = ['Desktop', 'Laptop', 'Server']
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.outerjoin(Trade) \
|
||||||
|
.filter(or_(Trade.user_from == g.user,
|
||||||
|
Trade.user_to == g.user,
|
||||||
|
Lot.owner_id == g.user.id)).distinct()
|
||||||
lot = None
|
lot = None
|
||||||
tags = (
|
tags = (
|
||||||
Tag.query.filter(Tag.owner_id == current_user.id)
|
Tag.query.filter(Tag.owner_id == current_user.id)
|
||||||
|
@ -51,6 +55,7 @@ class DeviceListMix(View):
|
||||||
)
|
)
|
||||||
|
|
||||||
if lot_id:
|
if lot_id:
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
devices = [dev for dev in lot.devices if dev.type in filter_types]
|
||||||
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
devices = sorted(devices, key=lambda x: x.updated, reverse=True)
|
||||||
|
|
Reference in New Issue