PyInvoice/pyinvoice/models.py

148 lines
4.7 KiB
Python
Raw Normal View History

from __future__ import unicode_literals
2015-06-09 14:20:04 +00:00
from decimal import Decimal
2015-05-28 10:17:55 +00:00
class PDFInfo(object):
2015-06-06 09:51:52 +00:00
"""
PDF Properties
"""
def __init__(self, title=None, author=None, subject=None):
"""
PDF Properties
:param title: PDF title
:type title: str or unicode
:param author: PDF author
:type author: str or unicode
:param subject: PDF subject
:type subject: str or unicode
"""
2015-05-28 10:17:55 +00:00
self.title = title
self.author = author
self.subject = subject
self.creator = 'PyInvoice (https://ciciapp.com/pyinvoice)'
2015-05-28 10:17:55 +00:00
2015-05-25 09:00:51 +00:00
class InvoiceInfo(object):
"""
Invoice information
"""
def __init__(self, invoice_id=None, invoice_datetime=None, due_datetime=None):
"""
Invoice info
:param invoice_id: Invoice id
:type invoice_id: int or str or unicode or None
:param invoice_datetime: Invoice create datetime
:type invoice_datetime: str or unicode or datetime or date
:param due_datetime: Invoice due datetime
:type due_datetime: str or unicode or datetime or date
"""
2015-05-25 09:00:51 +00:00
self.invoice_id = invoice_id
self.invoice_datetime = invoice_datetime
self.due_datetime = due_datetime
class AddressInfo(object):
def __init__(self, name=None, street=None, city=None, state=None, country=None, post_code=None):
"""
:type name: str or unicode or None
:type street: str or unicode or None
:type city: str or unicode or None
:type state: str or unicode or None
:type country: str or unicode or None
:type post_code: str or unicode or int or None
"""
2015-05-25 09:00:51 +00:00
self.name = name
self.street = street
self.city = city
self.state = state
self.country = country
self.post_code = post_code
class ServiceProviderInfo(AddressInfo):
"""
Service provider/Merchant information
"""
def __init__(self, name=None, street=None, city=None, state=None, country=None, post_code=None,
vat_tax_number=None):
"""
:type name: str or unicode or None
:type street: str or unicode or None
:type city: str or unicode or None
:type state: str or unicode or None
:type country: str or unicode or None
:type post_code: str or unicode or None
2015-06-11 13:23:28 +00:00
:type vat_tax_number: str or unicode or int or None
"""
2015-05-25 09:00:51 +00:00
super(ServiceProviderInfo, self).__init__(name, street, city, state, country, post_code)
2015-06-08 15:55:05 +00:00
self.vat_tax_number = vat_tax_number
2015-05-25 09:00:51 +00:00
class ClientInfo(AddressInfo):
"""
Client/Custom information
"""
def __init__(self, name=None, street=None, city=None, state=None, country=None, post_code=None,
email=None, client_id=None):
"""
:type name: str or unicode or None
:type street: str or unicode or None
:type city: str or unicode or None
:type state: str or unicode or None
:type country: str or unicode or None
:type post_code: str or unicode or None
:type email: str or unicode or None
2015-06-11 13:52:06 +00:00
:type client_id: str or unicode or int or None
"""
2015-05-25 09:00:51 +00:00
super(ClientInfo, self).__init__(name, street, city, state, country, post_code)
self.email = email
self.client_id = client_id
class Item(object):
"""
Product/Item information
"""
2015-06-09 14:20:04 +00:00
def __init__(self, name, description, units, unit_price):
2015-05-25 09:00:51 +00:00
"""
Item modal init
:param name: Item name
:type name: str or unicode or int
:param description: Item detail
:type description: str or unicode or int
2015-05-25 09:00:51 +00:00
:param units: Amount
:type units: int or str or unicode
2015-05-25 09:00:51 +00:00
:param unit_price: Unit price
2015-06-10 14:55:53 +00:00
:type unit_price: Decimal or str or unicode or int or float
2015-05-25 09:00:51 +00:00
:return:
"""
self.name = name
self.description = description
self.units = units
self.unit_price = unit_price
2015-06-09 14:20:04 +00:00
@property
def amount(self):
2015-06-10 14:55:53 +00:00
return int(self.units) * Decimal(str(self.unit_price))
2015-05-30 16:30:00 +00:00
2015-05-25 09:00:51 +00:00
class Transaction(object):
"""
Transaction information
"""
def __init__(self, gateway, transaction_id, transaction_datetime, amount):
2015-06-06 09:51:52 +00:00
"""
:param gateway: Payment gateway like Paypal, Stripe etc.
:type gateway: str or unicode
2015-06-06 09:51:52 +00:00
:param transaction_id:
:type transaction_id: int or str or unicode
2015-06-06 09:51:52 +00:00
:param transaction_datetime:
:type transaction_datetime: date or datetime or str or unicode
2015-06-06 09:51:52 +00:00
:param amount: $$
2015-06-11 14:17:42 +00:00
:type amount: int or float or str or unicode
2015-06-06 09:51:52 +00:00
:return:
"""
2015-05-25 09:00:51 +00:00
self.gateway = gateway
self.transaction_id = transaction_id
self.transaction_datetime = transaction_datetime
self.amount = amount