def _readConfig(self): ''' ''' defaultConfig = { 'locataire': 'Locataire', 'start': '11/8/2018', 'end': '25/8/2018', 'automatic': True, 'price': 1600, 'cleaning': 70, 'avelmor': True, 'tyagathe': False, 'tytania': False, 'typapy': False, 'cleaninginc': False, } config = copy(defaultConfig) try: filename = 'contrats.ini' if not isfile(filename): return defaultConfig # end if with open(filename, 'r') as f: lines = f.readlines() # end with for line in lines: pos = line.find('=') if pos == -1: continue # end if key = line[:pos].strip() value = line[pos + 1:].strip() if key not in defaultConfig.keys(): return defaultConfig else: if value.lower() == 'true': value = True elif value.lower() == 'false': value = False # end if if key in ['start', 'end']: DateTools.strToDate(value) # end if config[key] = value # end if # end for except: return defaultConfig # end try return config
def _getSeason(self, start, end): ''' ''' for s in Seasons: if (DateTools.strToDate(start) >= DateTools.strToDate(s.start)) \ and (DateTools.strToDate(end) <= DateTools.strToDate(s.end)): return s.seasonType # end if # end for raise ValueError('Saison non définie pour la période du %s au %s' % (start, end))
def _getHousePrice(self, houseName, weekList): ''' ''' totalPrice = 0 cleaning = None for start, end in weekList: duration = (end - start).days assert ((duration <= 7) and (duration > 0)) season = self._getSeason(start, end) house = Houses[houseName] priceWeek = PRICE_WEEK[house.name][season] priceNight = 30000 if season in PRICE_NIGHT[house.name]: priceNight = PRICE_NIGHT[house.name][season] else: self.logger.log('Pas de tarif à la nuit cette saison') # end if pricePerNight = self._duration * priceNight if (duration == 7) or (pricePerNight > priceWeek): # Duration = a week or price for a week is smaller housePrice = priceWeek cleaning = PRICE_WEEK[house.name][CLEANING] else: # Price housePrice = pricePerNight cleaning = PRICE_NIGHT[house.name][CLEANING] # end if self.logger.log('Prix pour %s (%s au %s): %d Euros' % (houseName, DateTools.shortDate(start), DateTools.shortDate(end), housePrice)) totalPrice += housePrice # end for self.logger.log('Ménage pour %s : %d Euros' % (houseName, cleaning)) addText = '' if self._cleaningInc: totalPrice += cleaning addText = ' (ménage inclus)' # end if self.logger.log('Total pour %s : %d Euros %s' % (houseName, totalPrice, addText)) return (totalPrice, cleaning)
def logError(self, msg): ''' ''' print(msg) msg = '%s - %s' % (DateTools.isoDate(datetime.now()), msg) with open(self.logFile, 'a') as f: f.write(msg)
def _getLocatairePdf(self): ''' ''' odtFile = self.templateOdt assert (odtFile[-4:].lower() == '.odt') assert (odtFile[:4].upper() == 'TMP_') filename = '%s_%s_%s.pdf' % (odtFile[4:-4], self._locataire.replace(' ', ''), DateTools.isoDate(self._start)) return join(self._outputdir, filename)
def _saveConfig(self): ''' ''' config = {} config['locataire'] = self._locataire config['start'] = DateTools.shortDate(self._start) config['end'] = DateTools.shortDate(self._end) config['automatic'] = self._automatic config['price'] = self._price config['cleaning'] = self._cleaning config['avelmor'] = self._avelMor config['tyagathe'] = self._tyAgathe config['tytania'] = self._tyTania config['typapy'] = self._tyPapy config['cleaninginc'] = self._cleaningInc filename = 'contrats.ini' with open(filename, 'w') as f: for key, value in config.items(): f.write('%s = %s\n' % (key, value))
def _replaceFields(self): ''' ''' self.logger.logDbg('replaceFields...') subList = ( ('__locataire__', self._locataire), ('__gites__', ', '.join(self._houseList)), ('__validite__', DateTools.fullDate(date.today() + timedelta(7))), ('__arrivee__', DateTools.fullDate(self._start)), ('__depart__', DateTools.fullDate(self._end)), ('__ratio__', ('%d' % self._ratio)), ('__loyer__', self._formatPrice(self._price)), ('__reste__', self._formatPrice(self._price * (1 - self._ratio / 100))), ('__arrhes__', self._formatPrice(self._price * self._ratio / 100)), ('__lits__', ('%d' % self._beds)), ('__caution__', ('%d' % self._deposit)), ) for tag, value in subList: self._content = re.sub(tag, value, self._content) # end for # Fill __menage__ if self._cleaningInc: cleaning = '(ménage inclus)' else: cleaning = '%s Euros' % self._formatPrice(self._cleaning) # end if self._content = re.sub('__menage__', cleaning, self._content) offset = self._content.find('__') if (offset != -1): raise ValueError('Il reste la balise %s...' % self._content[offset:offset + 15])
def _setend(self, end): self._setText('end', DateTools.shortDate(end))
def _getend(self): return DateTools.strToDate(self._getText('end'))
def _setstart(self, start): self._setText('start', DateTools.shortDate(start))
def _getstart(self): return DateTools.strToDate(self._getText('start'), source='Début de location')