Skip to content

Commit

Permalink
Merge pull request #40459 from Nihantra-Patel/fix_sp_address
Browse files Browse the repository at this point in the history
fix: sales partner address display Issue
  • Loading branch information
deepeshgarg007 authored Mar 17, 2024
2 parents 1fc099d + cefb8f6 commit 6d47b8a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 21 deletions.
29 changes: 17 additions & 12 deletions erpnext/setup/doctype/sales_partner/sales_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,30 @@ def validate(self):
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]))

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.address_line1,
address.address_line2,
address_doc.address_line1,
address_doc.address_line2,
city_state,
address.pincode,
address.country,
address_doc.pincode,
address_doc.country,
]

context.update(
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
20 changes: 11 additions & 9 deletions erpnext/templates/generators/sales_partner.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 6d47b8a

Please sign in to comment.