Beispiel #1
0
def test_reverse_tva():
    total_ttc = 1196.0
    tva = 1960
    result = 1000
    assert reverse_tva(total_ttc, tva) == result

    total_ttc = 1200000
    tva = 2000
    result = 1000000
    assert reverse_tva(total_ttc, tva, False) == result

    total_ttc = 1000.0
    tva = 1960
    result = 836.12040
    assert reverse_tva(total_ttc, tva) == result
def test_reverse_tva():
    total_ttc = 1196.0
    tva = 1960
    result = 1000
    assert reverse_tva(total_ttc, tva) == result

    total_ttc = 1200000
    tva = 2000
    result = 1000000
    assert reverse_tva(total_ttc, tva, False) == result


    total_ttc = 1000.0
    tva = 1960
    result = 836.12040
    assert reverse_tva(total_ttc, tva) == result
Beispiel #3
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            user=user,
            company=self.company,
            project=self.project,
            customer=self.customer,
            phase_id=self.phase_id,
            address=self.address,
            workplace=self.workplace,
            description=self.description,
            invoice=self,
            expenses_ht=-1 * self.expenses_ht,
            financial_year=self.financial_year,
            display_units=self.display_units,
            business_type_id=self.business_type_id,
            business_id=self.business_id,
        )

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(
                group.gen_cancelinvoice_group()
            )
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity='',
            )
            discount_line.product_id = Product.first_by_tva_value(discount.tva)
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(
                    payment.amount,
                    payment.tva.value,
                    False,
                ),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity='NONE',
            )
            paid_line.product_id = Product.first_by_tva_value(payment.tva.value)
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        cancelinvoice.payment_conditions = u"Réglé"
        return cancelinvoice
Beispiel #4
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            user=user,
            company=self.company,
            project=self.project,
            customer=self.customer,
            phase_id=self.phase_id,
            address=self.address,
            workplace=self.workplace,
            description=self.description,
            invoice=self,
            expenses_ht=-1 * self.expenses_ht,
            financial_year=self.financial_year,
            display_units=self.display_units,
            business_type_id=self.business_type_id,
            business_id=self.business_id,
        )

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(
                group.gen_cancelinvoice_group()
            )
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity='',
            )
            discount_line.product_id = Product.first_by_tva_value(discount.tva)
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(
                    payment.amount,
                    payment.tva.value,
                    False,
                ),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity='NONE',
            )
            paid_line.product_id = Product.first_by_tva_value(payment.tva.value)
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        cancelinvoice.payment_conditions = u"Réglé"
        return cancelinvoice
Beispiel #5
0
 def get_amount(self):
     """
     Returns the reversed tva amount
     """
     tva_amount = self.payment.tva.value
     ht_value = reverse_tva(self.payment.amount, tva_amount)
     tva_value = compute_tva(ht_value, tva_amount)
     return floor(tva_value)
Beispiel #6
0
 def get_amount(self):
     """
     Returns the reversed tva amount
     """
     tva_amount = self.payment.tva.value
     ht_value = reverse_tva(self.payment.amount, tva_amount)
     tva_value = compute_tva(ht_value, tva_amount)
     return floor(tva_value)
Beispiel #7
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            company=self.company,
            project=self.project,
            customer=self.customer,
            phase=self.phase,
            user=user,
        )
        cancelinvoice.address = self.address
        cancelinvoice.workplace = self.workplace
        cancelinvoice.CAEStatus = 'draft'
        cancelinvoice.description = self.description

        cancelinvoice.invoice = self
        cancelinvoice.expenses_ht = -1 * self.expenses_ht
        cancelinvoice.financial_year = self.financial_year
        cancelinvoice.prefix = self.prefix
        cancelinvoice.display_units = self.display_units

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(group.gen_cancelinvoice_group())
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity='NONE',
            )
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(
                    payment.amount,
                    payment.tva.value,
                    False,
                ),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity='NONE',
            )
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        return cancelinvoice
Beispiel #8
0
    def manual_payment_line_amounts(self):
        """
            Computes the ht and tva needed to reach each payment line total

            self.payment_lines are configured with TTC amounts


            return a list of dict:
                [{tva1:ht_amount, tva2:ht_amount}]
            each dict represents a configured payment line
        """
        # Cette méthode recompose un paiement qui a été configuré TTC, sous
        # forme de part HT + TVA au regard des différentes tva configurées dans
        # le devis
        ret_data = []
        parts = self.tva_ht_parts()
        # On enlève déjà ce qui est inclu dans l'accompte
        for tva, ht_amount in self.deposit_amounts().items():
            parts[tva] -= ht_amount

        for payment in self.payment_lines[:-1]:
            payment_ttc = payment.amount
            payment_lines = {}

            for tva, total_ht in parts.items():
                payment_ht = math_utils.reverse_tva(
                    payment_ttc,
                    tva,
                    False,
                )
                if total_ht >= payment_ht:
                    # Le total ht de cette tranche de tva est suffisant pour
                    # recouvrir notre paiement
                    # on la récupère
                    payment_lines[tva] = payment_ht
                    # On enlève ce qu'on vient de prendre de la tranche de tva
                    # pour le calcul des autres paiements
                    parts[tva] = total_ht - payment_ht
                    ret_data.append(payment_lines)
                    break
                else:
                    # On a besoin d'une autre tranche de tva pour atteindre
                    # notre paiement, on prend déjà ce qu'il y a
                    payment_lines[tva] = parts.pop(tva)
                    # On enlève la part qu'on a récupéré dans cette tranche de
                    # tva du total de notre paiement
                    payment_ttc -= total_ht + math_utils.compute_tva(
                        total_ht,
                        tva,
                    )

        # Ce qui reste c'est donc pour notre facture de solde
        sold = parts
        ret_data.append(sold)
        return ret_data
Beispiel #9
0
    def manual_payment_line_amounts(self):
        """
            Computes the ht and tva needed to reach each payment line total

            self.payment_lines are configured with TTC amounts


            return a list of dict:
                [{tva1:ht_amount, tva2:ht_amount}]
            each dict represents a configured payment line
        """
        # Cette méthode recompose un paiement qui a été configuré TTC, sous
        # forme de part HT + TVA au regard des différentes tva configurées dans
        # le devis
        ret_data = []
        parts = self.tva_ht_parts()
        # On enlève déjà ce qui est inclu dans l'accompte
        for tva, ht_amount in self.deposit_amounts().items():
            parts[tva] -= ht_amount

        for payment in self.payment_lines[:-1]:
            payment_ttc = payment.amount
            payment_lines = {}

            for tva, total_ht in parts.items():
                payment_ht = math_utils.reverse_tva(
                    payment_ttc,
                    tva,
                    False,
                )
                if total_ht >= payment_ht:
                    # Le total ht de cette tranche de tva est suffisant pour
                    # recouvrir notre paiement
                    # on la récupère
                    payment_lines[tva] = payment_ht
                    # On enlève ce qu'on vient de prendre de la tranche de tva
                    # pour le calcul des autres paiements
                    parts[tva] = total_ht - payment_ht
                    ret_data.append(payment_lines)
                    break
                else:
                    # On a besoin d'une autre tranche de tva pour atteindre
                    # notre paiement, on prend déjà ce qu'il y a
                    payment_lines[tva] = parts.pop(tva)
                    # On enlève la part qu'on a récupéré dans cette tranche de
                    # tva du total de notre paiement
                    payment_ttc -= total_ht + math_utils.compute_tva(
                        total_ht,
                        tva,
                    )

        # Ce qui reste c'est donc pour notre facture de solde
        sold = parts
        ret_data.append(sold)
        return ret_data
Beispiel #10
0
    def gen_cancelinvoice(self, user):
        """
            Return a cancel invoice with self's informations
        """
        cancelinvoice = CancelInvoice(
            company=self.company, project=self.project, customer=self.customer, phase=self.phase, user=user
        )
        cancelinvoice.address = self.address
        cancelinvoice.workplace = self.workplace
        cancelinvoice.CAEStatus = "draft"
        cancelinvoice.description = self.description

        cancelinvoice.invoice = self
        cancelinvoice.expenses_ht = -1 * self.expenses_ht
        cancelinvoice.financial_year = self.financial_year
        cancelinvoice.prefix = self.prefix
        cancelinvoice.display_units = self.display_units

        cancelinvoice.line_groups = []
        for group in self.line_groups:
            cancelinvoice.line_groups.append(group.gen_cancelinvoice_group())
        order = self.get_next_row_index()

        for discount in self.discounts:
            discount_line = TaskLine(
                cost=discount.amount,
                tva=discount.tva,
                quantity=1,
                description=discount.description,
                order=order,
                unity="NONE",
            )
            order += 1
            cancelinvoice.default_line_group.lines.append(discount_line)

        for index, payment in enumerate(self.payments):
            paid_line = TaskLine(
                cost=math_utils.reverse_tva(payment.amount, payment.tva.value, False),
                tva=payment.tva.value,
                quantity=1,
                description=u"Paiement {0}".format(index + 1),
                order=order,
                unity="NONE",
            )
            order += 1
            cancelinvoice.default_line_group.lines.append(paid_line)
        cancelinvoice.mentions = self.mentions
        return cancelinvoice
Beispiel #11
0
def test_reverse_tva():
    total_ttc = 1100.0
    tva = 10 * 100
    result = 1000
    assert reverse_tva(total_ttc, tva) == result