def before_save(self, xfer): xfer.is_new = (self.item.id is None) if xfer.getparam('autocreate', 0) == 1: self.item.send_email_param = (xfer.request.META.get( 'HTTP_REFERER', xfer.request.build_absolute_uri()), xfer.language) self.item.season = Season.current_season() if self.item.adherent_id is None: current_contact = Individual.objects.get( user=xfer.request.user) current_contact = current_contact.get_final_child() self.item.adherent = Adherent(id=current_contact.pk) self.item.adherent.save(new_num=True) self.item.adherent.__dict__.update(current_contact.__dict__) self.item.adherent.save() self.item.adherent_id = self.item.adherent.id if self.item.subscriptiontype.duration == 0: # periodic season = self.item.season self.item.begin_date = season.begin_date self.item.end_date = season.end_date elif self.item.subscriptiontype.duration == 1: # periodic periodid = xfer.getparam('period', 0) period = Period.objects.get(id=periodid) self.item.begin_date = period.begin_date self.item.end_date = period.end_date elif self.item.subscriptiontype.duration == 2: # monthly month_num = xfer.getparam('month', '') self.item.begin_date = convert_date(month_num + '-01') self.item.end_date = same_day_months_after(self.item.begin_date, 1) - timedelta(days=1) elif self.item.subscriptiontype.duration == 3: # calendar self.item.begin_date = convert_date(xfer.getparam( 'begin_date', '')) self.item.end_date = same_day_months_after(self.item.begin_date, 12) - timedelta(days=1)
def before_save(self, xfer): xfer.is_new = (self.item.id is None) if xfer.getparam('autocreate', 0) == 1: self.item.send_email_param = (xfer.request.META.get('HTTP_REFERER', xfer.request.build_absolute_uri()), xfer.language) self.item.season = Season.current_season() if self.item.adherent_id is None: current_contact = Individual.objects.get(user=xfer.request.user) current_contact = current_contact.get_final_child() self.item.adherent = Adherent(id=current_contact.pk) self.item.adherent.save(new_num=True) self.item.adherent.__dict__.update(current_contact.__dict__) self.item.adherent.save() self.item.adherent_id = self.item.adherent.id if self.item.subscriptiontype.duration == 0: # periodic season = self.item.season self.item.begin_date = season.begin_date self.item.end_date = season.end_date elif self.item.subscriptiontype.duration == 1: # periodic periodid = xfer.getparam('period', 0) period = Period.objects.get(id=periodid) self.item.begin_date = period.begin_date self.item.end_date = period.end_date elif self.item.subscriptiontype.duration == 2: # monthly month_num = xfer.getparam('month', '') self.item.begin_date = convert_date(month_num + '-01') self.item.end_date = same_day_months_after( self.item.begin_date, 1) - timedelta(days=1) elif self.item.subscriptiontype.duration == 3: # calendar self.item.begin_date = convert_date( xfer.getparam('begin_date', '')) self.item.end_date = same_day_months_after( self.item.begin_date, 12) - timedelta(days=1)
def saving(self, xfer): if not xfer.has_changed: self.before_save(xfer) self.item.save() date = convert_date(xfer.getparam('begin_date')) for period_idx in range(4): Period.objects.create(season=xfer.item, begin_date=same_day_months_after(date, period_idx * 3), end_date=same_day_months_after(date, (period_idx + 1) * 3) - timedelta(days=1)) if len(Season.objects.all()) == 1: xfer.item.set_has_actif()
def before_save(self, xfer): date = xfer.getparam('begin_date') if date is None: raise LucteriosException(IMPORTANT, _("date invalid!")) date = convert_date(date) new_season = "%d/%d" % (date.year, date.year + 1) if len(Season.objects.filter(designation=new_season)) > 0: raise LucteriosException(IMPORTANT, _("Season exists yet!")) self.item.designation = new_season self.item.iscurrent = False
def before_save(self, xfer): date = xfer.getparam('begin_date') if date is None: raise LucteriosException(IMPORTANT, _("date invalid!")) date = convert_date(date) new_season = "%d/%d" % (date.year, date.year + 1) if len( Season.objects.filter(designation=new_season).exclude( id=self.item.id)) > 0: raise LucteriosException(IMPORTANT, _("Season exists yet!")) self.item.designation = new_season self.item.iscurrent = False
def saving(self, xfer): if not xfer.has_changed: self.before_save(xfer) self.item.save() date = convert_date(xfer.getparam('begin_date')) for period_idx in range(4): Period.objects.create( season=xfer.item, begin_date=same_day_months_after(date, period_idx * 3), end_date=same_day_months_after(date, (period_idx + 1) * 3) - timedelta(days=1)) if len(Season.objects.all()) == 1: xfer.item.set_has_actif()
def _adherents(self): adherent_mdl = apps.get_model("member", "Adherent") adherent_mdl.objects.all().delete() self.adherent_list = {} subscription_mdl = apps.get_model("member", "Subscription") subscription_mdl.objects.all().delete() self.subscription_list = {} licence_mdl = apps.get_model("member", "License") licence_mdl.objects.all().delete() cur_a = self.old_db.open() cur_a.execute( "SELECT id, superId, DateNaissance, LieuNaissance FROM fr_sdlibre_membres_adherents") for adherentid, superid, date_naissance, lieu_naissance in cur_a.fetchall(): if superid in self.old_db.objectlinks['individual'].keys(): individual = self.old_db.objectlinks['individual'][superid] self.print_debug( "=> Adherent:%s", (six.text_type(individual),)) self.adherent_list[adherentid] = adherent_mdl( individual_ptr_id=individual.pk) self.adherent_list[adherentid].num = adherentid self.adherent_list[ adherentid].birthday = convert_date(date_naissance) if lieu_naissance is None: self.adherent_list[adherentid].birthplace = '' else: self.adherent_list[adherentid].birthplace = lieu_naissance self.adherent_list[adherentid].save(new_num=False) self.adherent_list[adherentid].__dict__.update( individual.__dict__) self.adherent_list[adherentid].save() cur_s = self.old_db.open() cur_s.execute( "SELECT id,adherentid,saisonid,type,end,begin,licence,equipe,activite,document,facture FROM fr_sdlibre_membres_licences") for subid, adherentid, saisonid, subtype, end, begin, licence, equipe, activite, document, facture in cur_s.fetchall(): if (adherentid in self.adherent_list.keys()) and (saisonid in self.season_list.keys()) and (subtype in self.subscriptiontype_list.keys()): self.print_debug( "=> Subscription:%s %s", (adherentid, saisonid)) begin = convert_date( begin, self.season_list[saisonid].begin_date) end = convert_date(end, self.season_list[saisonid].end_date) try: old_sub = subscription_mdl.objects.get_or_create(adherent=self.adherent_list[adherentid], season=self.season_list[ saisonid], subscriptiontype=self.subscriptiontype_list[subtype], begin_date=begin, end_date=end) except LucteriosException: if self.subscriptiontype_list[subtype].duration == 0: query_search = Q(season=self.season_list[saisonid]) else: query_search = (Q(begin_date__lte=end) & Q(end_date__gte=end)) | ( Q(begin_date__lte=begin) & Q(end_date__gte=begin)) old_sub = self.adherent_list[ adherentid].subscription_set.filter(query_search)[0] if isinstance(old_sub, tuple): old_sub = old_sub[0] self.subscription_list[subid] = old_sub if (facture is not None) and ('bill' in self.old_db.objectlinks.keys()): if facture in self.old_db.objectlinks['bill'].keys(): old_sub.bill = self.old_db.objectlinks['bill'][facture] old_sub.save() if (equipe in self.team_list.keys()) and (activite in self.activity_list.keys()): new_lic = licence_mdl.objects.create(subscription=old_sub, team=self.team_list[ equipe], activity=self.activity_list[activite]) if licence is not None: new_lic.value = licence new_lic.save() if document is not None: doc_idx = 0 for doc_item in document: doc_item = "%d_%d" % ( self.season_list[saisonid].id, doc_idx) if doc_item in self.doc_list.keys(): doc_adh = old_sub.docadherent_set.filter( document=self.doc_list[doc_item]) if len(doc_adh) > 0: doc_adh[0].value = doc_item == 'o' doc_idx += 1