feat: read public key file

This commit is contained in:
Saqib Ansari
2020-09-25 21:27:50 +05:30
parent f396b35622
commit 18afbc0617
2 changed files with 21 additions and 3 deletions

View File

@@ -8,6 +8,7 @@
"client_id",
"client_secret",
"public_key_file",
"public_key",
"column_break_3",
"gstin",
"username",
@@ -54,12 +55,18 @@
"fieldtype": "Password",
"label": "Password",
"reqd": 1
},
{
"fieldname": "public_key",
"fieldtype": "Long Text",
"hidden": 1,
"read_only": 1
}
],
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2020-09-25 21:19:17.159664",
"modified": "2020-09-25 21:24:00.404460",
"modified_by": "Administrator",
"module": "ERPNext Integrations",
"name": "E Invoice Settings",

View File

@@ -3,8 +3,19 @@
# For license information, please see license.txt
from __future__ import unicode_literals
# import frappe
import frappe
from frappe.utils import cstr
from frappe.model.document import Document
class EInvoiceSettings(Document):
pass
def validate(self):
pass
def before_save(self):
if not self.public_key or self.has_value_changed('public_key_file'):
self.public_key = self.read_key_file()
def read_key_file(self):
key_file = frappe.get_doc('File', dict(attached_to_name=self.doctype, attached_to_field='public_key_file'))
with open(key_file.get_full_path(), 'rb') as f:
return cstr(f.read())