本文整理汇总了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)
})