Merge pull request #40459 from Nihantra-Patel/fix_sp_address

fix: sales partner address display Issue
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.py b/erpnext/setup/doctype/sales_partner/sales_partner.py
index 1047360..a8a965d 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.py
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.py
@@ -54,25 +54,30 @@
 			self.partner_website = "http://" + self.partner_website
 
 	def get_context(self, context):
-		address = frappe.db.get_value(
-			"Address", {"sales_partner": self.name, "is_primary_address": 1}, "*", as_dict=True
+		address_names = frappe.db.get_all(
+			"Dynamic Link",
+			filters={"link_doctype": "Sales Partner", "link_name": self.name, "parenttype": "Address"},
+			pluck=["parent"],
 		)
-		if address:
-			city_state = ", ".join(filter(None, [address.city, address.state]))
-			address_rows = [
-				address.address_line1,
-				address.address_line2,
-				city_state,
-				address.pincode,
-				address.country,
-			]
 
-			context.update(
+		addresses = []
+		for address_name in address_names:
+			address_doc = frappe.get_doc("Address", address_name)
+			city_state = ", ".join([item for item in [address_doc.city, address_doc.state] if item])
+			address_rows = [
+				address_doc.address_line1,
+				address_doc.address_line2,
+				city_state,
+				address_doc.pincode,
+				address_doc.country,
+			]
+			addresses.append(
 				{
-					"email": address.email_id,
+					"email": address_doc.email_id,
 					"partner_address": filter_strip_join(address_rows, "\n<br>"),
-					"phone": filter_strip_join(cstr(address.phone).split(","), "\n<br>"),
+					"phone": filter_strip_join(cstr(address_doc.phone).split(","), "\n<br>"),
 				}
 			)
 
+		context["addresses"] = addresses
 		return context
diff --git a/erpnext/templates/generators/sales_partner.html b/erpnext/templates/generators/sales_partner.html
index 39138d3..9dd2db9 100644
--- a/erpnext/templates/generators/sales_partner.html
+++ b/erpnext/templates/generators/sales_partner.html
@@ -8,18 +8,20 @@
 <div class="partner-content" itemscope itemtype="http://schema.org/Organization">
 	<div class="row">
 		<div class="col-md-4">
-			{% if logo -%}
+			{% if logo %}
 			<img itemprop="brand" src="{{ logo }}" class="partner-logo"
 				alt="{{ partner_name }}" title="{{ partner_name }}" />
 			<br><br>
-			{%- endif %}
-			<address>
-				{% if partner_website -%}<p><a href="{{ partner_website }}"
-					target="_blank">{{ partner_website }}</a></p>{%- endif %}
-				{% if partner_address -%}<p itemprop="address">{{ partner_address }}</p>{%- endif %}
-				{% if phone -%}<p itemprop="telephone">{{ phone }}</p>{%- endif %}
-				{% if email -%}<p itemprop="email"><span class="fa fa-envelope"></span> {{ email }}</p>{%- endif %}
-			</address>
+			{% endif %}
+			{% if addresses %}
+				{% for address in addresses %}
+					<address>
+						{% if address.partner_address %}<p itemprop="address">{{ address.partner_address }}</p>{% endif %}
+						{% if address.phone %}<p itemprop="telephone">{{ address.phone }}</p>{% endif %}
+						{% if address.email %}<p itemprop="email"><span class="fa fa-envelope"></span> {{ address.email }}</p>{% endif %}
+					</address>
+				{% endfor %}
+			{% endif %}
 		</div>
 		<div class="col-md-8">
 			<p>{{ description }}</p>