Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Dawoodjee authored and Adam Dawoodjee committed Jun 25, 2024
0 parents commit a33238d
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions hooks.py
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 added modules/.DS_Store
Binary file not shown.
Binary file added modules/doctype/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions modules/doctype/zra_invoice/zra_invoice.json
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
}
]
}
36 changes: 36 additions & 0 deletions modules/doctype/zra_invoice/zra_invoice.py
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
31 changes: 31 additions & 0 deletions modules/doctype/zra_settings/zra_settings.json
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
}
]
}
5 changes: 5 additions & 0 deletions modules/doctype/zra_settings/zra_settings.py
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 added public/.DS_Store
Binary file not shown.
36 changes: 36 additions & 0 deletions zra_api.py
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

0 comments on commit a33238d

Please sign in to comment.