Esempio n. 1
0
	def __init__(self, Emprunt_id = None,  User=None, Jeu=None,Exemplaire=None,date_emprunt=None,date_echeance=None,date_rendu=None):

		self.Emprunt_id = Emprunt_id   		#Id de l'emprunt
		self.User = User 			#Id de l'adhérent

		if Emprunt_id == None:
			# Test si l'exemplaire est disponible
			if EnsReservation.Reservation_EnCours(User) and EnsReservation.get_Reservation_User().get_Jeu() == self.Jeu:
				EnsReservation.supprimer_Reservation(EnsReservation.get_Reservation_User(User))
				print ("Reservation supprimé !")
			if EnsExemplaires.get_nombre_exemplaires(Jeu,disponible=1) > 0:
				self.Exemplaire = EnsExemplaires.get_Exemplaire_dispo(Jeu)
			else:
				self.Exemplaire=None
				print ("Oops, ce jeu n'est pas disponible !")
				raise
			self.date_rendu = date_rendu
			# PréCondition: Exemplaire Disponible !
			if (date_emprunt == None and self.Exemplaire.get_Est_disponible() and not(EnsEmprunt.a_un_emprunt_en_cours(User))):


				self.date_emprunt = date.today()
				# TEST DU retard
				#self.date_emprunt = date(2015,10,21)



				self.date_echeance = self.calcul_Date_Echeance()
				try:
					EnsExemplaires.get_Exemplaire(self.Exemplaire.get_Exemplaire_id()).set_Est_disponible(False)
					self.save()
					print ("Un emprunt a été créé !")
				except:
					print ("Oops, impossible d'emprunter, déjà un emprunt en cours ?!")
					raise
			else:
				print ("Oops ! Emprunt non valide !")
				raise
				self.date_emprunt = date_emprunt
				self.date_echeance = date_echeance
		else:
			self.Exemplaire=Exemplaire
			self.date_emprunt=date_emprunt
			self.date_echeance=date_echeance
			self.date_rendu=date_rendu