def get(self, request, company_id:int) -> HttpResponseRedirect: if checkWiFi(): company = get_object_or_404(Company, pk=company_id) month, year = now().month, now().year month, year = previous_month_year(month, year) html = cashregisterhtml2pdf(company_id, month, year) if html: # create pdf file and save on templates/pdf/cashregister_{company}_{month}_{year}.pdf options = {'page-size': 'A4', 'margin-top': '0.4in', 'margin-right': '0.2in', 'margin-bottom': '0.4in', 'margin-left': '0.6in', 'encoding': "UTF-8", 'orientation': 'portrait', 'no-outline': None, 'quiet': ''} pdfile = f'templates/pdf/cashregister_{company}_{month}_{year}.pdf' pdfkit.from_string(html, pdfile, options=options, css=settings.CSS_FILE) # send e-mail with attached cash register as file in pdf format mail = {'subject': f'cash register for {month}/{year} r.', 'message': f'Cash Register for {company} on {month}/{year} in attachment ...', 'sender': settings.EMAIL_HOST_USER, 'recipient': [settings.ACCOUNTANT_MAIL], 'attachments': [pdfile]} sendemail(**mail) messages.info(request, f'Cash register for {company} on {month}/{year} was sending....') else: messages.warning(request, r'Nothing to send...') else: messages.error(request, 'Occurred problem with internet connection...') return HttpResponseRedirect(reverse('cashregister:cash_register', args=[company_id]))
def queryset(self, request, queryset): if self.value() == LAST_MONTH: month, year = previous_month_year(now().month, now().year) return queryset.filter(start_work__year=year, start_work__month=month) else: return queryset
def setup(self, request, **kwargs): super(CashRegisterView, self).setup(request, **kwargs) self.request, self.kwargs, ctx = request, kwargs, 'contents' tags = CashRegister.objects.order_by(ctx).distinct(ctx).exclude(contents='z przeniesienia').values_list(ctx, flat=True) symbols = CashRegister.objects.order_by('symbol').distinct('symbol').values_list('symbol', flat=True) companies = Company.objects.filter(status__range=[1, 3]).order_by('company') self.context = {'companies': companies, 'tags': list(tags), 'symbols': list(symbols)} if 'company_id' in self.kwargs.keys(): self.company_id = self.kwargs['company_id'] check = CashRegister.objects.filter(company_id=self.company_id) month, year = now().month, now().year self.company = get_object_or_404(Company, pk=self.company_id) self.registerdata = cashregisterdata(self.company_id, month, year) self.context.update(self.registerdata) records = check.filter(created__month=month, created__year=year).exclude(contents='z przeniesienia') query = Q(company_id=self.company_id)&(Q(created__year=year)|Q(created__year=year-1)) cr_data = CashRegister.objects.filter(query).exclude(contents='z przeniesienia') cr_set = cr_data.datetimes('created','month', order='DESC') self.context.update({'company_id': self.company_id, 'company': self.company, 'records': records.order_by('-created'), 'cr_set': cr_set}) pm, py = previous_month_year(month, year) previous = check.filter(created__month=pm, created__year=py) if previous: self.context.__setitem__('previous', True) else: self.context.__setitem__('previous', False) if self.request.method == 'GET': self.form = CashRegisterForm(initial={'company': self.company}) elif self.request.method == 'POST': self.form = CashRegisterForm(data=self.request.POST) self.context.__setitem__('form', self.form)
def setup(self, request, **kwargs): super(AccountPaymentView, self).setup(request, **kwargs) self.request, self.kwargs = request, kwargs self.employee_id = self.kwargs['employee_id'] records = employee_records(self.employee_id) self.month, self.year = now().month, now().year self.initial = initial_account_form(self.employee_id) self.worker = get_object_or_404(Employee, pk=self.employee_id) self.prevmonth, self.prevyear = previous_month_year(self.month, self.year) earlier_date = date(self.prevyear, self.prevmonth, 1) # set list of valid employees q1 = Q(status=1) q2 = Q(employeedata__end_contract__gte=earlier_date) employees = Employee.objects.filter(q1|q2).order_by('surname', 'forename') if self.request.method == 'GET': self.form = AccountPaymentForm(initial=self.initial) elif self.request.method == 'POST': self.form = AccountPaymentForm(data=self.request.POST) # seting context self.context = {'form': self.form, 'worker': self.worker, 'earlier_date': earlier_date, 'month': self.month, 'employee_id': self.employee_id, 'employees': employees, 'year': self.year, 'ap_flag': True, 'records': records}
# my models from employee.models import Employee from evidence.models import WorkEvidence, EmployeeLeave, AccountPayment # my functions from functions.myfunctions import previous_month_year # my widgets from functions.widgets import RadioSelectButtonGroup # Create your forms here. # queryset to validate HiddenInput fields queryset = Employee.objects.all() month, year = previous_month_year(now().month, now().year) q1 = queryset.filter(status=1) q2 = queryset.filter(employeedata__end_contract__year__gte=year, employeedata__end_contract__month__gte=month) query = q1 | q2 # tempus-dominus datetimepiker icons icons = { 'today': 'fas fa-calendar-day', 'clear': 'fas fa-trash-alt', 'close': 'fas fa-times-circle' } # my forms class WorkEvidenceForm(forms.ModelForm):