Guest User

Untitled

a guest
Jul 23rd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. class InterestLoanSet(models.QuerySet):
  2. def add_end_date(self):
  3. return self.annotate(loan_end_date=ExpressionWrapper(F('start_date') + relativedelta(months=+F('term'), output_field=DateField())))
  4.  
  5. def active_loans(self, start_date, end_date):
  6. return self.exclude(start_date__gt=end_date).add_end_date().exclude(loan_end_date__lt=start_date)
  7.  
  8.  
  9. class InterestLoan(AbstractTransaction):
  10. objects = InterestLoanSet.as_manager()
  11. interest_nominal_code = models.ForeignKey(NominalCode, null=False, on_delete=models.PROTECT)
  12. balance_nominal_code = models.ForeignKey(NominalCode, null=False, on_delete=models.PROTECT, related_name='loans')
  13. principal = models.DecimalField(max_digits=10, decimal_places=2)
  14. term = models.PositiveIntegerField()
  15. interest_rate = models.DecimalField(max_digits=4, decimal_places=4)
Add Comment
Please, Sign In to add comment