diff --git a/python_ifirma/core.py b/python_ifirma/core.py index 086213e..223a87e 100644 --- a/python_ifirma/core.py +++ b/python_ifirma/core.py @@ -160,12 +160,31 @@ class iFirmaAPI(): def generate_invoice(self, invoice): url = "https://www.ifirma.pl/iapi/fakturakraj.json" - return self.__create_invoice_and_return_id(invoice, url) + invoice_id = self.__create_invoice_and_return_id(invoice, url) + if invoice_id: + invoice_number = self.__get_invoice_number(invoice_id) + return invoice_id, invoice_number + return None, None def get_invoice_pdf(self, invoice_id): url = "https://www.ifirma.pl/iapi/fakturakraj/{}.pdf".format(invoice_id) return self.__download_pdf(url) + def __get_invoice_number(self, invoice_id): + url = "https://www.ifirma.pl/iapi/fakturakraj/{}.json".format(invoice_id) + request_hash_text = "{}{}{}".format( + url, + self.__username, + self.__invoice_key_name, + ) + headers = { + "Accept": "application/json", + "Content-type": "application/json; charset=UTF-8", + "Authentication": self.__create_authentication_header_value(request_hash_text) + } + resp = requests.get(url, headers=headers) + return json.loads(resp.content.decode('utf-8'))["response"]["PelnyNumer"] + def __download_pdf(self, url): request_hash_text = "{}{}{}".format( url, diff --git a/python_ifirma/tests.py b/python_ifirma/tests.py index b768266..246b9a3 100644 --- a/python_ifirma/tests.py +++ b/python_ifirma/tests.py @@ -117,6 +117,8 @@ class TestCreateInvoice(TestCase): def test_download_invoice(self): invoice = NewInvoiceParams(self.client, [self.position]) - invoice_id = self.ifirma_client.generate_invoice(invoice) + invoice_id, invoice_number = self.ifirma_client.generate_invoice(invoice) + self.assertIsNotNone(invoice_id) + self.assertIsNotNone(invoice_number) self.assertIsNotNone(self.ifirma_client.get_invoice_pdf(invoice_id)) \ No newline at end of file diff --git a/readme.md b/readme.md index 4f4727c..fa84ec4 100644 --- a/readme.md +++ b/readme.md @@ -55,16 +55,16 @@ client = Client( position = Position( VAT.VAT_23, # VAT rate 1, # Quantity - 1000, # Unit price + 1000.00, # Unit total price "nazwa", # Position name "szt" # Position unit ) ``` -#####3. Create invoice in iFirma service and get it's id +#####3. Create invoice in iFirma service and get it's id and number ```python invoice = NewInvoiceParams(client, [position]) -invoice_id = ifirma_client.generate_invoice(invoice) +invoice_id, invoice_number = ifirma_client.generate_invoice(invoice) ``` #####4. Download invoice PDF diff --git a/setup.py b/setup.py index 5651a90..2eaee35 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="python-ifirma", - version="0.0.3", + version="0.0.5", packages=find_packages(), install_requires=[ 'requests',