@@ -0,0 +1,2330 @@
+# -*- coding: utf-8 -*-%0A# This file is part of Shuup.%0A#%0A# Copyright (c) 2012-2017, Shoop Commerce Ltd. All rights reserved.%0A#%0A# This source code is licensed under the OSL-3.0 license found in the%0A# LICENSE file in the root directory of this source tree.%0Afrom django.db.models import Avg, Count, Sum%0Afrom django.utils.translation import ugettext_lazy as _%0A%0Afrom shuup.core.models import Contact%0Afrom shuup.default_reports.forms import CustomerSalesReportForm%0Afrom shuup.default_reports.mixins import OrderReportMixin%0Afrom shuup.reports.report import ShuupReportBase%0A%0A%0Aclass CustomerSalesReport(OrderReportMixin, ShuupReportBase):%0A    identifier = %22customer_sales_report%22%0A    title = _(%22Customer Sales%22)%0A    form_class = CustomerSalesReportForm%0A%0A    filename_template = %22customer-sales-report-%25(time)s%22%0A    schema = %5B%0A        %7B%22key%22: %22customer%22, %22title%22: _(%22Customer%22)%7D,%0A        %7B%22key%22: %22order_count%22, %22title%22: _(%22Orders%22)%7D,%0A        %7B%22key%22: %22average_sales%22, %22title%22: _(%22Average Sales%22)%7D,%0A        %7B%22key%22: %22taxless_total%22, %22title%22: _(%22Taxless Total%22)%7D,%0A        %7B%22key%22: %22taxful_total%22, %22title%22: _(%22Taxful Total%22)%7D,%0A    %5D%0A%0A    def get_objects(self):%0A        return Contact.objects.filter(%0A            customer_orders__in=super(CustomerSalesReport, self).get_objects()%0A        ).annotate(%0A            order_count=Count(%22customer_orders%22, distinct=True),%0A            average_sales=Avg(%22customer_orders__taxful_total_price_value%22),%0A            taxless_total=Sum(%22customer_orders__taxless_total_price_value%22),%0A            taxful_total=Sum(%22customer_orders__taxful_total_price_value%22)%0A        ).filter(order_count__gt=0).order_by(%22-%25s%22 %25 self.options%5B%22order_by%22%5D).values(%0A            %22name%22, %22order_count%22, %22average_sales%22, %22taxless_total%22, %22taxful_total%22%0A        )%0A%0A    def get_data(self):%0A        data = %5B%5D%0A%0A        for contact in self.get_objects():%0A            data.append(%7B%0A                %22customer%22: contact%5B%22name%22%5D,%0A                %22order_count%22: contact%5B%22order_count%22%5D,%0A                %22average_sales%22: self.shop.create_price(contact%5B%22average_sales%22%5D).as_rounded().value,%0A                %22taxless_total%22: self.shop.create_price(contact%5B%22taxless_total%22%5D).as_rounded().value,%0A                %22taxful_total%22: self.shop.create_price(contact%5B%22taxful_total%22%5D).as_rounded().value,%0A            %7D)%0A%0A        return self.get_return_data(data)%0A

create customer sales