I need to add a field to invoices that are automatically created by subscriptions. So in a Server Script for DocType Subscription on "Before Safe", I pull some data from a few tables as well as from a custom field in the subscription.
Basically:
cur_doc = doc.get_title()
performance_period = frappe.db.get_value('Subscription', cur_doc, 'custom_performance_period')
frappe.errprint( performance_period )
bi = frappe.db.sql("SELECT billing_interval FROM `tabSubscription Plan Detail` d JOIN `tabSubscription Plan` p ON plan_name = p.name WHERE d.parent='" + cur_doc + "' LIMIT 1", as_dict=1)
billing_interval = bi[0].get('billing_interval')
frappe.errprint( billing_interval )
Then, with a few if or switch statements, a sensible performance period could be printed on the invoices.
But here's the question: How do you then put that into a custom field in the invoice that the subscription generates? Can it even be done from within a server script or must one hook into the scheduler?