本文整理匯總了Python中corehq.apps.accounting.interface.InvoiceInterface.is_rendered_as_email方法的典型用法代碼示例。如果您正苦於以下問題:Python InvoiceInterface.is_rendered_as_email方法的具體用法?Python InvoiceInterface.is_rendered_as_email怎麽用?Python InvoiceInterface.is_rendered_as_email使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類corehq.apps.accounting.interface.InvoiceInterface
的用法示例。
在下文中一共展示了InvoiceInterface.is_rendered_as_email方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_bookkeeper_email
# 需要導入模塊: from corehq.apps.accounting.interface import InvoiceInterface [as 別名]
# 或者: from corehq.apps.accounting.interface.InvoiceInterface import is_rendered_as_email [as 別名]
def send_bookkeeper_email(month=None, year=None, emails=None):
today = datetime.date.today()
# now, make sure that we send out LAST month's invoices if we did
# not specify a month or year.
today = utils.get_previous_month_date_range(today)[0]
month = month or today.month
year = year or today.year
from corehq.apps.accounting.interface import InvoiceInterface
request = HttpRequest()
params = urlencode((
('report_filter_statement_period_use_filter', 'on'),
('report_filter_statement_period_month', month),
('report_filter_statement_period_year', year),
))
request.GET = QueryDict(params)
request.couch_user = FakeUser(
domain="hqadmin",
username="[email protected]gi.com",
)
invoice = InvoiceInterface(request)
invoice.is_rendered_as_email = True
first_of_month = datetime.date(year, month, 1)
email_context = {
'month': first_of_month.strftime("%B"),
}
email_content = render_to_string(
'accounting/bookkeeper_email.html', email_context)
email_content_plaintext = render_to_string(
'accounting/bookkeeper_email_plaintext.html', email_context)
format_dict = Format.FORMAT_DICT[Format.CSV]
excel_attachment = {
'title': 'Invoices_%(period)s.%(extension)s' % {
'period': first_of_month.strftime('%B_%Y'),
'extension': format_dict['extension'],
},
'mimetype': format_dict['mimetype'],
'file_obj': invoice.excel_response,
}
emails = emails or settings.BOOKKEEPER_CONTACT_EMAILS
for email in emails:
send_HTML_email(
"Invoices for %s" % datetime.date(year, month, 1).strftime("%B %Y"),
email,
email_content,
email_from=settings.DEFAULT_FROM_EMAIL,
text_content=email_content_plaintext,
file_attachments=[excel_attachment],
)
logger.info(
"[BILLING] Sent Bookkeeper Invoice Summary for %(month)s "
"to %(emails)s." % {
'month': first_of_month.strftime("%B %Y"),
'emails': ", ".join(emails)
})