Skip to content
This repository has been archived by the owner on Aug 24, 2022. It is now read-only.

Commit

Permalink
Obsolete libraries not showing in invoicing, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
risufaj committed Oct 31, 2018
1 parent 9ae5454 commit 6fa8018
Show file tree
Hide file tree
Showing 14 changed files with 111 additions and 23 deletions.
10 changes: 6 additions & 4 deletions invoicing/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ def get_percentage(self, obj):
library_ids.append(library.pk)
for sample in samples:
sample_ids.append(sample.pk)
for library in libraries:
print("Library---------------")
pprint(vars(library))

depth = sum(libraries.values_list(
'sequencing_depth', flat=True)) + \
sum(samples.values_list('sequencing_depth', flat=True))
Expand Down Expand Up @@ -182,8 +180,9 @@ def get_num_libraries_samples(self, obj):

num_samples = obj.samples.count()
if num_libraries > 0:
print(num_libraries)



libcount = 0
flowcells = self.get_percentage(obj)
maxYear = max([d['flowcell_create_year'] for d in flowcells])
Expand All @@ -194,6 +193,8 @@ def get_num_libraries_samples(self, obj):
libcount = libcount + len(pool['libraries'])

return f'{libcount} libraries'


else:
sampcount = 0
flowcells = self.get_percentage(obj)
Expand All @@ -207,6 +208,7 @@ def get_num_libraries_samples(self, obj):

def get_library_protocol(self, obj):
protocols = set([x.library_protocol.pk for x in obj.records])

return protocols.pop() if protocols else ''

def get_fixed_costs(self, obj):
Expand Down
26 changes: 24 additions & 2 deletions invoicing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
LibraryPreparationCostsSerializer,
SequencingCostsSerializer,
)

from django.db import transaction
Request = apps.get_model('request', 'Request')
ReadLength = apps.get_model('library_sample_shared', 'ReadLength')
LibraryProtocol = apps.get_model('library_sample_shared', 'LibraryProtocol')
Expand All @@ -39,6 +39,9 @@
Flowcell = apps.get_model('flowcell', 'Flowcell')





class InvoicingViewSet(viewsets.ReadOnlyModelViewSet):
permission_classes = [IsAdminUser]
serializer_class = InvoicingSerializer
Expand All @@ -57,7 +60,6 @@ def get_queryset(self):
).select_related(
'read_length', 'library_protocol',
).only('read_length', 'library_protocol__name')

samples_qs = Sample.objects.filter(
~Q(pool=None) & ~Q(status=-1)
).select_related(
Expand All @@ -81,8 +83,18 @@ def get_queryset(self):
'cost_unit__name',
).order_by('sequencing_date', 'pk')



return queryset


def list(self,request):
queryset = self.filter_queryset(self.get_queryset())
serializer = self.get_serializer(queryset, many=True)

return Response(serializer.data)


@action(methods=['get'], detail=False)
def billing_periods(self, request):
flowcells = Flowcell.objects.all()
Expand Down Expand Up @@ -276,10 +288,20 @@ class FixedCostsViewSet(mixins.UpdateModelMixin,
class LibraryPreparationCostsViewSet(mixins.UpdateModelMixin,
viewsets.ReadOnlyModelViewSet):
""" Get the list of Library Preparation Costs. """
obsolete_protocols = LibraryProtocol.objects.filter(obsolete=settings.OBSOLETE).values_list('id', flat=True)
lst = list(obsolete_protocols)
with transaction.atomic():
for id in obsolete_protocols:
LibraryProtocol.objects.filter(id=id).update(obsolete=settings.NON_OBSOLETE)
permission_classes = [IsAdminUser]
queryset = LibraryPreparationCosts.objects.all()
print(queryset.query)

serializer_class = LibraryPreparationCostsSerializer

with transaction.atomic():
for id in obsolete_protocols:
LibraryProtocol.objects.filter(id=id).update(obsolete=settings.OBSOLETE)

class SequencingCostsViewSet(mixins.UpdateModelMixin,
viewsets.ReadOnlyModelViewSet):
Expand Down
2 changes: 2 additions & 0 deletions library_preparation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def list(self, request):
data = sorted(serializer.data, key=lambda x: x['barcode'][3:])
return Response(data)



@action(methods=['post'], detail=False,
authentication_classes=[CsrfExemptSessionAuthentication])
# @authentication_classes((CsrfExemptSessionAuthentication))
Expand Down
12 changes: 6 additions & 6 deletions library_sample_shared/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,23 @@ def idx_id(sef, obj):
@admin.register(LibraryProtocol)
class LibraryProtocolAdmin(admin.ModelAdmin):
list_display = ('name', 'type', 'provider', 'catalog',
'typical_application','status_name',)
'typical_application','obsolete_name',)
search_fields = ('name', 'provider', 'catalog', 'typical_application',)
list_filter = ('type',)
actions = ('mark_as_obsolete','mark_as_non_obsolete',)

def mark_as_obsolete(self,request,queryset):
queryset.update(status=settings.OBSOLETE)
queryset.update(obsolete=settings.OBSOLETE)
mark_as_obsolete.short_description = "Mark library protocol as obsolete"

def mark_as_non_obsolete(self,request,queryset):
queryset.update(status=settings.NON_OBSOLETE)
queryset.update(obsolete=settings.NON_OBSOLETE)
mark_as_non_obsolete.short_description = "Mark library protocol as non-obsolete"

def status_name(self,obj):
def obsolete_name(self,obj):

return "Non-obsolete" if obj.status==settings.NON_OBSOLETE else "Obsolete"
status_name.short_description = "STATUS"
return "Non-obsolete" if obj.obsolete==settings.NON_OBSOLETE else "Obsolete"
obsolete_name.short_description = "STATUS"



Expand Down
1 change: 1 addition & 0 deletions library_sample_shared/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class LibraryProtocol(models.Model):

status = models.PositiveIntegerField("Status", default=1)
comments = models.TextField('Comments', null=True, blank=True)
obsolete = models.PositiveIntegerField("Obsolete", default=1)

class Meta:
verbose_name = 'Library Protocol'
Expand Down
13 changes: 12 additions & 1 deletion library_sample_shared/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,20 @@ def get_queryset(self):
na_type = self.request.query_params.get('type', None)
if na_type is not None:
queryset = queryset.filter(type=na_type)
queryset = queryset.filter(status=settings.NON_OBSOLETE)
queryset = queryset.filter(obsolete=settings.NON_OBSOLETE)
return queryset

class LibraryProtocolInvoicingViewSet(MoveOtherMixin, viewsets.ReadOnlyModelViewSet):
""" Get the list of library protocols for invoicing. """
serializer_class = LibraryProtocolSerializer

def get_queryset(self):
queryset = LibraryProtocol.objects.order_by('name')
na_type = self.request.query_params.get('type', None)
if na_type is not None:
queryset = queryset.filter(type=na_type)

return queryset

class LibraryTypeViewSet(MoveOtherMixin, viewsets.ReadOnlyModelViewSet):
""" Get the list of library types. """
Expand Down
23 changes: 22 additions & 1 deletion pooling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
logger = logging.getLogger('db')


class PoolingViewSet(LibrarySampleMultiEditMixin, viewsets.ViewSet):
class PoolingViewSet(LibrarySampleMultiEditMixin, viewsets.ModelViewSet):
permission_classes = [IsAdminUser]
library_model = Library
sample_model = Sample
Expand Down Expand Up @@ -183,6 +183,17 @@ def list(self, request):
data = sorted(data, key=lambda x: x['barcode'][3:])
return Response(data)

@action(methods=['post'], detail=True)
def edit_comment(self, request, pk=None):

instance = Pool.objects.filter(pk=pk)

post_data = self._get_post_data(request)
newComment = post_data['newComment']

instance.update(comment=newComment)
return Response({'success': True})

@action(methods=['post'], detail=False,
authentication_classes=[CsrfExemptSessionAuthentication])
def download_benchtop_protocol(self, request):
Expand Down Expand Up @@ -467,3 +478,13 @@ def download_pooling_template(self, request):

wb.save(response)
return response

def _get_post_data(self, request):
post_data = {}
if request.is_ajax():
post_data = request.data.get('data', {})
if isinstance(post_data, str):
post_data = json.loads(post_data)
else:
post_data = json.loads(request.data.get('data', '{}'))
return post_data
2 changes: 1 addition & 1 deletion request/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_restrict_permissions(self, obj):

def get_completed(self, obj):
""" Return True if request's libraries and samples are sequenced. """
return obj.statuses.count(5) > 0
return obj.statuses.count(6) > 0

def get_deep_seq_request_name(self, obj):
return obj.deep_seq_request.name.split('/')[-1] \
Expand Down
11 changes: 5 additions & 6 deletions request/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def get_queryset(self,showAll=False):
Prefetch('samples', queryset=samples_qs),
'files',
).order_by('-create_time')
print(queryset.values())

if not showAll:
queryset = queryset.filter(sequenced=False)
if self.request.user.is_staff:
Expand All @@ -188,7 +188,7 @@ def get_queryset(self,showAll=False):

def list(self, request):
""" Get the list of requests. """
print(request.GET)

showAll = False
if request.GET.get('showAll') == 'True':
showAll = True
Expand Down Expand Up @@ -253,11 +253,10 @@ def mark_as_complete(self,request,pk=None):
instance = Request.objects.filter(pk=pk)


print(pk)

post_data = self._get_post_data(request)
override = post_data['override']
print(post_data['override'])
print(override)

if post_data['override'] == 'False':
override = False
else:
Expand All @@ -280,7 +279,7 @@ def checkifcomplete(element):
#print(instance.statuses)
#check if all libraries/samples related to this requested have been sequenced
statuses = [status for x in instance for status in x.statuses]
print(statuses)

complete = all([checkifcomplete(x) for x in statuses])

if complete:
Expand Down
1 change: 1 addition & 0 deletions static/main-hub/app/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ext.define('MainHub.Application', {
'invoicing.FixedCosts',
'invoicing.LibraryPreparationCosts',
'invoicing.SequencingCosts',
'invoicing.LibraryProtocolsInvoicing',
'usage.Records',
'usage.Organizations',
'usage.PrincipalInvestigators',
Expand Down
27 changes: 27 additions & 0 deletions static/main-hub/app/store/invoicing/LibraryProtocolsInvoicing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Ext.define('MainHub.store.invoicing.LibraryProtocolsInvoicing', {
extend: 'Ext.data.Store',
storeId: 'libraryprotocolinvoicingStore',

requires: [
'MainHub.model.libraries.LibraryProtocol'
],

model: 'MainHub.model.libraries.LibraryProtocol',

proxy: {
type: 'ajax',
url: 'api/library_protocols_invoicing/',
timeout: 1000000,
pageParam: false, //to remove param "page"
startParam: false, //to remove param "start"
limitParam: false, //to remove param "limit"
noCache: false, //to remove param "_dc",
reader: {
type: 'json',
rootProperty: 'data',
successProperty: 'success'
}
},

autoLoad: true
});
2 changes: 1 addition & 1 deletion static/main-hub/app/view/invoicing/InvoicingController.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Ext.define('MainHub.view.invoicing.InvoicingController', {
},

libraryProtocolRenderer: function (value, meta) {
var record = Ext.getStore('libraryProtocolsStore').findRecord(
var record = Ext.getStore('libraryprotocolinvoicingStore').findRecord(
'id', value, 0, false, true, true);
var name = record.get('name');
meta.tdAttr = Ext.String.format('data-qtip="{0}"', name);
Expand Down
2 changes: 1 addition & 1 deletion static/main-hub/app/view/requests/Requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Ext.define('MainHub.view.requests.Requests', {

margin: '0 15 0 0',
cls: 'grid-header-checkbox',
hidden: !USER.is_staff,
hidden: false,
listeners:{
change: function(checkbox, newValue, oldValue, eOpts) {

Expand Down
2 changes: 2 additions & 0 deletions wui/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
LibraryTypeViewSet,
ReadLengthViewSet,
ConcentrationMethodViewSet,
LibraryProtocolInvoicingViewSet
)
from library.views import LibrarySampleTree, LibraryViewSet
from sample.views import NucleicAcidTypeViewSet, SampleViewSet
Expand Down Expand Up @@ -44,6 +45,7 @@
router.register(r'index_types', IndexTypeViewSet, base_name='index-type')
router.register(r'indices', IndexViewSet, base_name='index')
router.register(r'library_protocols', LibraryProtocolViewSet, base_name='library-protocol')
router.register(r'library_protocols_invoicing', LibraryProtocolInvoicingViewSet, base_name='library-protocol-invoicing')
router.register(r'library_types', LibraryTypeViewSet, base_name='library-type')
router.register(r'nucleic_acid_types', NucleicAcidTypeViewSet, base_name='nucleic-acid-type')
router.register(r'pool_sizes', PoolSizeViewSet, base_name='pool-size')
Expand Down

0 comments on commit 6fa8018

Please sign in to comment.