get also invoice number during invoice generation
This commit is contained in:
parent
74250ffbf6
commit
ab14604e39
@ -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,
|
||||
|
||||
@ -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))
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user