Issue using custom letter heads

When I use a custom letter head including company information, I always get this error: “Company None not found”

The HTML code I use is the following:

{% set company = frappe.get_doc(“Company”, doc.company) %}
{% set company_address_name = frappe.db.get_value(“Dynamic Link”, filters={“link_doctype”: “Company”, “link_name”: doc.company, “parenttype”: “Address”}, fieldname=“parent”) %}
{% set address = frappe.get_doc(“Address”, company_address_name) if company_address_name else None %}

I use the latest ERPNext v13

Any suggestions are greatly appreciated. Thank you so much!