Customize Sales Invoce to personalize salutation

Hey there,
I would like to personalize the salutation in invoices.This is what it should look like:
For female salutation I would like to have: (== “Weiblich”)
Sehr geehrte Frau LASTNAME,
“Textbody”

For male salutation: (!= “Weiblich”)
Sehr geehrter Herr LASTNAME,
“Textbody”

LASTNAME should be the one from the customer chosen in invoice.

It works, if I only have one Contact linked to my Customer.
At First here is my Code:

{%- for row in frappe.get_list(doctype=“Contact”,
fields=[“salutation”, “first_name”, “last_name”, “gender”],
filters={ “link_name”:doc.customer_name}) -%}
{% if row.gender != “Weiblich” %} Sehr geehrter {{ row.salutation }} {{ row.last_name }} {%- endif -%} {% if row.gender == “Weiblich” %} Sehr geehrte {{ row.salutation }} {{ row.last_name }} {%- endif -%},
{% endfor %}

As soon there are more than one contacts linked to my customer it fills every contact from contact/listview into my invoice.
Does anybody have a clue what I should change, so that only the Contact where the invoice belongs to is filled in?