brotherton-erpnext/erpnext/patches/v8_7/make_subscription_from_recurring_data.py
rohitwaghchaure 166b78f022 [Enhance] Subscription module (#10089)
* [Enhance] Subscription module

* Added view documents from the subscription form

* Test cases

* documentation

* UI Test cases, fixes

* Removed child table in the subscription

* Provision to make subscription from the document, added subscription in the dashboard for the sales and buying flow

* added patch to make subscription from the recurring data

* Rename field subscriptio to subscription_id, added new test cases, remove recurring_document from controller

* renamed subscription_id to subscription
2017-09-07 16:14:22 +05:30

45 lines
1.6 KiB
Python

# Copyright (c) 2017, Frappe and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import today
def execute():
frappe.reload_doc('subscription', 'doctype', 'subscription')
frappe.reload_doc('selling', 'doctype', 'sales_order')
frappe.reload_doc('buying', 'doctype', 'purchase_order')
frappe.reload_doc('accounts', 'doctype', 'sales_invoice')
frappe.reload_doc('accounts', 'doctype', 'purchase_invoice')
for doctype in ['Sales Order', 'Sales Invoice',
'Purchase Invoice', 'Purchase Invoice']:
for data in get_data(doctype):
make_subscription(doctype, data)
def get_data(doctype):
return frappe.db.sql(""" select name, from_date, end_date, recurring_type,recurring_id
next_date, notify_by_email, notification_email_address, recurring_print_format,
repeat_on_day_of_month, submit_on_creation
from `tab{0}` where is_recurring = 1 and next_date >= %s
""".format(doctype), today(), as_dict=1)
def make_subscription(doctype, data):
doc = frappe.get_doc({
'doctype': 'Subscription',
'reference_doctype': doctype,
'reference_document': data.name,
'start_date': data.from_date,
'end_date': data.end_date,
'frequency': data.recurring_type,
'repeat_on_day': data.repeat_on_day_of_month,
'notify_by_email': data.notify_by_email,
'recipients': data.notification_email_address,
'next_schedule_date': data.next_date,
'submit_on_creation': data.submit_on_creation
}).insert(ignore_permissions=True)
doc.submit()
if not doc.subscription:
frappe.db.set_value(doctype, data.name, "subscription", doc.name)