Fix custom taxation without invoice addresses

This commit is contained in:
Raphael Michel
2018-05-28 16:23:34 +02:00
parent 86117091fe
commit 5383a8b77c
2 changed files with 14 additions and 12 deletions

View File

@@ -160,18 +160,19 @@ class TaxRule(LoggedModel):
def get_matching_rule(self, invoice_address): def get_matching_rule(self, invoice_address):
rules = json.loads(self.custom_rules) rules = json.loads(self.custom_rules)
for r in rules: if invoice_address:
if r['country'] == 'EU' and str(invoice_address.country) not in EU_COUNTRIES: for r in rules:
continue if r['country'] == 'EU' and str(invoice_address.country) not in EU_COUNTRIES:
if r['country'] not in ('ZZ', 'EU') and r['country'] != str(invoice_address.country): continue
continue if r['country'] not in ('ZZ', 'EU') and r['country'] != str(invoice_address.country):
if r['address_type'] == 'individual' and invoice_address.is_business: continue
continue if r['address_type'] == 'individual' and invoice_address.is_business:
if r['address_type'] in ('business', 'business_vat_id') and not invoice_address.is_business: continue
continue if r['address_type'] in ('business', 'business_vat_id') and not invoice_address.is_business:
if r['address_type'] == 'business_vat_id' and (not invoice_address.vat_id or not invoice_address.vat_id_validated): continue
continue if r['address_type'] == 'business_vat_id' and (not invoice_address.vat_id or not invoice_address.vat_id_validated):
return r continue
return r
return {'action': 'vat'} return {'action': 'vat'}
def is_reverse_charge(self, invoice_address): def is_reverse_charge(self, invoice_address):

View File

@@ -51,6 +51,7 @@
checked in order and once the first rule matches the order, it will be used and all further rules will checked in order and once the first rule matches the order, it will be used and all further rules will
be ignored. If no rule matches, tax will be charged. be ignored. If no rule matches, tax will be charged.
{% endblocktrans %} {% endblocktrans %}
{% trans "All of these rules will only apply if an invoice address is set." %}
</div> </div>
<div class="formset" data-formset data-formset-prefix="{{ formset.prefix }}"> <div class="formset" data-formset data-formset-prefix="{{ formset.prefix }}">