def _import_subscription(self, type_name, dateformat): working_subscription = None current_season = Season.current_season() type_option = 0 if '#' in type_name: type_name, type_option = type_name.split('#') try: type_obj = SubscriptionType.objects.filter(name=type_name) if len(type_obj) > 0: type_obj = type_obj[0] if type_obj.duration == 1: type_option = int(type_option) - 1 period_list = current_season.period_set.all() begin_date = period_list[type_option].begin_date end_date = period_list[type_option].end_date elif type_obj.duration == 2: type_option = int(type_option) - 1 mounths = current_season.get_months() begin_date = convert_date(mounths[type_option][0] + '-01') end_date = same_day_months_after( begin_date, 1) - timedelta(days=1) elif type_obj.duration == 3: try: begin_date = datetime.strptime( type_option, dateformat).date() except (TypeError, ValueError): begin_date = date.today() end_date = same_day_months_after( begin_date, 12) - timedelta(days=1) else: begin_date = current_season.begin_date end_date = current_season.end_date try: working_subscription = Subscription.objects.get( adherent=self, season=current_season, subscriptiontype=type_obj, begin_date=begin_date, end_date=end_date) except ObjectDoesNotExist: working_subscription = Subscription() working_subscription.adherent = self working_subscription.season = current_season working_subscription.subscriptiontype = type_obj working_subscription.begin_date = begin_date working_subscription.end_date = end_date working_subscription.save() if isinstance(working_subscription, tuple): working_subscription = working_subscription[0] except: logging.getLogger('diacamma.member').exception("import_data") return working_subscription
def set_periode(self, dateref): self.dateref = dateref self.season = Season.get_from_date(dateref) if self.subscriptiontype.duration == 0: # periodic self.begin_date = self.season.begin_date self.end_date = self.season.end_date elif self.subscriptiontype.duration == 1: # periodic period = self.season.get_period_from_date(dateref) self.begin_date = period.begin_date self.end_date = period.end_date elif self.subscriptiontype.duration == 2: # monthly self.begin_date = convert_date('%4d-%02d-01' % (dateref.year, dateref.month)) self.end_date = same_day_months_after(self.begin_date, 1) - timedelta(days=1) elif self.subscriptiontype.duration == 3: # calendar self.begin_date = dateref self.end_date = same_day_months_after(self.begin_date, 12) - timedelta(days=1)
def get_filter(self): team = self.getparam("team", ()) activity = self.getparam("activity", ()) genre = self.getparam("genre", 0) age = self.getparam("age", ()) status = self.getparam("status", -1) dateref = convert_date(self.getparam("dateref", ""), Season.current_season().date_ref) if self.getparam('is_renew', False): date_one_year = same_day_months_after(dateref, -12) date_six_month = same_day_months_after(dateref, -6) date_three_month = same_day_months_after(dateref, -3) current_filter = Q(subscription__subscriptiontype__duration=0) & Q( subscription__end_date__gte=date_one_year) current_filter |= Q(subscription__subscriptiontype__duration=1) & Q( subscription__end_date__gte=date_six_month) current_filter |= Q(subscription__subscriptiontype__duration=2) & Q( subscription__end_date__gte=date_three_month) current_filter |= Q(subscription__subscriptiontype__duration=3) & Q( subscription__end_date__gte=date_one_year) exclude_filter = Q(subscription__begin_date__lte=dateref) & Q( subscription__end_date__gte=dateref) else: current_filter = Q(subscription__begin_date__lte=dateref) & Q( subscription__end_date__gte=dateref) exclude_filter = Q() if len(team) > 0: current_filter &= Q(subscription__license__team__in=team) if len(activity) > 0: current_filter &= Q(subscription__license__activity__in=activity) if len(age) > 0: age_filter = Q() for age_item in Age.objects.filter(id__in=age): age_filter |= Q(birthday__gte="%d-01-01" % (dateref.year - age_item.maximum)) & Q( birthday__lte="%d-12-31" % (dateref.year - age_item.minimum)) current_filter &= age_filter if genre != 0: current_filter &= Q(genre=genre) if status == -1: current_filter &= Q(subscription__status__in=(1, 2)) else: current_filter &= Q(subscription__status=status) return (current_filter, exclude_filter)
def CurrentCallFundsAdding(self, to_create): if to_create: nb_seq = 0 if Params.getvalue("condominium-mode-current-callfunds") == 0: nb_seq = 4 if Params.getvalue("condominium-mode-current-callfunds") == 1: nb_seq = 12 year = FiscalYear.get_current() for num in range(nb_seq): date = same_day_months_after(year.begin, int(num * 12 / nb_seq)) new_call = CallFunds.objects.create(date=date, comment=_("Call of funds #%(num)d of year from %(begin)s to %(end)s") % {'num': num + 1, 'begin': get_value_converted(year.begin), 'end': get_value_converted(year.end)}, status=0) for category in Set.objects.filter(type_load=0, is_active=True): CallDetail.objects.create(set=category, type_call=0, callfunds=new_call, price=category.get_current_budget() / nb_seq, designation=_("%(type)s - #%(num)d") % {'type': _('current'), 'num': num + 1}) else: year = FiscalYear.get_current() calls = CallFunds.objects.filter(date__gte=year.begin, date__lte=year.end, calldetail__type_call=0).distinct() return len(calls) == 0