ValidationError: Due / Reference Date cannot be after X

This particular error is driving me up the wall as I get it with every Purchase and Sales invoice. It occurs when setting repeat Subscriptions for invoices or duplicating an old one manually.

I understand what the error is saying. It’s saying that the Due Date on the invoice cannot be a date in the past (or earlier than the invoice date, at least). The problem is that the Subscription invoice repeat is not honouring the ‘30 days’ invoice payment terms correctly by offsetting the newly created invoice from today’s date - it is cloning the old one and not being smart enough about also adjusting the payment terms.

I’ve tried to manage this in two ways:

  1. Only use the Due Date and not the Payment Terms
  2. Only use the Payment Terms and not the Due Date

Both ways do not work correctly with Subscriptions, or they do not work as expected and I’m using it incorrectly. Either the code is not correctly handling repeat invoices, or the process for creating duplicates is not clear enough for me to understand.

Please can somebody clarify this as either a process fault or a bug?

1 Like

Nobody has anything to add? Am I the only one with this issue? How does everybody else handle repeat invoices?

@ChipwizBen

Can you share a screenshot of the Subscription in question? That might throw some light on the configuration and why the problem might be happening.

It seems like if the date isn’t being set properly, then it might be a potential software bug. In that case, you should also create an issue on the ERPNext repo.

Here is a screenshot of the subscription. When it fails to run, ERPNext disables it, which you can see here:

Here is a screenshot from the top of the invoice:

Here is a screenshot of the payment terms:

Here is a copy of the error:
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/subscription/subscription.py”, line 129, in create_documents
doc = make_new_document(data, schedule_date)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/subscription/subscription.py”, line 166, in make_new_document
new_doc.insert(ignore_permissions=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 221, in insert
self.run_before_save_methods()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 861, in run_before_save_methods
self.run_method(“validate”)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 757, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1026, in composer
return composed(self, method, *args, **kwargs)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 1009, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 751, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py”, line 46, in validate
super(PurchaseInvoice, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py”, line 34, in validate
super(BuyingController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/stock_controller.py”, line 17, in validate
super(StockController, self).validate()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 53, in validate
self.validate_all_documents_schedule()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 80, in validate_all_documents_schedule
self.validate_invoice_documents_schedule()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 70, in validate_invoice_documents_schedule
self.validate_due_date()
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py”, line 145, in validate_due_date
“Supplier”, self.supplier, self.company, self.payment_terms_template)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/party.py”, line 327, in validate_due_date
.format(formatdate(default_due_date)))
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 323, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 309, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
raise raise_exception(encode(msg))
ValidationError: Due / Reference Date cannot be after 02-11-2018

ERPNext: v10.1.72 (master)

Frappe Framework: v10.1.64 (master)