Flexible invoice period in recurring invoice
This commit is contained in:
parent
9ec73ccf1e
commit
bc8e9d7a34
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -485,7 +485,8 @@ def manage_recurring_invoices():
|
||||
and notify the concerned people
|
||||
"""
|
||||
rv = webnotes.conn.sql("""select name, recurring_id from `tabSales Invoice` where ifnull(convert_into_recurring_invoice, 0) = 1
|
||||
and next_date = %s and next_date <= end_date and docstatus=1 order by next_date desc""", nowdate())
|
||||
and next_date = %s and next_date <= ifnull(end_date, '2199-12-31') and docstatus=1""", nowdate(), debug=1)
|
||||
msgprint(rv)
|
||||
for d in rv:
|
||||
if not webnotes.conn.sql("""select name from `tabSales Invoice` where posting_date = %s and recurring_id = %s and docstatus=1""", (nowdate(), d[1])):
|
||||
prev_rv = get_obj('Sales Invoice', d[0], with_children=1)
|
||||
@ -503,6 +504,8 @@ def create_new_invoice(prev_rv):
|
||||
new_rv.doc.posting_date = new_rv.doc.next_date
|
||||
new_rv.doc.aging_date = new_rv.doc.next_date
|
||||
new_rv.doc.due_date = add_days(new_rv.doc.next_date, cint(date_diff(prev_rv.doc.due_date, prev_rv.doc.posting_date)))
|
||||
new_rv.doc.invoice_period_from_date = get_next_month_date(new_rv.doc.invoice_period_from_date)
|
||||
new_rv.doc.invoice_period_to_date = get_next_month_date(new_rv.doc.invoice_period_to_date)
|
||||
new_rv.doc.owner = prev_rv.doc.owner
|
||||
new_rv.doc.save()
|
||||
|
||||
@ -512,6 +515,21 @@ def create_new_invoice(prev_rv):
|
||||
|
||||
return new_rv
|
||||
|
||||
def get_next_month_date(dt):
|
||||
import datetime
|
||||
m = getdate(dt).month + 1
|
||||
y = getdate(dt).year
|
||||
d = getdate(dt).day
|
||||
if m > 12:
|
||||
m, y = 1, y+1
|
||||
try:
|
||||
next_month_date = datetime.date(y, m, d)
|
||||
except:
|
||||
import calendar
|
||||
last_day = calendar.monthrange(y, m)[1]
|
||||
next_month_date = datetime.date(y, m, last_day)
|
||||
return next_month_date.strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
def send_notification(new_rv):
|
||||
"""Notify concerned persons about recurring invoice generation"""
|
||||
@ -528,7 +546,7 @@ def send_notification(new_rv):
|
||||
</tr>
|
||||
</table>
|
||||
''' % (com, new_rv.doc.name, new_rv.doc.customer, new_rv.doc.address_display, getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"), \
|
||||
getdate(add_days(add_months(new_rv.doc.posting_date, -1), 1)).strftime("%d-%m-%Y"), getdate(new_rv.doc.posting_date).strftime("%d-%m-%Y"),\
|
||||
getdate(new_rv.doc.invoice_period_from_date).strftime("%d-%m-%Y"), getdate(new_rv.doc.invoice_period_to_date).strftime("%d-%m-%Y"),\
|
||||
getdate(new_rv.doc.due_date).strftime("%d-%m-%Y"))
|
||||
|
||||
|
||||
@ -569,6 +587,6 @@ def send_notification(new_rv):
|
||||
|
||||
|
||||
msg = hd + tbl + totals
|
||||
msgprint(msg)
|
||||
from webnotes.utils.email_lib import sendmail
|
||||
sendmail(recipients = new_rv.doc.notification_email_address.split(", "), \
|
||||
sender=new_rv.doc.owner, subject=subject, parts=[['text/plain', msg]])
|
||||
sendmail(new_rv.doc.notification_email_address.split(", "), subject=subject, msg = msg)
|
@ -683,6 +683,8 @@ class DocType(TransactionBase):
|
||||
|
||||
def convert_into_recurring(self):
|
||||
if self.doc.convert_into_recurring_invoice:
|
||||
if not self.doc.invoice_period_from_date or not self.doc.invoice_period_to_date:
|
||||
msgprint("Invoice period from date and to date is mandatory for recurring invoice", raise_exception=1)
|
||||
self.set_next_date()
|
||||
if not self.doc.recurring_id:
|
||||
webnotes.conn.set(self.doc, 'recurring_id', make_autoname('RECINV/.#####'))
|
||||
|
@ -5,7 +5,7 @@
|
||||
{
|
||||
'creation': '2012-04-13 11:56:18',
|
||||
'docstatus': 0,
|
||||
'modified': '2012-05-14 14:09:43',
|
||||
'modified': '2012-06-04 14:40:59',
|
||||
'modified_by': u'Administrator',
|
||||
'owner': u'Administrator'
|
||||
},
|
||||
@ -1498,11 +1498,25 @@
|
||||
{
|
||||
'allow_on_submit': 1,
|
||||
'depends_on': u'eval:doc.convert_into_recurring_invoice==1',
|
||||
'description': u'The date on which recurring invoice will be stop',
|
||||
'description': u'Start date of the invoice period',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'end_date',
|
||||
'fieldname': u'invoice_period_from_date',
|
||||
'fieldtype': u'Date',
|
||||
'label': u'End Date',
|
||||
'label': u'Invoice Period From Date',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0,
|
||||
'print_hide': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'allow_on_submit': 1,
|
||||
'depends_on': u'eval:doc.convert_into_recurring_invoice==1',
|
||||
'description': u'End date of the invoice period',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'invoice_period_to_date',
|
||||
'fieldtype': u'Date',
|
||||
'label': u'Invoice Period To Date',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0,
|
||||
'print_hide': 1
|
||||
@ -1559,6 +1573,20 @@
|
||||
'print_hide': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'allow_on_submit': 1,
|
||||
'depends_on': u'eval:doc.convert_into_recurring_invoice==1',
|
||||
'description': u'The date on which recurring invoice will be stop',
|
||||
'doctype': u'DocField',
|
||||
'fieldname': u'end_date',
|
||||
'fieldtype': u'Date',
|
||||
'label': u'End Date',
|
||||
'no_copy': 1,
|
||||
'permlevel': 0,
|
||||
'print_hide': 1
|
||||
},
|
||||
|
||||
# DocField
|
||||
{
|
||||
'doctype': u'DocField',
|
||||
|
Loading…
x
Reference in New Issue
Block a user