Beispiel #1
0
def test_custom_rules_business(event):
    tr = TaxRule(event=event,
                 rate=Decimal('10.00'),
                 price_includes_tax=False,
                 custom_rules=json.dumps([
                     {
                         'country': 'ZZ',
                         'address_type': 'business',
                         'action': 'no'
                     },
                 ]))
    ia = InvoiceAddress(is_business=True, country=Country('AT'))
    assert not tr.is_reverse_charge(ia)
    assert not tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('0.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('100.00'),
        net=Decimal('100.00'),
        tax=Decimal('0.00'),
        rate=Decimal('0.00'),
        name='',
    )

    ia = InvoiceAddress(is_business=False, country=Country('DE'))
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('10.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('100.00'),
        tax=Decimal('10.00'),
        rate=Decimal('10.00'),
        name='',
    )
Beispiel #2
0
def test_custom_rules_country_rate_subtract_from_gross(event):
    tr = TaxRule(event=event,
                 rate=Decimal('10.00'),
                 price_includes_tax=False,
                 custom_rules=json.dumps([
                     {
                         'country': 'EU',
                         'address_type': 'business_vat_id',
                         'action': 'vat',
                         'rate': '100.00'
                     },
                 ]))
    ia = InvoiceAddress(is_business=True,
                        country=Country('DE'),
                        vat_id='DE1234',
                        vat_id_validated=True)
    assert tr.tax_rate_for(ia) == Decimal('100.00')
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax(
        Decimal('100.00'),
        invoice_address=ia,
        subtract_from_gross=Decimal('20.00')) == TaxedPrice(
            gross=Decimal(
                '163.64'),  # ((100 * 1.1) - 20) / (1 + 10%) * (1 + 100%)
            net=Decimal('81.82'),
            tax=Decimal('81.82'),
            rate=Decimal('100.00'),
            name='',
        )
Beispiel #3
0
def test_from_net_price(event):
    tr = TaxRule(event=event, rate=Decimal('10.00'), price_includes_tax=False)
    tp = tr.tax(Decimal('100.00'))
    assert tp.gross == Decimal('110.00')
    assert tp.net == Decimal('100.00')
    assert tp.tax == Decimal('10.00')
    assert tp.rate == Decimal('10.00')
Beispiel #4
0
def test_from_gross_price(event):
    tr = TaxRule(event=event, rate=Decimal('10.00'), price_includes_tax=True)
    tp = tr.tax(Decimal('100.00'))
    assert tp.gross == Decimal('100')
    assert tp.net == Decimal('90.91')
    assert tp.tax == Decimal('100.00') - Decimal('90.91')
    assert tp.rate == Decimal('10.00')
Beispiel #5
0
def test_custom_rules_override(event):
    tr = TaxRule(event=event,
                 eu_reverse_charge=True,
                 home_country=Country('DE'),
                 rate=Decimal('10.00'),
                 price_includes_tax=False,
                 custom_rules=json.dumps([{
                     'country': 'ZZ',
                     'address_type': '',
                     'action': 'vat'
                 }]))
    ia = InvoiceAddress(is_business=True,
                        vat_id='AT12346',
                        vat_id_validated=True,
                        country=Country('AT'))
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('10.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('100.00'),
        tax=Decimal('10.00'),
        rate=Decimal('10.00'),
        name='',
    )
Beispiel #6
0
def test_custom_rules_country_rate_keep_gross_if_rate_changes(event):
    tr = TaxRule(event=event,
                 rate=Decimal('10.00'),
                 price_includes_tax=False,
                 keep_gross_if_rate_changes=True,
                 custom_rules=json.dumps([
                     {
                         'country': 'EU',
                         'address_type': 'business_vat_id',
                         'action': 'vat',
                         'rate': '100.00'
                     },
                 ]))
    ia = InvoiceAddress(is_business=True, country=Country('DE'))
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('10.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('100.00'),
        tax=Decimal('10.00'),
        rate=Decimal('10.00'),
        name='',
    )
    ia = InvoiceAddress(is_business=True,
                        country=Country('DE'),
                        vat_id='DE1234',
                        vat_id_validated=True)
    assert tr.tax_rate_for(ia) == Decimal('100.00')
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('55.00'),
        tax=Decimal('55.00'),
        rate=Decimal('100.00'),
        name='',
    )
Beispiel #7
0
def test_reverse_charge_no_country(event):
    tr = TaxRule(event=event,
                 eu_reverse_charge=True,
                 rate=Decimal('10.00'),
                 price_includes_tax=False)
    ia = InvoiceAddress()
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('10.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('100.00'),
        tax=Decimal('10.00'),
        rate=Decimal('10.00'),
        name='',
    )
Beispiel #8
0
def test_reverse_charge_individual_3rdc(event):
    tr = TaxRule(event=event,
                 eu_reverse_charge=True,
                 home_country=Country('DE'),
                 rate=Decimal('10.00'),
                 price_includes_tax=False)
    ia = InvoiceAddress(is_business=False, country=Country('US'))
    assert not tr.is_reverse_charge(ia)
    assert not tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('0.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('100.00'),
        net=Decimal('100.00'),
        tax=Decimal('0.00'),
        rate=Decimal('0.00'),
        name='',
    )
Beispiel #9
0
def test_reverse_charge_disabled(event):
    tr = TaxRule(event=event,
                 eu_reverse_charge=False,
                 home_country=Country('DE'),
                 rate=Decimal('10.00'),
                 price_includes_tax=False)
    ia = InvoiceAddress(is_business=True,
                        vat_id='AT12346',
                        vat_id_validated=True,
                        country=Country('AT'))
    assert not tr.is_reverse_charge(ia)
    assert tr._tax_applicable(ia)
    assert tr.tax_rate_for(ia) == Decimal('10.00')
    assert tr.tax(Decimal('100.00'), invoice_address=ia) == TaxedPrice(
        gross=Decimal('110.00'),
        net=Decimal('100.00'),
        tax=Decimal('10.00'),
        rate=Decimal('10.00'),
        name='',
    )