Ejemplo n.º 1
0
 def get_balance(self, acc: Account) -> Decimal:
     """
     Returns balance of this invoice on specified account.
     :param acc: Account
     :return:
     """
     return sum_queryset(self.get_entries(acc))
Ejemplo n.º 2
0
 def get_balance(self, t: datetime):
     """
     Returns account balance before specified datetime (excluding entries on the datetime).
     :param t: datetime
     :return: Decimal
     """
     return sum_queryset(
         self.accountentry_set.all().filter(timestamp__lt=t))
Ejemplo n.º 3
0
 def balance(self) -> Decimal:
     """
     Returns account balance after this entry.
     :return: Decimal
     """
     return sum_queryset(
         AccountEntry.objects.filter(account=self.account,
                                     timestamp__lte=self.timestamp).exclude(
                                         timestamp=self.timestamp,
                                         id__gt=self.id))
Ejemplo n.º 4
0
 def get_close_date(self) -> datetime:
     recv = self.receivables.order_by('-timestamp', '-id')
     first = recv.first()
     if first is None:
         return None
     total = sum_queryset(recv)
     if self.type == INVOICE_CREDIT_NOTE:
         if total >= Decimal('0.00'):
             return first.timestamp
     else:
         if total <= Decimal('0.00'):
             return first.timestamp
     return None
Ejemplo n.º 5
0
 def get_close_date(self) -> Optional[datetime]:
     recv = self.receivables.order_by("-timestamp", "-id")
     first = recv.first()
     if first is None:
         return None
     total = sum_queryset(recv)
     if self.type == INVOICE_CREDIT_NOTE:
         if total >= Decimal("0.00"):
             return first.timestamp
     else:
         if total <= Decimal("0.00"):
             return first.timestamp
     return None
Ejemplo n.º 6
0
 def get_item_balances(self, acc: Account) -> list:
     """
     Returns balances of items of the invoice.
     :param acc: Account
     :return: list (AccountEntry, Decimal) in item id order
     """
     items = []
     entries = self.get_entries(acc)
     for item in entries.filter(source_invoice=self).order_by('id'):
         assert isinstance(item, AccountEntry)
         settlements = sum_queryset(entries.filter(settled_item=item))
         bal = item.amount + settlements if item.amount is not None else settlements
         items.append((item, bal))
     return items
Ejemplo n.º 7
0
 def get_overpaid_amount(self) -> Decimal:
     if self.type == INVOICE_CREDIT_NOTE:
         return max(Decimal('0.00'), sum_queryset(self.receivables))
     else:
         return max(Decimal('0.00'), -sum_queryset(self.receivables))
Ejemplo n.º 8
0
 def get_unpaid_amount(self) -> Decimal:
     return sum_queryset(self.receivables)
Ejemplo n.º 9
0
 def get_amount(self) -> Decimal:
     return sum_queryset(self.items, 'amount')
Ejemplo n.º 10
0
 def balance(self) -> Decimal:
     return sum_queryset(self.accountentry_set.all())
Ejemplo n.º 11
0
 def get_overpaid_amount(self) -> Decimal:
     amt = sum_queryset(self.receivables)
     if self.type == INVOICE_CREDIT_NOTE:
         return max(Decimal("0.00"), amt)
     return max(Decimal("0.00"), -amt)
Ejemplo n.º 12
0
 def get_total_amount(self, force: bool = False) -> Decimal:
     if self.cached_total_amount is None or force:
         self.cached_total_amount = sum_queryset(ReferencePaymentRecord.objects.filter(batch__file=self))
         self.save(update_fields=["cached_total_amount"])
     return self.cached_total_amount
Ejemplo n.º 13
0
 def is_settled(self) -> bool:
     """
     True if entry is either manually settled or has SUM(children)==amount.
     """
     return self.manually_settled or sum_queryset(self.child_set) == self.amount  # type: ignore