-
Notifications
You must be signed in to change notification settings - Fork 0
/
partner.py
41 lines (37 loc) · 1.47 KB
/
partner.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
from abc import ABC, abstractmethod
from helper_country import HelperCountry
from invoice import Invoice
class Partner(ABC):
@abstractmethod
def __init__(self, is_vat_payer, country):
"""
Inits a Partner.
Country must be a valid country from HelperCountry class.
"""
if not isinstance(is_vat_payer, bool):
raise TypeError("is_vat_payer must be a boolean")
if not HelperCountry.is_country_valid(country):
raise ValueError("Country is not valid")
self.is_vat_payer = is_vat_payer
self.country = country
class Customer(Partner):
def __init__(self, is_vat_payer, country, legal_entity):
super().__init__(is_vat_payer, country)
if not isinstance(legal_entity, bool):
raise TypeError("legal_entity must be a boolean")
self.legal_entity = legal_entity
class ServiceProvider(Partner):
def __init__(self, is_vat_payer, country):
super().__init__(is_vat_payer, country)
self.legal_entity = True
self.issued_invoices = []
def issue_invoice(self, customer, service_amount):
"""
Issues an invoice to a customer and
stores it in issued_invoices field
"""
if not isinstance(customer, Partner):
raise TypeError("Customer must be an object derived from partner class")
invoice = Invoice(self, customer, service_amount)
self.issued_invoices.append(invoice)
return invoice