-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(india): auto generate/cancel irn on invoice submit/cancel #30873
Conversation
38dea63
to
61e2efd
Compare
61e2efd
to
72e953b
Compare
@nextchamp-saqib cancel_irn_on_cancel function doesn't take into account when irn & ewaybill both are generated, this is due to logic being added on the client-side using einvoice.js instead of on the server-side inside utils.py cancel_irn function. I will also send PR for the same. I am also working on adding all of the crucial logic on the server-side to avoid these kinds of bugs and enable rapid development. |
3681b7c
to
4ebfd80
Compare
Problem: if IRN (e-invoice) cancellation is not successful due to any reason. invoice is still canceled so now the user doesn't have any way to cancel the e-invoice. some possible errors:
Suggestions:
|
85a1427
to
d62c656
Compare
Codecov Report
@@ Coverage Diff @@
## develop #30873 +/- ##
===========================================
+ Coverage 62.97% 63.26% +0.29%
===========================================
Files 986 986
Lines 67417 67523 +106
===========================================
+ Hits 42453 42719 +266
+ Misses 24964 24804 -160
|
(if error handling is fixed) There will be an error thrown right? The cancellation process would rollback
This problem existed even before. The way a user can cancel is to create a Credit Note or check IRN Cancelled manually and then cancel the invoice. This hasn't been documented anywhere and it is confusing.
If cancellation of IRN is successful and erpnext throws an error then the cancellation will be rolled backed but the IRN will be canceled on the portal. This was the reason |
This should fix it frappe/frappe#16855 |
It is possible to check "IRN Cancelled" and cancel the sales invoice while not cancelling the IRN on the portal. This creates confusion while auditing cancelled invoices on the portal
Hey, @maharshivpatel can you review/test this once again and let me know if you see any problems here? As per your previous comment, only one problem is unsolved. |
@nextchamp-saqib I will start testing soon meanwhile about that one problem that is unsolved I think we should do something like the below. this will increase the time limit to 72 hours and prevent accidental cancels. it should prevent all of the issues and provide better UX. what are your thoughts on this ? |
This is only applicable if the user chooses to opt for "auto-generate" functionality. If the user doesn't opt for "generate on submission" we would still need the validation. I would also suggest giving preference to manual IRN generation for new ERPNext users. As they are configuring the system this is the best option as this prevents most mistakes and gives a sense of control while previewing the details that are being sent to IRP. we should also add an option to show a preview dialog for "generate on submission" and if the user clicks on the primary button then "continue submission" else "rollback the submit. for example, we recently discovered that a user wrote the wrong item name ( Product A ) with the item code of ( Product B ) and the user added that item on SI as it showed up as ( Product B ) due to the item code. however, when we generate IRN, the item name would be sent to IRP so the wrong item name ( Product A ) this mistake was prevented as the name ( Product A ) showed up in Preview. moral of the story is previewing details before sending is great functionality and we should not remove it even for "generate on submission" we can add an option to enable/disable it for UX. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When API response is "success": false, It throws an error as expected but it doesn't roll back the submit.
@@ -885,7 +885,10 @@ def log_request(self, url, headers, data, res): | |||
} | |||
) | |||
request_log.save(ignore_permissions=True) | |||
frappe.db.commit() | |||
|
|||
if (self.invoice.doctype, self.invoice.name) not in frappe.flags.currently_saving: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (self.invoice.doctype, self.invoice.name) not in frappe.flags.currently_saving:
This Prevents E-invoice Request Log ( logging ).
It should log failed request even if it was made using hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was aware of this.
The problem is we can't run frappe.db.commit
as it will commit all the previous changes to the db
and lead to partial submissions in case
If IRN is to be generated on submission and submission is just one single process, then we'll have to prevent commit
unless the submission is successful
Do you have any solution for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry but I don't have an elegant way to share this. You can find relevant code by looking at the line number.
@nextchamp-saqib I think something like this will work instead of preventing commit what if we rollback the changes and then commit.
what I have done is as follows
if success is true it will run log_request else save variables [ url, header, and data ].
if success is false then RequestFailed will be raised and it will call set_failed_status which will rollback changes and then run log_request if It is run from the hook it will commit (with changes rollbacked )
If it was ran by hook get the current committed docstatus from db and set it to invoice docstatus then commit changes. In this case, submit is failed so it won't commit anything (rollback) so we do want to commit . It is safe to commit log_request after set_failed_status committed (rollbacked)
what do you think of this? are there any downsides?
If you want to test this manually add IGST & SGST both taxes and then try to submit you will receive an error [ For Sl. No 1, GST rate of tax is incorrect or not as notified ] but the invoice will still be submitted. |
There's one more problem here. The solution to this is to have a confirmation dialog if the invoice is eligible for e-invoicing. But editing/customizing the default submit confirmation is not possible as of now @maharshivpatel Let me know if you see any other fix for this. |
@nextchamp-saqib how do you feel about unbinding submit function using jquery and using our own function like as below? can you give write access to the PR branch? It will be easy to share and compare code changes. |
@@ -13,13 +13,15 @@ erpnext.setup_einvoice_actions = (doctype) => { | |||
|
|||
const { doctype, irn, irn_cancelled, ewaybill, eway_bill_cancelled, name, __unsaved } = frm.doc; | |||
|
|||
const automate_irns = await frappe.db.get_single_value('E Invoice Settings', 'automate_irns'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if automate_irns is true user doesn't get to use generate e-way bill dialog to generate the e-way bill after submitting the doc which is possible behavior and is currently being used in the case of the manual IRN generation process.
This pull request has been automatically marked as inactive because it has not had recent activity. It will be closed within 3 days if no further activity occurs, but it only takes a comment to keep a contribution alive :) Also, even if it is closed, you can always reopen the PR when you're ready. Thank you for contributing. |
Added a check in E Invoice Settings
On cancellation, Reason & Remark is by default set as '3' & 'Cancelled by user' respectively
Do not allow manual IRN cancellations (ref. #26638)