[fix]Earlier recurring billing
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index ae225d2..7b6f943 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _, throw
-from frappe.utils import today, flt, cint, fmt_money
+from frappe.utils import today, flt, cint, fmt_money, getdate
from erpnext.setup.utils import get_company_currency, get_exchange_rate
from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year, get_account_currency
from erpnext.utilities.transaction_base import TransactionBase
@@ -31,6 +31,9 @@
self.set_missing_values(for_validate=True)
self.validate_date_with_fiscal_year()
+ if self.meta.get_field('next_date') and self.next_date:
+ self.validate_recurring_next_date()
+
if self.meta.get_field("currency"):
self.calculate_taxes_and_totals()
if not self.meta.get_field("is_return") or not self.is_return:
@@ -88,6 +91,14 @@
validate_fiscal_year(self.get(date_field), self.fiscal_year,
self.meta.get_label(date_field), self)
+ def validate_recurring_next_date(self):
+ posting_date = self.get("posting_date") or self.get("transaction_date")
+ if getdate(posting_date) > getdate(self.next_date):
+ frappe.throw(_("Next Date must be greater than Posting Date"))
+
+ if getdate(self.next_date).day != self.repeat_on_day_of_month:
+ frappe.throw(_("Next Date's day and Repeat on Day of Month must be equal"))
+
def validate_due_date(self):
from erpnext.accounts.party import validate_due_date
if self.doctype == "Sales Invoice":
diff --git a/erpnext/controllers/recurring_document.py b/erpnext/controllers/recurring_document.py
index f83df2b..c3e98e8 100644
--- a/erpnext/controllers/recurring_document.py
+++ b/erpnext/controllers/recurring_document.py
@@ -72,7 +72,7 @@
frappe.throw(exception_message)
def make_new_document(reference_doc, date_field, posting_date):
- new_document = frappe.copy_doc(reference_doc, ignore_no_copy=True)
+ new_document = frappe.copy_doc(reference_doc, ignore_no_copy=False)
mcount = month_map[reference_doc.recurring_type]
from_date = get_next_date(reference_doc.from_date, mcount)
@@ -89,7 +89,7 @@
date_field: posting_date,
"from_date": from_date,
"to_date": to_date,
- "next_date": get_next_date(from_date, mcount,cint(reference_doc.repeat_on_day_of_month))
+ "next_date": get_next_date(reference_doc.next_date, mcount,cint(reference_doc.repeat_on_day_of_month))
})
# copy document fields
@@ -202,7 +202,7 @@
if not doc.repeat_on_day_of_month:
msgprint(_("Please enter 'Repeat on Day of Month' field value"), raise_exception=1)
- next_date = doc.next_date or get_next_date(doc.from_date, month_map[doc.recurring_type],
+ next_date = get_next_date(posting_date, month_map[doc.recurring_type],
cint(doc.repeat_on_day_of_month))
frappe.db.set(doc, 'next_date', next_date)