def warehouse_product_report_view(request): date_start, date_end = date_range_filter(request) products = Product.objects.none() if 'get_button' in request.GET: products = Product.filters_data(request, Product.objects.filter(active=True)) vendor_filter, date_filter, search_filter = [True] * 3 vendors, categories = Vendor.objects.filter( active=True), WarehouseCategory.objects.filter(active=True) # get warehouse warehouse_data = InvoiceOrderItem.objects.filter( order__date_expired__range=[date_start, date_end], product__in=products) warehouse_movement = warehouse_data.values_list('product__title').annotate(qty=Sum('qty'), total_value=Sum('total_final_value') ).order_by('product__title') \ if warehouse_data else 'No data' # get sells sells_data = OrderItem.objects.filter( order__date_expired__range=[date_start, date_end], title__in=products) sell_movements = sells_data.values_list('title__title', 'title__vendor__title')\ .annotate(qty=Sum('qty'), total_cost=Sum('total_cost_value'), total_value=Sum('total_value') ).order_by('title__title') return render(request, 'reports/warehouse_product.html', context=locals())
def get_context_data(self, **kwargs): context = super(ChartSizeManagerView, self).get_context_data(**kwargs) brands = Brand.objects.filter(active=True) categories = Category.objects.filter(active=True) products = Product.filters_data( self.request, Product.my_query.active_for_site())[:15] search_filter, brand_filter = [True] * 2 context.update(locals()) return context
def ajax_presentation_filter_products_view(request): products = Product.filters_data(request, Product.objects.all()) products = products[:30] data = dict() data['result'] = render_to_string('dashboard/ajax_calls/product_presentation_container.html', request=request, context={ 'product_list': products }) return JsonResponse(data)
def ajax_products_discount_add(request, pk): data = dict() discount_order = get_object_or_404(ProductDiscount, id=pk) products = Product.filters_data(request, Product.objects.all()) products = list(products) discount_order.products_related.add(*products) discount_order.save() discount_order.refresh_from_db() data['result'] = render_to_string(template_name='dashboard/ajax_calls/discount_result.html', request=request, context={'object': discount_order}) return JsonResponse(data)
def ajax_search_products(request, pk): instance = get_object_or_404(SalesInvoice, id=pk) products = Product.filters_data(request, Product.objects.filter(active=True)) data = dict() data['result'] = render_to_string( template_name='point_of_sale/ajax/product_container.html', request=request, context={ 'object': instance, 'products': products }) return JsonResponse(data)
def ajax_search_products(request): products = Product.filters_data(request, Product.objects.all()) print('hey!', products.count()) data = dict() queryset_table = TableProduct(products) RequestConfig(request, paginate={"per_page": 30}).configure(queryset_table) data['result'] = render_to_string('dashboard/ajax_calls/queryset_table.html', request=request, context={ 'product_list': products, 'queryset_table': queryset_table }) return JsonResponse(data)
def get_queryset(self): qs = Product.my_query.active_for_site() qs = Product.filters_data(self.request, qs) self.initial_queryset = qs if self.request.GET.getlist('char_name', None): try: ids = ProductCharacteristics.filters_data( self.request, ProductCharacteristics.objects.all()).values_list( 'product_related__id') qs = qs.filter(id__in=ids) except: qs = qs return qs
def update_sale_invoice_view(request, pk): instance = get_object_or_404(SalesInvoice, id=pk) form = SalesInvoiceForm(request.POST or None, instance=instance) form.fields['costumer'].widget = forms.HiddenInput() if form.is_valid(): form.save() return redirect(instance.get_edit_url()) back_url = instance.get_edit_url() products = Product.filters_data(request, Product.objects.filter(active=True))[:10] return render(request, 'point_of_sale/update_view.html', context={'form': form, 'object': instance, 'products': products, 'back_url': back_url })
def get_queryset(self): self.initial_queryset = Product.my_query.products_with_offer() qs = Product.filters_data(self.request, self.initial_queryset) if self.request.GET.get('attr_name', None): qs = Attribute.product_filter_data(self.request, qs) if self.request.GET.getlist('char_name', None): try: ids = ProductCharacteristics.filters_data( self.request, ProductCharacteristics.objects.all()).values_list( 'product_related__id') qs = qs.filter(id__in=ids) except: qs = qs return qs
def get_queryset(self): brand = self.brand = get_object_or_404(Brand, slug=self.kwargs['slug']) qs = Product.my_query.active_for_site().filter(brand=brand) self.initial_queryset = qs qs = Product.filters_data(self.request, qs) if self.request.GET.getlist('char_name', None): try: ids = ProductCharacteristics.filters_data( self.request, ProductCharacteristics.objects.all()).values_list( 'product_related__id') qs = qs.filter(id__in=ids) except: qs = qs return qs
def ajax_warehouse_analysis(request): print('here') data = dict() products = Product.filters_data(request, Product.objects.all()) queryset = InvoiceOrderItem.objects.filter(product__in=products) queryset_table = queryset.values_list('product__title', 'product__qty','product__vendor')\ .annotate(qty=Sum('qty'), total_value=Sum('total_final_value') ).order_by('product__title') \ if queryset else 'No data' print(queryset_table) data['result_analysis'] = render_to_string( template_name='reports/ajax_analysis.html', request=request, context={'queryset_table': queryset_table}) return JsonResponse(data)
def get_queryset(self): self.initial_queryset = Product.my_query.active_for_site().filter( timestamp__gt=datetime.datetime.today() - datetime.timedelta(days=60)) qs = Product.filters_data(self.request, self.initial_queryset) if self.request.GET.getlist('attr_name', None): qs = Attribute.product_filter_data(self.request, qs) if self.request.GET.getlist('char_name', None): try: ids = ProductCharacteristics.filters_data( self.request, ProductCharacteristics.objects.all()).values_list( 'product_related__id') qs = qs.filter(id__in=ids) except: qs = qs return qs
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) products = Product.objects.none() if 'search_button' in self.request.GET: products = Product.filters_data(self.request, Product.objects.all()) back_url = reverse('dashboard:discount_manager') # filters brand_filter, category_filter, search_filter, vendor_filter = [True ] * 4 vendors, categories, brands = Vendor.objects.filter( active=True), Category.objects.filter( active=True), Brand.objects.filter(active=True) # ajax filter url get_params = self.request.get_full_path().split( '?', 1)[1] if '?' in self.request.get_full_path() else '' ajax_add_url = reverse('dashboard:ajax_products_discount_add', kwargs={'pk': self.object.id }) + '?' + get_params print(ajax_add_url) context.update(locals()) return context
def ajax_product_calculate_view(request): data = dict() qs = Product.filters_data(request, Product.objects.all()) total_qty = qs.aggregate(Sum('qty'))['qty__sum'] if qs.exists() else 0 total_cost_value = qs.aggregate( total=Sum(F('qty') * F('price_buy')))['total'] if qs.exists() else 0 total_value = qs.aggregate( total=Sum(F('qty') * F('final_price')))['total'] if qs.exists() else 0 qs_vendor = qs.values_list('vendor__title').annotate( qty_=Sum('qty'), total_cost_=Sum(F('qty') * F('price_buy')), total_value_=Sum(F('qty') * F('final_price'))).order_by('qty_') data['report_result'] = render_to_string( template_name='dashboard/ajax_calls/product_result.html', request=request, context={ 'currency': CURRENCY, 'qs_vendor': qs_vendor[:10], 'total_qty': total_qty, 'total_cost_value': total_cost_value, 'total_value': total_value }) return JsonResponse(data)
def get_queryset(self): queryset = Product.filters_data(self.request, Product.objects.all()) self.total_products = queryset.count() if queryset else 0 return queryset
def get_queryset(self): qs = self.model.my_query.active() qs = Product.filters_data(self.request, qs) return qs