add transfer in name of lot
This commit is contained in:
parent
97edb260b7
commit
7d40f5b537
|
@ -1,6 +1,7 @@
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from citext import CIText
|
from citext import CIText
|
||||||
|
from flask import g
|
||||||
from sqlalchemy import Column, Integer
|
from sqlalchemy import Column, Integer
|
||||||
from sqlalchemy.dialects.postgresql import UUID
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from sqlalchemy.orm import backref, relationship
|
from sqlalchemy.orm import backref, relationship
|
||||||
|
@ -43,6 +44,15 @@ class Transfer(Thing):
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def type_transfer(self):
|
||||||
|
if self.user_from == g.user:
|
||||||
|
return 'Outgoing'
|
||||||
|
|
||||||
|
if self.user_to == g.user:
|
||||||
|
return 'Incoming'
|
||||||
|
|
||||||
|
return 'Temporary'
|
||||||
|
|
||||||
|
|
||||||
class DeliveryNote(Thing):
|
class DeliveryNote(Thing):
|
||||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4)
|
||||||
|
|
|
@ -111,7 +111,7 @@ class LotView(View):
|
||||||
query = query.filter(Lot.name.ilike(args['search'] + '%'))
|
query = query.filter(Lot.name.ilike(args['search'] + '%'))
|
||||||
lots = query.paginate(per_page=6 if args['search'] else query.count())
|
lots = query.paginate(per_page=6 if args['search'] else query.count())
|
||||||
return things_response(
|
return things_response(
|
||||||
self.schema.dump(lots.items, many=True, nested=2),
|
self.get_lots_dump(lots),
|
||||||
lots.page,
|
lots.page,
|
||||||
lots.per_page,
|
lots.per_page,
|
||||||
lots.total,
|
lots.total,
|
||||||
|
@ -120,6 +120,19 @@ class LotView(View):
|
||||||
)
|
)
|
||||||
return jsonify(ret)
|
return jsonify(ret)
|
||||||
|
|
||||||
|
def get_lots_dump(self, lots):
|
||||||
|
lots_dump = self.schema.dump(lots.items, many=True, nested=2)
|
||||||
|
for lot in lots.items:
|
||||||
|
if not lot.transfer:
|
||||||
|
continue
|
||||||
|
for _lot in lots_dump:
|
||||||
|
if _lot['id'] == str(lot.id):
|
||||||
|
name = _lot['name']
|
||||||
|
type_transfer = lot.type_transfer()
|
||||||
|
_lot['name'] = f'{name} - ({type_transfer})'
|
||||||
|
break
|
||||||
|
return lots_dump
|
||||||
|
|
||||||
def visibility_filter(self, query):
|
def visibility_filter(self, query):
|
||||||
query = (
|
query = (
|
||||||
query.outerjoin(Trade)
|
query.outerjoin(Trade)
|
||||||
|
@ -142,10 +155,7 @@ class LotView(View):
|
||||||
# temporary
|
# temporary
|
||||||
if lot_type == "temporary":
|
if lot_type == "temporary":
|
||||||
return query.filter(Lot.trade == None).filter(
|
return query.filter(Lot.trade == None).filter(
|
||||||
or_(
|
or_(Lot.transfer == None, Transfer.date == None)
|
||||||
Lot.transfer == None,
|
|
||||||
Transfer.date == None
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if lot_type == "incoming":
|
if lot_type == "incoming":
|
||||||
|
|
Reference in New Issue