Beispiel #1
0
def generate_pdf_dict():
    return {
        'subscriptions': SubscriptionDao.all_active_subscritions(),
        'products': SubscriptionProductDao.get_all(),
        'depots': DepotDao.all_depots_order_by_code(),
        'weekdays': {
            weekdays[weekday['weekday']]: weekday['weekday']
            for weekday in DepotDao.distinct_weekdays()
        },
        'messages': ListMessageDao.all_active()
    }
Beispiel #2
0
    def _collect_type_fields(self):
        containers = []
        for product in SubscriptionProductDao.get_all_visible().order_by('pk'):
            product_container = CategoryContainer(instance=product)
            for subscription_size in product.sizes.filter(visible=True).order_by('pk'):
                size_container = CategoryContainer(instance=subscription_size, name=subscription_size.long_name)
                for subscription_type in subscription_size.types.filter(visible=True).order_by('pk'):
                    field_name = f'amount[{subscription_type.id}]'
                    self.fields[field_name] = IntegerField(label=subscription_type.name, min_value=0,
                                                           initial=self._get_initial(subscription_type))

                    size_container.append(SubscriptionTypeField(field_name, instance=subscription_type))
                product_container.append(size_container)
            containers.append(product_container)
        return containers
Beispiel #3
0
    def handle(self, *args, **options):
        if not options['force'] and timezone.now().weekday(
        ) not in Config.depot_list_generation_days():
            print(
                'not the specified day for depot list generation, use --force to override'
            )
            return

        if options['future'] or timezone.now().weekday(
        ) in Config.depot_list_generation_days():
            for subscription in SubscriptionDao.subscritions_with_future_depots(
            ):
                subscription.depot = subscription.future_depot
                subscription.future_depot = None
                subscription.save()
                emails = []
                for member in subscription.recipients:
                    emails.append(member.email)
                membernotification.depot_changed(emails, subscription.depot)

        if options['force'] and not options['future']:
            print('future depots ignored, use --future to override')

        depot_dict = {
            'subscriptions':
            SubscriptionDao.all_active_subscritions(),
            'products':
            SubscriptionProductDao.get_all_for_depot_list(),
            'extra_sub_categories':
            ExtraSubscriptionCategoryDao.categories_for_depot_list_ordered(),
            'depots':
            DepotDao.all_depots_order_by_code(),
            'weekdays': {
                weekdays[weekday['weekday']]: weekday['weekday']
                for weekday in DepotDao.distinct_weekdays()
            },
            'messages':
            ListMessageDao.all_active()
        }

        render_to_pdf_storage('exports/depotlist.html', depot_dict,
                              'depotlist.pdf')
        render_to_pdf_storage('exports/depot_overview.html', depot_dict,
                              'depot_overview.pdf')
        render_to_pdf_storage('exports/amount_overview.html', depot_dict,
                              'amount_overview.pdf')
Beispiel #4
0
 def fill_overview_cache(self):
     self.fill_active_subscription_cache()
     self.overview_cache = []
     for product in SubscriptionProductDao.get_all():
         for subscription_size in SubscriptionSizeDao.sizes_for_depot_list_by_product(product):
             cache = self.subscription_cache
             size_id = subscription_size.id
             amounts = self.subscription_amounts(cache, size_id)
             self.overview_cache.append(amounts)
     for category in ExtraSubscriptionCategoryDao.all_categories_ordered():
         types = ExtraSubscriptionTypeDao.extra_types_by_category_ordered(
             category)
         for extra_subscription in types:
             code = extra_subscription.name
             cache = self.subscription_cache
             esub = self.extra_subscription(cache, code)
             self.overview_cache.append(esub)
Beispiel #5
0
def depot_overview_direct(request):
    depot_dict = {
        'subscriptions':
        SubscriptionDao.all_active_subscritions(),
        'products':
        SubscriptionProductDao.get_all_for_depot_list(),
        'extra_sub_categories':
        ExtraSubscriptionCategoryDao.categories_for_depot_list_ordered(),
        'depots':
        DepotDao.all_depots_order_by_code(),
        'weekdays': {
            weekdays[weekday['weekday']]: weekday['weekday']
            for weekday in DepotDao.distinct_weekdays()
        },
        'messages':
        ListMessageDao.all_active()
    }

    return render_to_pdf_http('exports/depot_overview.html', depot_dict,
                              'depotlist.pdf')
Beispiel #6
0
def size_change(request, subscription_id):
    """
    change the size of a subscription
    """
    subscription = get_object_or_404(Subscription, id=subscription_id)
    saved = False
    share_error = False
    if request.method == 'POST' and int(timezone.now().strftime(
            '%m')) <= Config.business_year_cancelation_month():
        # create dict with subscription type -> selected amount
        selected = selected_subscription_types(request.POST)
        # check if members of sub have enough shares
        if subscription.all_shares < sum([
                sub_type.shares * amount
                for sub_type, amount in selected.items()
        ]):
            share_error = True
        elif sum(selected.values()
                 ) > 0:  # check that at least one subscription was selected
            replace_subscription_types(subscription, selected)
            saved = True
    products = SubscriptionProductDao.get_all()
    renderdict = get_menu_dict(request)
    renderdict.update({
        'saved':
        saved,
        'subscription':
        subscription,
        'shareerror':
        share_error,
        'hours_used':
        Config.assignment_unit() == 'HOURS',
        'next_cancel_date':
        temporal.next_cancelation_date(),
        'selected_subscription':
        subscription.future_types.all()[0].id,
        'products':
        products,
    })
    return render(request, 'size_change.html', renderdict)
Beispiel #7
0
    def handle(self, *args, **options):
        if not options['force'] and timezone.now().weekday(
        ) not in Config.depot_list_generation_days():
            print(
                'not the specified day for depot list generation, use --force to override'
            )
            return

        if options['future'] or timezone.now().weekday(
        ) in Config.depot_list_generation_days():
            for subscription in SubscriptionDao.subscritions_with_future_depots(
            ):
                subscription.depot = subscription.future_depot
                subscription.future_depot = None
                subscription.save()
                emails = []
                for member in subscription.recipients:
                    emails.append(member.email)
                send_depot_changed(emails, subscription.depot)

        if options['force'] and not options['future']:
            print('future depots ignored, use --future to override')

        depots = DepotDao.all_depots_order_by_code()

        subscription_ids = []
        for product in SubscriptionProductDao.get_all():
            for subscription_size in SubscriptionSizeDao.sizes_for_depot_list_by_product(
                    product):
                subscription_ids.append(subscription_size.id)

        categories = []
        types = []

        for product in SubscriptionProductDao.get_all():
            cat = {'name': product.name, 'description': product.description}
            count = 0
            for subscription_size in SubscriptionSizeDao.sizes_for_depot_list_by_product(
                    product):
                count += 1
                es_type = {
                    'name': subscription_size.name,
                    'size': subscription_size,
                    'last': False
                }
                types.append(es_type)
            es_type['last'] = True
            cat['count'] = count
            categories.append(cat)

        for category in ExtraSubscriptionCategoryDao.all_categories_ordered():
            cat = {'name': category.name, 'description': category.description}
            count = 0
            for extra_subscription in ExtraSubscriptionTypeDao.extra_types_by_category_ordered(
                    category):
                count += 1
                es_type = {
                    'name': extra_subscription.name,
                    'size': extra_subscription.size,
                    'last': False
                }
                types.append(es_type)
            es_type['last'] = True
            cat['count'] = count
            categories.append(cat)

        used_weekdays = []
        for item in DepotDao.distinct_weekdays():
            used_weekdays.append(weekdays[item['weekday']])

        overview = {'all': None}
        for weekday in used_weekdays:
            overview[weekday] = None

        count = len(types)
        for weekday in used_weekdays:
            overview[weekday] = [0] * count
        overview['all'] = [0] * count

        all = overview.get('all')

        for depot in depots:
            depot.fill_overview_cache()
            depot.fill_active_subscription_cache()
            row = overview.get(depot.get_weekday_display())
            count = 0
            # noinspection PyTypeChecker
            while count < len(row):
                row[count] += depot.overview_cache[count]
                all[count] += depot.overview_cache[count]
                count += 1

        insert_point = 0
        for weekday in used_weekdays:
            overview[weekday].insert(insert_point, 0)
        overview['all'].insert(insert_point, 0)

        index = 1
        for subscription_size in SubscriptionSizeDao.sizes_for_depot_list():
            for weekday in used_weekdays:
                overview[weekday][insert_point] = overview[weekday][insert_point] + subscription_size.units * \
                    overview[weekday][index]
            overview['all'][insert_point] = overview['all'][
                insert_point] + subscription_size.units * overview['all'][index]
            index += 1
        renderdict = {
            'overview': overview,
            'depots': depots,
            'subscription_ids': subscription_ids,
            'subscriptioncount': len(subscription_ids) + 1,
            'categories': categories,
            'types': types,
            'es_types': types[len(subscription_ids):],
            'datum': timezone.now(),
            'weekdays': used_weekdays,
            'messages': ListMessageDao.all_active()
        }

        render_to_pdf_storage('exports/legacy.html', renderdict, 'dpl.pdf')
        render_to_pdf_storage('exports/depotlist.html', renderdict,
                              'depotlist.pdf')
        render_to_pdf_storage('exports/depot_overview.html', renderdict,
                              'depot_overview.pdf')
        render_to_pdf_storage('exports/amount_overview.html', renderdict,
                              'amount_overview.pdf')