def get_actionable_blocks(self): blocked_wages = (Event.objects.filter( society=user_society(self.request), invoice__paid=False).aggregate( wages=Sum(F('shifts__hours') * F('shifts__wage'), output_field=models.DecimalField( decimal_places=2))))['wages'] missing_ids = (Worker.objects.filter( employment__society=user_society(self.request), norlonn_number__isnull=True).count()) return self._sanitise_blocks([{ 'title': _("Your Blocked Wages"), 'kpi': blocked_wages if blocked_wages else None, 'detail': _("Wages blocked by unpaid invoices"), 'url': reverse('invoices'), 'alert': 'success' }, { 'title': _("Your Missing Norlønn-IDs"), 'kpi': missing_ids if missing_ids else None, 'detail': _("Workers whose pay will not be exported"), 'url': reverse('workers') }])
def index(request): reports = NorlonnReport.objects.all().order_by('-date') errors = [] queryset = Shift.objects.select_related().prefetch_related( 'event__invoice').filter(norlonn_report__isnull=True, event__processed__isnull=False) if request.user.has_perm('norlonn.generate_report'): shifts = queryset else: shifts = queryset.filter( event__society=user_society(request.user.spfuser)) for s in shifts: if s.worker.norlonn_number is None: errors.append( _("Worker %s (for %s) lacks norlonn number!" % (s.worker, s.event))) if not s.event.invoice.paid: errors.append( _("%s (for %s) --- Invoice not paid" % (s.worker, s.event))) return render(request, 'norlonn/index.jinja', { 'reports': reports, 'errors': errors })
def form_valid(self, form): """ Evaluate the add-worker-by-national-ID form, and redirect appropriately. """ worker = Worker.objects.filter( person_id=form.cleaned_data['person_id']).first() society = user_society(self.request) if worker and society in worker.societies.all(): msg.info( self.request, _('{worker} is already associated with your society {society}.' ).format(worker=worker, society=society)) return redirect(worker) elif worker: employment = Employment(society=society, worker=worker) employment.save() msg.success( self.request, _('The worker {worker} has been successfully associated as employed with {society}.' ).format(worker=worker, society=society)) return redirect(worker) else: msg.info( self.request, _('There is no worker with that national ID. You may create one now.' )) return redirect('worker-create', society_name=society, nid=form.cleaned_data['person_id'])
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({ 'society': user_society(self.request), 'dashboard': { 'general': self.get_general_status_blocks(), 'actionable': self.get_actionable_blocks() } }) return context
def post(self, request, *args, **kwargs): form_class = self.get_form_class() form = self.get_form(form_class) if form.is_valid(): self.object = form.save(commit=False) self.object.society = user_society(request) form_validated = True else: self.object = None form_validated = False inlines = self.construct_inlines() if all_valid(inlines) and form_validated: return self.forms_valid(form, inlines) return self.forms_invalid(form, inlines)
def get_form_class(self): return make_shift_base(user_society(self.request))