Debugging subscriptions, how is it done? Which log file? What output from where?

Subscriptions just won’t generate invoices (?*#…!)

so I

  • disabled all server and client scripts
  • set time to the first of the month on server, client and user settings (I now live in Hawaii;)
  • updated invoice-from and until in database

The weird thing is: In a test installation with the identical database it worked after changing the from and to dates to 1 and 29 of Feb. Other than that is running on a local machine straight over port 8000, there are no differences. Same version, same everything.

I checked all logs to no avail, the ones in frappe-bench and in site. Where do I get some output?

Cheers,
kombi

I have this notorious history of answering my own questions and then finding them again the next time the problem occurs.

So:
Once you have eliminated all other obstacles such as faulty scripts you must turn back the clock to the first day of the billing period in the early morning on both server and client.

You are then, after generating most invoices from most subcriptions faced with the “Document has been modified after you have opened it”-problem, where both those times are always some miliseconds apart, no matter how often you reload the document.

When I find a solution to that I will post it here.

1 Like

To generate invoices from subscriptions after the defined date has passed:

  1. turn back clock on server
timedatectl set-ntp false
date --set=2024-02-01 # or whatever
  1. Temporarily disable the “Document has been modified”-Exception. In
/apps/frappe/frappe/model/document.py 

comment out with a # the line saying (Line 811 or somewhere around that)

raise_exeption.frappe.TimestampMismatchError
  1. generate invoices from subscriptions with Action / Fetch updates

  2. un-comment above line and set time back to actual:

timedatectl set-ntp true

Hi @kombi:

After some (funny) research I’ve found many interesting things.

Subscription invoice creation is launched by create_subscription_process, triggered with scheduler (daily basis). (see ERPNext hooks.py)

From this, subscription class method process is called and launched invoice creation under some conditions. See:

So, bulk invoice creation for past dates could be done with a server script (or using console), like this:

first_date = frappe.utils.getdate("2024-01-01")
end_date = frappe.utils.getdate("2024-01-15")
current_date = first_date
while current_date <= end_date:
    subscription = frappe.get_doc("Subscription", "ACC-SUB-2024-00004")
    print(subscription.current_invoice_start, current_date)
    subscription.current_invoice_start=current_date
    subscription.current_invoice_end=current_date
    subscription.save()
    subscription.process(posting_date=current_date)
    current_date = frappe.utils.add_to_date(current_date, days=1)

Drive with care :wink:
Hope this helps.

1 Like

A funny if-cascade indeed + your’s is a much better method than my McGuyver-approach above. Could / should be in the standard list of scripts for maintenance use. Thanks AVC!

ps. Who do you use the sm58 with?:wink:

Glad to help @kombi .

Good eyes! Oh, this picture with the SM58 was made many versions ago … when I’d pretend to be Bon Scott. Now I pretend to be Otis Redding or James Brown … (Beyoncé hips, of course)

1 Like