Repository: frappe/frappe

Issue:
attach_print type error
        Looks like this is used in email attachments :pensive: 

```
Traceback with variables (most recent call last):
  File "apps/frappe/frappe/utils/background_jobs.py", line 172, in execute_job
    method(**kwargs)
      site = 'redacted'
      method = <function send_mail at 0x7f34106aee60>
      event = None
      job_name = '<function send_mail at 0x7f40dafd7640>'
      kwargs = {'email_queue_name': '9f709cdc6a', 'is_background_task': True}
      user = 'Administrator'
      is_async = True
      retry = 0
      method_name = 'send_mail'
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 184, in send_mail
    record.send(is_background_task=is_background_task, smtp_server_instance=smtp_server_instance)
      email_queue_name = '9f709cdc6a'
      is_background_task = True
      smtp_server_instance = None
      record = <EmailQueue: 9f709cdc6a>
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 135, in send
    message = ctx.build_message(recipient.recipient)
      self = <EmailQueue: 9f709cdc6a>
      is_background_task = True
      smtp_server_instance = None
      ctx = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f341042f8b0>
      message = None
      recipient = <EmailQueueRecipient: 4bd851fa96 parent=9f709cdc6a>
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 294, in build_message
    message = self.include_attachments(message)
      self = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f341042f8b0>
      recipient_email = 'redacted'
      message = 'redacted'
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 353, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
      self = <frappe.email.doctype.email_queue.email_queue.SendMailContext object at 0x7f341042f8b0>
      message = 'redacted'
      message_obj = <email.message.EmailMessage object at 0x7f3410052140>
      attachments = [{'print_format': 'GST Tax Invoice - with PAN', 'html': '', 'doctype': 'Sales Invoice', 'name': 'redacted', 'lang': 'en', 'print_letterhead': '1'}]
      attachment = {'print_format': 'GST Tax Invoice - with PAN', 'html': '', 'doctype': 'Sales Invoice', 'name': 'redacted', 'lang': 'en', 'print_letterhead': '1'}
      file_filters = {}
builtins.TypeError: attach_print() got an unexpected keyword argument 'html'
```

_Originally posted by @ankush in https://github.com/frappe/frappe/issues/19285#issuecomment-1357496636_
      


Discussion:

Resolving patch:
diff --git a/frappe/__init__.py b/frappe/__init__.py
--- a/frappe/__init__.py
+++ b/frappe/__init__.py
@@ -2010,12 +2010,14 @@ def attach_print(
 	file_name=None,
 	print_format=None,
 	style=None,
+	html=None,
 	doc=None,
 	lang=None,
 	print_letterhead=True,
 	password=None,
 ):
 	from frappe.utils import scrub_urls
+	from frappe.utils.pdf import get_pdf
 
 	if not file_name:
 		file_name = name
@@ -2044,10 +2046,14 @@ def attach_print(
 	if int(print_settings.send_print_as_pdf or 0):
 		ext = ".pdf"
 		kwargs["as_pdf"] = True
-		content = get_print(doctype, name, **kwargs)
+		content = (
+			get_pdf(html, options={"password": password} if password else None)
+			if html
+			else get_print(doctype, name, **kwargs)
+		)
 	else:
 		ext = ".html"
-		content = scrub_urls(get_print(doctype, name, **kwargs)).encode("utf-8")
+		content = html or scrub_urls(get_print(doctype, name, **kwargs)).encode("utf-8")
 
 	out = {"fname": file_name + ext, "fcontent": content}
 


Test patch: