Skip to content
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

fix: fetch overdue payments in dunning #42627

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Nihantra-Patel
Copy link
Contributor

version 15

fixes: #42605

Before:

before_dunning.mp4

After:

after_dunning.mp4

@github-actions github-actions bot added the needs-tests This PR needs automated unit-tests. label Aug 5, 2024
@tonspar
Copy link
Contributor

tonspar commented Aug 8, 2024

Perfect, thank you @Nihantra-Patel .

@daanlenaerts
Copy link

daanlenaerts commented Aug 12, 2024

Hi @Nihantra-Patel, I found this issue because I was having the same problem with generating dunnings. Your changes do fix the problem, but I'm not sure there are no unintended side effects. Why do you add source.payment_schedule = [] instead of removing the next 2 lines? Which would have the same effect. I assume there's some reason these lines exist?

# update outstanding
source.payment_schedule = []
if source.payment_schedule and len(source.payment_schedule) == 1:
	target.overdue_payments[0].outstanding = source.get("outstanding_amount")

@Nihantra-Patel
Copy link
Contributor Author

Lines you had were clearing out source.payment_schedule and handling only the case when there was just one payment schedule. This caused issues because you were losing data. Removing those lines helps to keep all the payment schedules and process them correctly.

So, instead of clearing source.payment_schedule and only checking for one payment schedule, just make sure you add all overdue payments to the target and keep everything as it is. This way, you don't miss any data and everything works as expected.

@daanlenaerts
Copy link

daanlenaerts commented Aug 12, 2024

Thank you for your quick reply @Nihantra-Patel. That makes sense! And why did you keep the if statement? The condition is always false, as len(source.payment_schedule) is now always 0 due to the line you added?

@Nihantra-Patel
Copy link
Contributor Author

Since source.payment_schedule is emptied before the check, the if statement will never be true. So, you don't need that if statement at all. Just keep the code that clears old payments and adds new ones to the target. This makes the code simpler and avoids any confusion. please check the video that i provided above.

@daanlenaerts
Copy link

Just keep the code that clears old payments and adds new ones to the target. This makes the code simpler and avoids any confusion.

Absolutely, that's my point :D The if statement is still present in your code, so it might be good to remove those lines to keep things clean. I would do it, but can't really because it's your bug fix.

@Nihantra-Patel
Copy link
Contributor Author

Hmm 🤔

You said that if you remove/comment out the code below the outstanding will be updated? Did you test it?

I don't think it will be an outstanding update.

if source.payment_schedule and len(source.payment_schedule) == 1:
	target.overdue_payments[0].outstanding = source.get("outstanding_amount")

@daanlenaerts
Copy link

I'm not really saying that, all I'm saying is that the line you added in this fix ensures the if statement never succeeds, effectively rendering it useless. In which case it might be better to remove it.

However, to answer your question, I just tried actually removing the if statement and that does work (as it is effectively the same as your changes, it just makes the code cleaner). The outstanding amount is taken directly from the sales invoice's payment_schedule.

I do think that this would be an issue when a sales invoice would have multiple payment schedule lines, but I'm not sure when that's the case.

Comment on lines 2655 to 2658
# update outstanding
source.payment_schedule = []
if source.payment_schedule and len(source.payment_schedule) == 1:
target.overdue_payments[0].outstanding = source.get("outstanding_amount")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# update outstanding
source.payment_schedule = []
if source.payment_schedule and len(source.payment_schedule) == 1:
target.overdue_payments[0].outstanding = source.get("outstanding_amount")
# In the Sales Invoice, the outstanding amount of payment schedule might
# not be updated. This will be the case if it doesn't use a **Payment
# Terms Template** with _Allocate Payment Based On Payment Terms_
# enabled. In this case, we use the total outstanding amount from the
# Sales Invoice.
if source.payment_schedule and len(source.payment_schedule) == 1:
for row in target.overdue_payments:
if row.payment_schedule == source.payment_schedule[0].name:
row.outstanding = source.outstanding_amount

@stale stale bot added the inactive label Sep 15, 2024
@frappe frappe deleted a comment from stale bot Sep 16, 2024
@stale stale bot removed the inactive label Sep 16, 2024
@ruthra-kumar ruthra-kumar removed the request for review from deepeshgarg007 September 16, 2024 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-tests This PR needs automated unit-tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dunning - fetch ovedue payments - miss match in outstanding totals
4 participants