-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvoice.py
30 lines (24 loc) · 1.13 KB
/
invoice.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
from datetime import datetime
from helper_country import HelperCountry
class Invoice():
def __init__(self, service_provider, customer, service_amount):
self.service_provider = service_provider
self.customer = customer
if not isinstance(service_amount, (int, float)):
raise TypeError("Amount must be a number")
if service_amount < 0:
raise ValueError("Amount cannot be negative")
self.service_amount = service_amount
self.calculate_and_set_vat_and_subtotal()
self.created_at = datetime.now()
def calculate_and_set_vat_and_subtotal(self):
customer_country_data = HelperCountry.get_country_data(self.customer.country)
if (
not self.service_provider.is_vat_payer or
customer_country_data.get('region') != HelperCountry.EUROPE or
self.customer.is_vat_payer and self.customer.country != self.service_provider.country
):
self.vat = 0
else:
self.vat = round(self.service_amount * customer_country_data.get('vat') / 100, 2)
self.total = self.service_amount + self.vat