-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Adam Dawoodjee
authored and
Adam Dawoodjee
committed
Jun 25, 2024
0 parents
commit a33238d
Showing
10 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
doc_events = { | ||
"Sales Invoice": { | ||
"on_submit": "erpnext_zra_integration.modules.doctype.zra_invoice.zra_invoice.before_submit" | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"doctype": "DocType", | ||
"name": "ZRA Invoice", | ||
"module": "ERPNext ZRA Integration", | ||
"fields": [ | ||
{ | ||
"fieldname": "customer_name", | ||
"fieldtype": "Data", | ||
"label": "Customer Name", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "posting_date", | ||
"fieldtype": "Date", | ||
"label": "Posting Date", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "items", | ||
"fieldtype": "Table", | ||
"label": "Items", | ||
"options": "ZRA Invoice Item", | ||
"reqd": 1 | ||
} | ||
], | ||
"permissions": [ | ||
{ | ||
"role": "System Manager", | ||
"read": 1, | ||
"write": 1, | ||
"create": 1, | ||
"delete": 1 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import frappe | ||
from frappe.model.document import Document | ||
from erpnext_zra_integration.zra_api import ZRAAPI | ||
|
||
class ZRAInvoice(Document): | ||
def before_submit(self): | ||
settings = frappe.get_doc("ZRA Settings") | ||
zra_api = ZRAAPI( | ||
api_key=settings.api_key, | ||
device_serial_no=settings.device_serial_no, | ||
branch_id=settings.branch_id, | ||
tpin=settings.tpin | ||
) | ||
|
||
invoice_data = self.get_invoice_data() | ||
response = zra_api.submit_sales_invoice(invoice_data) | ||
|
||
if response.get('error'): | ||
frappe.throw(response['error']) | ||
|
||
def get_invoice_data(self): | ||
# Prepare the invoice data as required by the ZRA API | ||
invoice_data = { | ||
"invoice_no": self.name, | ||
"date": self.posting_date, | ||
"customer_name": self.customer_name, | ||
"items": [{ | ||
"item_code": item.item_code, | ||
"description": item.description, | ||
"quantity": item.qty, | ||
"rate": item.rate, | ||
"amount": item.amount | ||
} for item in self.items], | ||
# we We can Add other fields as needed | ||
} | ||
return invoice_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"doctype": "DocType", | ||
"name": "ZRA Settings", | ||
"module": "ERPNext ZRA Integration", | ||
"fields": [ | ||
{ | ||
"fieldname": "api_key", | ||
"fieldtype": "Data", | ||
"label": "API Key", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "device_serial_no", | ||
"fieldtype": "Data", | ||
"label": "Device Serial Number", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "branch_id", | ||
"fieldtype": "Data", | ||
"label": "Branch ID", | ||
"reqd": 1 | ||
}, | ||
{ | ||
"fieldname": "tpin", | ||
"fieldtype": "Data", | ||
"label": "TPIN", | ||
"reqd": 1 | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import frappe | ||
from frappe.model.document import Document | ||
|
||
class ZRASettings(Document): | ||
pass |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import requests | ||
import json | ||
|
||
class ZRAAPI: | ||
BASE_URL = "http://<hostname>:<server.port>/<vsdcpath>" | ||
|
||
def __init__(self, api_key, device_serial_no, branch_id, tpin): | ||
self.api_key = api_key | ||
self.device_serial_no = device_serial_no | ||
self.branch_id = branch_id | ||
self.tpin = tpin | ||
|
||
def initialize_device(self): | ||
url = f"{self.BASE_URL}/initializer/selectInitInfo" | ||
payload = { | ||
"tpin": self.tpin, | ||
"bhfId": self.branch_id, | ||
"dvcSrlNo": self.device_serial_no | ||
} | ||
headers = { | ||
'Content-Type': 'application/json', | ||
'Authorization': f'Bearer {self.api_key}' | ||
} | ||
response = requests.post(url, data=json.dumps(payload), headers=headers) | ||
return response.json() | ||
|
||
def submit_sales_invoice(self, invoice_data): | ||
url = f"{self.BASE_URL}/sales/newInvoice" | ||
headers = { | ||
'Content-Type': 'application/json', | ||
'Authorization': f'Bearer {self.api_key}' | ||
} | ||
response = requests.post(url, data=json.dumps(invoice_data), headers=headers) | ||
return response.json() | ||
|
||
# We can Add other methods as required by the VSDC API |