mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-06 23:10:26 +00:00
fix: download & upload e-invoice
This commit is contained in:
@@ -92,8 +92,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
{% for item in einvoice.ItemList %}
|
||||||
{% for item in einvoice.ItemList %}
|
<tr>
|
||||||
<td class="text-left" style="width: 3%;">{{ item.SlNo }}</td>
|
<td class="text-left" style="width: 3%;">{{ item.SlNo }}</td>
|
||||||
<td class="text-left">{{ item.PrdDesc }}</td>
|
<td class="text-left">{{ item.PrdDesc }}</td>
|
||||||
<td class="text-left" style="width: 10%;">{{ item.HsnCd }}</td>
|
<td class="text-left" style="width: 10%;">{{ item.HsnCd }}</td>
|
||||||
@@ -105,8 +105,8 @@
|
|||||||
<td class="text-right" style="width: 7%;">{{ item.GstRt + item.CesRt }} %</td>
|
<td class="text-right" style="width: 7%;">{{ item.GstRt + item.CesRt }} %</td>
|
||||||
<td class="text-right" style="width: 5%;">{{ frappe.utils.fmt_money(0, None, "INR") }}</td>
|
<td class="text-right" style="width: 5%;">{{ frappe.utils.fmt_money(0, None, "INR") }}</td>
|
||||||
<td class="text-right">{{ frappe.utils.fmt_money(item.TotItemVal, None, "INR") }}</td>
|
<td class="text-right">{{ frappe.utils.fmt_money(item.TotItemVal, None, "INR") }}</td>
|
||||||
{% endfor %}
|
</tr>
|
||||||
</tr>
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -473,7 +473,7 @@ def make_einvoice(doctype, name):
|
|||||||
else:
|
else:
|
||||||
frappe.throw(error_msgs[0], title=_('E Invoice Validation Failed'))
|
frappe.throw(error_msgs[0], title=_('E Invoice Validation Failed'))
|
||||||
|
|
||||||
return json.dumps(einvoice)
|
return {'einvoice': json.dumps([einvoice])}
|
||||||
|
|
||||||
def validate_einvoice(validations, einvoice, error_msgs=[]):
|
def validate_einvoice(validations, einvoice, error_msgs=[]):
|
||||||
type_map = { 'string': 'str', 'number': 'int', 'object': 'dict', 'array': 'list' }
|
type_map = { 'string': 'str', 'number': 'int', 'object': 'dict', 'array': 'list' }
|
||||||
@@ -503,8 +503,10 @@ def validate_einvoice(validations, einvoice, error_msgs=[]):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# convert to int or str
|
# convert to int or str
|
||||||
function = eval('c' + should_be_of_type)
|
if should_be_of_type == 'str':
|
||||||
einvoice[field] = function(invoice_value)
|
einvoice[field] = str(invoice_value)
|
||||||
|
elif should_be_of_type == 'int':
|
||||||
|
einvoice[field] = flt(invoice_value, 3)
|
||||||
|
|
||||||
max_length = validation.get('maxLength')
|
max_length = validation.get('maxLength')
|
||||||
minimum = flt(validation.get('minimum'))
|
minimum = flt(validation.get('minimum'))
|
||||||
@@ -527,6 +529,12 @@ def update_einvoice_fields(doctype, name, signed_einvoice):
|
|||||||
enc_signed_invoice = signed_einvoice.get('SignedInvoice')
|
enc_signed_invoice = signed_einvoice.get('SignedInvoice')
|
||||||
decrypted_signed_invoice = jwt_decrypt(enc_signed_invoice)['data']
|
decrypted_signed_invoice = jwt_decrypt(enc_signed_invoice)['data']
|
||||||
|
|
||||||
|
if json.loads(decrypted_signed_invoice)['DocDtls']['No'] != name:
|
||||||
|
frappe.throw(
|
||||||
|
_("Document number of uploaded Signed E-Invoice doesn't matches with Sales Invoice"),
|
||||||
|
title=_("Inappropriate E-Invoice")
|
||||||
|
)
|
||||||
|
|
||||||
frappe.db.set_value(doctype, name, 'irn', signed_einvoice.get('Irn'))
|
frappe.db.set_value(doctype, name, 'irn', signed_einvoice.get('Irn'))
|
||||||
frappe.db.set_value(doctype, name, 'ewaybill', signed_einvoice.get('EwbNo'))
|
frappe.db.set_value(doctype, name, 'ewaybill', signed_einvoice.get('EwbNo'))
|
||||||
frappe.db.set_value(doctype, name, 'signed_qr_code', signed_einvoice.get('SignedQRCode').split('.')[1])
|
frappe.db.set_value(doctype, name, 'signed_qr_code', signed_einvoice.get('SignedQRCode').split('.')[1])
|
||||||
@@ -551,6 +559,7 @@ def upload_einvoice():
|
|||||||
name = data['docname']
|
name = data['docname']
|
||||||
|
|
||||||
update_einvoice_fields(doctype, name, signed_einvoice)
|
update_einvoice_fields(doctype, name, signed_einvoice)
|
||||||
|
attach_qrcode_image(doctype, name)
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def download_cancel_einvoice():
|
def download_cancel_einvoice():
|
||||||
|
|||||||
@@ -9,197 +9,197 @@ erpnext.setup_einvoice_actions = (doctype) => {
|
|||||||
|
|
||||||
const { docstatus, irn, irn_cancelled, ewaybill, eway_bill_cancelled, doctype, name, __unsaved } = frm.doc;
|
const { docstatus, irn, irn_cancelled, ewaybill, eway_bill_cancelled, doctype, name, __unsaved } = frm.doc;
|
||||||
|
|
||||||
if (docstatus == 0 && !irn && !__unsaved) {
|
// if (docstatus == 0 && !irn && !__unsaved) {
|
||||||
frm.add_custom_button(
|
|
||||||
_("Generate IRN"),
|
|
||||||
() => {
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.generate_irn',
|
|
||||||
args: { doctype: doctype, name: name },
|
|
||||||
freeze: true,
|
|
||||||
callback: () => frm.reload_doc()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
__("E Invoicing")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (docstatus == 1 && irn && !irn_cancelled) {
|
|
||||||
frm.add_custom_button(
|
|
||||||
__("Cancel IRN"),
|
|
||||||
() => {
|
|
||||||
const fields = [
|
|
||||||
{
|
|
||||||
"label" : "Reason",
|
|
||||||
"fieldname": "reason",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"reqd": 1,
|
|
||||||
"default": "1-Duplicate",
|
|
||||||
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Remark",
|
|
||||||
"fieldname": "remark",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"reqd": 1
|
|
||||||
}
|
|
||||||
];
|
|
||||||
const d = new frappe.ui.Dialog({
|
|
||||||
title: __("Cancel IRN"),
|
|
||||||
fields: fields,
|
|
||||||
primary_action: function() {
|
|
||||||
const data = d.get_values();
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_irn',
|
|
||||||
args: {
|
|
||||||
doctype: doctype,
|
|
||||||
name: name,
|
|
||||||
irn: irn,
|
|
||||||
reason: data.reason.split('-')[0],
|
|
||||||
remark: data.remark
|
|
||||||
},
|
|
||||||
freeze: true,
|
|
||||||
callback: () => frm.reload_doc() || d.hide(),
|
|
||||||
error: () => d.hide()
|
|
||||||
});
|
|
||||||
},
|
|
||||||
primary_action_label: __('Submit')
|
|
||||||
});
|
|
||||||
d.show();
|
|
||||||
},
|
|
||||||
__("E Invoicing")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (docstatus == 1 && irn && !irn_cancelled && !eway_bill_cancelled) {
|
|
||||||
frm.add_custom_button(
|
|
||||||
__("Cancel E-Way Bill"),
|
|
||||||
() => {
|
|
||||||
const fields = [
|
|
||||||
{
|
|
||||||
"label" : "Reason",
|
|
||||||
"fieldname": "reason",
|
|
||||||
"fieldtype": "Select",
|
|
||||||
"reqd": 1,
|
|
||||||
"default": "1-Duplicate",
|
|
||||||
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Remark",
|
|
||||||
"fieldname": "remark",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"reqd": 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
const d = new frappe.ui.Dialog({
|
|
||||||
title: __('Cancel E-Way Bill'),
|
|
||||||
fields: fields,
|
|
||||||
primary_action: function() {
|
|
||||||
const data = d.get_values();
|
|
||||||
frappe.call({
|
|
||||||
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_eway_bill',
|
|
||||||
args: {
|
|
||||||
doctype: doctype,
|
|
||||||
name: name,
|
|
||||||
eway_bill: ewaybill,
|
|
||||||
reason: data.reason.split('-')[0],
|
|
||||||
remark: data.remark
|
|
||||||
},
|
|
||||||
freeze: true,
|
|
||||||
callback: () => frm.reload_doc() || d.hide(),
|
|
||||||
error: () => d.hide()
|
|
||||||
})
|
|
||||||
},
|
|
||||||
primary_action_label: __('Submit')
|
|
||||||
});
|
|
||||||
d.show();
|
|
||||||
},
|
|
||||||
__("E Invoicing")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (frm.doc.docstatus == 0 && !frm.doc.irn && !frm.doc.__unsaved) {
|
|
||||||
// frm.add_custom_button(
|
// frm.add_custom_button(
|
||||||
// "Download E-Invoice",
|
// _("Generate IRN"),
|
||||||
// () => {
|
// () => {
|
||||||
// frappe.call({
|
// frappe.call({
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.make_einvoice',
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.generate_irn',
|
||||||
// args: { doctype: frm.doc.doctype, name: frm.doc.name },
|
// args: { doctype: doctype, name: name },
|
||||||
// freeze: true,
|
// freeze: true,
|
||||||
// callback: (res) => {
|
// callback: () => frm.reload_doc()
|
||||||
// if (!res.exc) {
|
|
||||||
// const args = {
|
|
||||||
// cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_einvoice',
|
|
||||||
// einvoice: res.message.einvoice,
|
|
||||||
// name: frm.doc.name
|
|
||||||
// };
|
|
||||||
// open_url_post(frappe.request.url, args);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
// })
|
||||||
// }, "E-Invoicing");
|
// },
|
||||||
// frm.add_custom_button(
|
// __("E Invoicing")
|
||||||
// "Upload Signed E-Invoice",
|
// );
|
||||||
// () => {
|
|
||||||
// new frappe.ui.FileUploader({
|
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_einvoice',
|
|
||||||
// allow_multiple: 0,
|
|
||||||
// doctype: frm.doc.doctype,
|
|
||||||
// docname: frm.doc.name,
|
|
||||||
// on_success: (attachment, r) => {
|
|
||||||
// if (!r.exc) {
|
|
||||||
// frm.reload_doc();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }, "E-Invoicing");
|
|
||||||
// }
|
// }
|
||||||
// if (frm.doc.docstatus == 1 && frm.doc.irn && !frm.doc.irn_cancelled) {
|
|
||||||
|
// if (docstatus == 1 && irn && !irn_cancelled) {
|
||||||
// frm.add_custom_button(
|
// frm.add_custom_button(
|
||||||
// "Cancel IRN",
|
// __("Cancel IRN"),
|
||||||
// () => {
|
// () => {
|
||||||
|
// const fields = [
|
||||||
|
// {
|
||||||
|
// "label" : "Reason",
|
||||||
|
// "fieldname": "reason",
|
||||||
|
// "fieldtype": "Select",
|
||||||
|
// "reqd": 1,
|
||||||
|
// "default": "1-Duplicate",
|
||||||
|
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "label": "Remark",
|
||||||
|
// "fieldname": "remark",
|
||||||
|
// "fieldtype": "Data",
|
||||||
|
// "reqd": 1
|
||||||
|
// }
|
||||||
|
// ];
|
||||||
// const d = new frappe.ui.Dialog({
|
// const d = new frappe.ui.Dialog({
|
||||||
// title: __('Cancel IRN'),
|
// title: __("Cancel IRN"),
|
||||||
// fields: [
|
// fields: fields,
|
||||||
// {
|
|
||||||
// "label" : "Reason", "fieldname": "reason",
|
|
||||||
// "fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
|
||||||
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// "label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1
|
|
||||||
// }
|
|
||||||
// ],
|
|
||||||
// primary_action: function() {
|
// primary_action: function() {
|
||||||
// const data = d.get_values();
|
// const data = d.get_values();
|
||||||
// const args = {
|
// frappe.call({
|
||||||
// cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_cancel_einvoice',
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_irn',
|
||||||
// irn: frm.doc.irn, reason: data.reason.split('-')[0], remark: data.remark, name: frm.doc.name
|
// args: {
|
||||||
// };
|
// doctype: doctype,
|
||||||
// open_url_post(frappe.request.url, args);
|
// name: name,
|
||||||
// d.hide();
|
// irn: irn,
|
||||||
|
// reason: data.reason.split('-')[0],
|
||||||
|
// remark: data.remark
|
||||||
|
// },
|
||||||
|
// freeze: true,
|
||||||
|
// callback: () => frm.reload_doc() || d.hide(),
|
||||||
|
// error: () => d.hide()
|
||||||
|
// });
|
||||||
// },
|
// },
|
||||||
// primary_action_label: __('Download JSON')
|
// primary_action_label: __('Submit')
|
||||||
// });
|
// });
|
||||||
// d.show();
|
// d.show();
|
||||||
// }, "E-Invoicing");
|
// },
|
||||||
|
// __("E Invoicing")
|
||||||
// frm.add_custom_button(
|
// )
|
||||||
// "Upload Cancel JSON",
|
|
||||||
// () => {
|
|
||||||
// new frappe.ui.FileUploader({
|
|
||||||
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_cancel_ack',
|
|
||||||
// allow_multiple: 0,
|
|
||||||
// doctype: frm.doc.doctype,
|
|
||||||
// docname: frm.doc.name,
|
|
||||||
// on_success: (attachment, r) => {
|
|
||||||
// if (!r.exc) {
|
|
||||||
// frm.reload_doc();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }, "E-Invoicing");
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// if (docstatus == 1 && irn && !irn_cancelled && !eway_bill_cancelled) {
|
||||||
|
// frm.add_custom_button(
|
||||||
|
// __("Cancel E-Way Bill"),
|
||||||
|
// () => {
|
||||||
|
// const fields = [
|
||||||
|
// {
|
||||||
|
// "label" : "Reason",
|
||||||
|
// "fieldname": "reason",
|
||||||
|
// "fieldtype": "Select",
|
||||||
|
// "reqd": 1,
|
||||||
|
// "default": "1-Duplicate",
|
||||||
|
// "options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "label": "Remark",
|
||||||
|
// "fieldname": "remark",
|
||||||
|
// "fieldtype": "Data",
|
||||||
|
// "reqd": 1
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// const d = new frappe.ui.Dialog({
|
||||||
|
// title: __('Cancel E-Way Bill'),
|
||||||
|
// fields: fields,
|
||||||
|
// primary_action: function() {
|
||||||
|
// const data = d.get_values();
|
||||||
|
// frappe.call({
|
||||||
|
// method: 'erpnext.regional.india.e_invoice.e_invoice_utils.cancel_eway_bill',
|
||||||
|
// args: {
|
||||||
|
// doctype: doctype,
|
||||||
|
// name: name,
|
||||||
|
// eway_bill: ewaybill,
|
||||||
|
// reason: data.reason.split('-')[0],
|
||||||
|
// remark: data.remark
|
||||||
|
// },
|
||||||
|
// freeze: true,
|
||||||
|
// callback: () => frm.reload_doc() || d.hide(),
|
||||||
|
// error: () => d.hide()
|
||||||
|
// })
|
||||||
|
// },
|
||||||
|
// primary_action_label: __('Submit')
|
||||||
|
// });
|
||||||
|
// d.show();
|
||||||
|
// },
|
||||||
|
// __("E Invoicing")
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (docstatus == 0 && !irn && !__unsaved) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
"Download E-Invoice",
|
||||||
|
() => {
|
||||||
|
frappe.call({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.make_einvoice',
|
||||||
|
args: { doctype, name },
|
||||||
|
freeze: true,
|
||||||
|
callback: (res) => {
|
||||||
|
if (!res.exc) {
|
||||||
|
const args = {
|
||||||
|
cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_einvoice',
|
||||||
|
einvoice: res.message.einvoice,
|
||||||
|
name: name
|
||||||
|
};
|
||||||
|
open_url_post(frappe.request.url, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}, "E-Invoicing");
|
||||||
|
frm.add_custom_button(
|
||||||
|
"Upload Signed E-Invoice",
|
||||||
|
() => {
|
||||||
|
new frappe.ui.FileUploader({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_einvoice',
|
||||||
|
allow_multiple: 0,
|
||||||
|
doctype: doctype,
|
||||||
|
docname: name,
|
||||||
|
on_success: (attachment, r) => {
|
||||||
|
if (!r.exc) {
|
||||||
|
frm.reload_doc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, "E-Invoicing");
|
||||||
|
}
|
||||||
|
if (docstatus == 1 && irn && !irn_cancelled) {
|
||||||
|
frm.add_custom_button(
|
||||||
|
"Cancel IRN",
|
||||||
|
() => {
|
||||||
|
const d = new frappe.ui.Dialog({
|
||||||
|
title: __('Cancel IRN'),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
"label" : "Reason", "fieldname": "reason",
|
||||||
|
"fieldtype": "Select", "reqd": 1, "default": "1-Duplicate",
|
||||||
|
"options": ["1-Duplicate", "2-Data Entry Error", "3-Order Cancelled", "4-Other"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Remark", "fieldname": "remark", "fieldtype": "Data", "reqd": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
primary_action: function() {
|
||||||
|
const data = d.get_values();
|
||||||
|
const args = {
|
||||||
|
cmd: 'erpnext.regional.india.e_invoice.e_invoice_utils.download_cancel_einvoice',
|
||||||
|
irn: irn, reason: data.reason.split('-')[0], remark: data.remark, name: name
|
||||||
|
};
|
||||||
|
open_url_post(frappe.request.url, args);
|
||||||
|
d.hide();
|
||||||
|
},
|
||||||
|
primary_action_label: __('Download JSON')
|
||||||
|
});
|
||||||
|
d.show();
|
||||||
|
}, "E-Invoicing");
|
||||||
|
|
||||||
|
frm.add_custom_button(
|
||||||
|
"Upload Cancel JSON",
|
||||||
|
() => {
|
||||||
|
new frappe.ui.FileUploader({
|
||||||
|
method: 'erpnext.regional.india.e_invoice.e_invoice_utils.upload_cancel_ack',
|
||||||
|
allow_multiple: 0,
|
||||||
|
doctype: doctype,
|
||||||
|
docname: name,
|
||||||
|
on_success: (attachment, r) => {
|
||||||
|
if (!r.exc) {
|
||||||
|
frm.reload_doc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, "E-Invoicing");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user