Exemplo n.º 1
0
 def get(self, *args, **kwargs):
     current_year = datetime.date.today().year
     nodes = models.Group.objects.all()
     response = HttpResponse(content_type="text/plain")
     response['Content-Disposition'] = 'attachment; filename="cnt_sheet.csv"'
     w = csv.writer(response)
     for node in nodes:
         articles = node.article_set.filter(
             Q(offer__orderitem__completed_on__year=current_year - 2) |
             Q(offer__orderitem__completed_on__year=current_year - 1) |
             Q(offer__orderitem__completed_on__year=current_year)
             ).distinct()
         if articles.count() > 0:
             path = "/".join([tree_path(node.get_ancestors(), "/"),
                 unicode(node)])
             w.writerow([
                 path.encode('utf-8'),
             ])
             for a in articles:
                 w.writerow([
                     a.code.encode('utf-8'),
                     a.description.encode('utf-8'),
                     getattr(a, 'brand', ''),
                     a.measure_unit,
                 ])
     return response
Exemplo n.º 2
0
 def get(self, *args, **kwargs):
     nodes = models.Group.objects.all()
     response = HttpResponse(content_type="text/plain")
     response['Content-Disposition'] = 'attachment; filename="stock.csv"'
     w = csv.writer(response)
     for node in nodes:
         articles = node.article_set.filter(stock__gt=0)
         if articles.count() > 0:
             path = "/".join([tree_path(node.get_ancestors(), "/"),
                 unicode(node)])
             w.writerow([
                 path.encode('utf-8'),
             ])
             for a in articles:
                 w.writerow([
                     a.code.encode('utf-8'),
                     a.description.encode('utf-8'),
                     getattr(a, 'brand', ''),
                     a.stock,
                     a.measure_unit,
                     floatformat(a.stock_value, 2),
                 ])
     return response
Exemplo n.º 3
0
 def get_category_path(self, separator=" > "):
     path = tree_path(self.parent.get_ancestors(separator))
     if not path:
         return self.parent.name
     return separator.join([path, self.parent.name])