chore: rename schema to template & js cleanup

This commit is contained in:
Saqib Ansari
2020-09-29 18:39:13 +05:30
committed by Saurabh
parent 4d15506791
commit c3e0ff93d7
4 changed files with 5 additions and 44 deletions

View File

@@ -4,58 +4,18 @@
frappe.ui.form.on('E Invoice Settings', {
refresh: function(frm) {
if (!frm.doc.enable) return;
frm.trigger("show_fetch_token_btn");
frm.add_custom_button(__("Get GSTIN Details"),
() => {
frm.call({
doc: frm.doc,
method: 'get_gstin_details',
args: {
'gstin': '36AAECF1151A1ZC'
},
freeze: true,
callback: (res) => console.log(res)
});
});
frm.add_custom_button(__("Generate IRN"),
() => {
frm.call({
doc: frm.doc,
method: 'generate_irn',
args: {
'invoice': 'SINV-20-21-0051'
},
freeze: true,
callback: (res) => console.log(res)
});
});
frm.add_custom_button(__("Fetch IRN Details"),
() => {
frm.call({
doc: frm.doc,
method: 'get_irn_details',
args: {
'irn': 'c63d9e180dfdaa9242e29e2e1e0a8d76f20e116ed3de179a2e9120f384e1b432'
},
freeze: true,
callback: (res) => console.log(res)
});
});
},
show_fetch_token_btn(frm) {
const { token_expiry } = frm.doc;
const now = frappe.datetime.now_datetime();
const expiry_in_mins = moment(token_expiry).diff(now, "minute");
if (expiry_in_mins <= 1) {
if (expiry_in_mins <= 1 || !token_expiry) {
frm.add_custom_button(__("Fetch Token"),
() => {
frm.call({
doc: frm.doc,
method: 'make_authentication_request',
method: 'erpnext.regional.india.e_invoice_utils.fetch_token',
freeze: true,
callback: () => frm.refresh()
});

View File

@@ -65,6 +65,7 @@ def get_header(creds):
headers.update(dict(Gstin=creds.gstin, AuthToken=creds.auth_token))
return headers
@frappe.whitelist()
def fetch_token(self):
einv_creds = get_einv_credentials()
@@ -250,7 +251,7 @@ def get_item_list(invoice):
gst_accounts_list = [d for accounts in gst_accounts.values() for d in accounts if d]
for d in invoice.items:
item_schema = read_json("einv_item_schema")
item_schema = read_json("einv_item_template")
item = frappe._dict(dict())
item.update(d.as_dict())
item.sr_no = d.idx
@@ -331,7 +332,7 @@ def get_return_doc_reference(invoice):
))
def make_e_invoice(invoice):
schema = read_json("einv_schema")
schema = read_json("einv_template")
validations = read_json("einv_validation")
validations = json.loads(validations)