def discount(self): """The AllowanceTotalAmount of the Invoice. """ if self._discount_amount is not None: return self._discount_amount else: return MyMoney('0', self._currency)
def charge(self): """The ChargeTotalAmount of the Invoice. """ if self._charge_amount is not None: return self._charge_amount else: return MyMoney('0', self._currency)
def parse_money(amount, currency): if amount is None: return None elif isinstance(amount, MyMoney): return amount try: return MyMoney(amount, currency) except InvalidOperation: raise ValueError('Could not convert {} to money'.format(amount))
def payable_amount(self): """The total PayableAmount of the invoice. It's only computed as the :meth:`total` if the Invoice was not imported from an XML file. In that case, its value is the one reported on the XML. """ if self._payable_amount is not None: return self._payable_amount # TODO PrepaidAmount prepaid_amount = MyMoney('0', self._currency) return self.total() - prepaid_amount
def tax_amount(self, tax_type=None): """Computes the tax amount of the Invoice. Parameters ---------- tax_type: Tax object (default None). If a Tax object is provided, the tax amount corresponding to the porvided Tax. If None the total tax amount. """ if tax_type is None: taxes = self.unique_taxes else: taxes = {tax_type} result = (self.taxable_base(tax_type=tax) * tax.percent for tax in taxes) return sum(result, MyMoney('0', self._currency))
def discount_amount(self): """Property: The AllowanceTotalAmount of the Invoice. Parameters ---------- value: string, integer, float The input must be a valid input for the Decimal class the Python Standard Library. Raises ------ decimal.InvalidOperation: If the input cannot be converted to a Decimal. """ if self._discount_amount is not None: return self._discount_amount else: return MyMoney('0', self._currency)
def gross_subtotal(self, tax_type=None): """Sum of gross amount of each invoice line.""" amounts = (line.line_extension_amount for line in self.lines_with_taxes(tax_type=tax_type)) return sum(amounts, MyMoney('0', self._currency))