-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhelper.py
42 lines (34 loc) · 1.46 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Teamleader Helper functions
"""
from teamleader.api import Teamleader
from teamleader.exceptions import InvalidInputError
def vat_liability_to_invoice(customer_vat_liability, tariff='21', service=False):
'''Determine invoice line vat term based on default tariff and customer VAT liability.
'''
tariff = str(tariff).zfill(2)
if tariff not in ['00', '06', '12', '21']:
raise InvalidInputError("Invalid VAT tariff.")
if customer_vat_liability == 'intra_community_eu':
return 'VCMD' if service else 'CM'
elif customer_vat_liability == 'vat_liable':
return tariff
elif customer_vat_liability == 'outside_eu':
return 'EX'
elif customer_vat_liability == 'unknown':
return tariff
elif customer_vat_liability == 'private_person':
return tariff
elif customer_vat_liability == 'not_vat_liable':
return '00'
elif customer_vat_liability == 'contractant':
return 'MC'
else:
raise InvalidInputError("Invalid customer VAT liability.")
def payment_term_to_invoice(customer_payment_term):
'''Determine invoice line payment term based on default tariff and customer VAT settings.
'''
invoice_payment_term = customer_payment_term.replace('_days', 'D').replace('_end_month', 'DEM')
if invoice_payment_term not in Teamleader._valid_payment_terms:
raise InvalidInputError("Invalid contents of argument customer_payment_term.")
return invoice_payment_term