def monthlyData(self, year, excelCellInfoPerDate=None): #find columns in this sheet which represent months allMonths = sorted([k for k in self.__dict__ if dates.datify(k, year)], key=(lambda dateColumn: dates.datify(dateColumn))) #build monthly expected payments table monthlyExpectedPaymentOf = {} #if there are different expected payment throughtout this sheet, then monthlyColumns gets updated #ar the c'tor of the excel record if len(self.monthlyColumns): currExpectedPayment = self.payment for m in allMonths: if int(m) in self.monthlyColumns: currExpectedPayment = utils.Intify( excel_utils.ExtractCellValueByColumn( self, 'ת.חודשי_%d' % int(m))) monthlyExpectedPaymentOf[m] = currExpectedPayment else: for m in allMonths: monthlyExpectedPaymentOf[m] = utils.Intify(self.payment) for month in allMonths: cell_info = excelCellInfoPerDate[dates.datify(month, year)] expected_payment = monthlyExpectedPaymentOf[month] actual_payment = utils.Intify(self.monthlyPayment(month)) cell_info.payment_details.actual_payment = actual_payment cell_info.payment_details.expected_payment = expected_payment
def monthlyData(self, year, excelCellInfoPerDate=None): #find columns in this sheet which represent months allMonths = sorted([k for k in self.__dict__ if dates.datify(k, year)], key=(lambda dateColumn: dates.datify(dateColumn))) #build monthly expected payments table monthlyExpectedPaymentOf = {} #if there are different expected payment throughtout this sheet, then monthlyColumns gets updated #ar the c'tor of the excel record if len(self.monthlyColumns): currExpectedPayment = self.payment for m in allMonths: if m in self.monthlyColumns: currExpectedPayment = int( getattr(self, 'תשלום חודשי_%d' % m)) monthlyExpectedPaymentOf[m] = currExpectedPayment else: for m in allMonths: monthlyExpectedPaymentOf[m] = utils.Intify(self.payment) #calculate how much was paid during the whole period total_paid = sum( utils.Intify(self.monthlyPayment(month)) for month in allMonths if self.monthlyPayment(month) is not None) for month in allMonths: cell_info = excelCellInfoPerDate[dates.datify(month, year)] expected_payment = monthlyExpectedPaymentOf[month] if not total_paid: actual_payment = 0 else: if total_paid >= expected_payment: actual_payment = expected_payment else: actual_payment = total_paid total_paid -= actual_payment cell_info.payment_details.actual_payment = actual_payment cell_info.payment_details.expected_payment = expected_payment