Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drobná pročištění, bugfix #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions fakturoid/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def load(self, id):
response = self.session._get('{0}/{1}'.format(self.endpoint, id))
return self.unpack(response)

def find(self, params={}, endpoint=None):
def find(self, params=None, endpoint=None):
if params is None:
params = {}
response = self.session._get(endpoint or self.endpoint, params=params)
return self.unpack(response)

Expand Down Expand Up @@ -216,12 +218,14 @@ class SubjectsApi(CrudModelApi):
model_type = Subject
endpoint = 'subjects'

def find(self, since=None):
def find(self, since=None, custom_id=None):
params = {}
if since:
if not isinstance(since, (datetime, date)):
raise TypeError("'since' parameter must be date or datetime")
params['since'] = since.isoformat()
if custom_id:
params['custom_id'] = custom_id
return ModelList(self, self.endpoint, params)


Expand All @@ -233,7 +237,9 @@ class InvoicesApi(CrudModelApi):

STATUSES = ['open', 'sent', 'overdue', 'paid', 'cancelled']

def find(self, proforma=None, subject_id=None, since=None, number=None, status=None):
def find(self,
proforma=None, subject_id=None, since=None, number=None,
status=None, custom_id=None):
params = {}
if subject_id:
if not isinstance(subject_id, int):
Expand All @@ -257,6 +263,9 @@ def find(self, proforma=None, subject_id=None, since=None, number=None, status=N
else:
endpoint = '{0}/regular'.format(self.endpoint)

if custom_id:
params['custom_id'] = custom_id

return ModelList(self, endpoint, params)


Expand Down
9 changes: 7 additions & 2 deletions fakturoid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ def serialize_field_value(self, field, value):
return value.isoformat()
return value

def get_fields(self):
def get_fields(self, include_readonly=False):
data = {}
for field, value in self.__dict__.items():
if self.is_field_writable(field, value):
if include_readonly or self.is_field_writable(field, value):
data[field] = self.serialize_field_value(field, value)
return data

Expand Down Expand Up @@ -136,6 +136,11 @@ def is_field_writable(self, field, value):
return False
return super(AbstractInvoice, self).is_field_writable(field, value)

def get_fields(self, include_readonly=False):
data = super(AbstractInvoice, self).get_fields(include_readonly)
data.pop('_loaded_lines', None)
return data


class Invoice(AbstractInvoice):
"""See http://docs.fakturoid.apiary.io/ for complete field reference."""
Expand Down
10 changes: 7 additions & 3 deletions fakturoid/paging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ def load_page(self, n):

def ensure_page_count(self):
if self.page_count is None:
#load any page to get page count from headers
self.get_page(0)
try:
self.get_page(0)
except IndexError:
self.page_count = 0

def get_page(self, n):
if self.page_count and n >= self.page_count:
if (self.page_count is not None) and n >= self.page_count:
raise IndexError('index out of range')
if n in self.pages:
return self.pages[n]
Expand All @@ -31,6 +33,8 @@ def get_page(self, n):

def __len__(self):
self.ensure_page_count()
if self.page_count == 0:
return 0
return self.page_size * (self.page_count-1) + len(self.get_page(self.page_count-1))

def __getitem__(self, key):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name='fakturoid',
version='1.0.1',
version='1.0.2',
url="https://github.com/farin/python-fakturoid",
description='Python API for fakturoid.cz',
#long_description=read('README.md'),
Expand Down