Skip to content

Commit

Permalink
fix: add customer name and supplier name columns (#37557)
Browse files Browse the repository at this point in the history
fix: add customer name and supplier name columns
  • Loading branch information
viralkansodiya authored Nov 12, 2023
1 parent 6f6d5cb commit ecc305d
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def execute(filters=None):
def get_columns(filters):
party_type = filters.get("party_type")
party_type_value = get_party_group(party_type)
return [
columns = [
"{party_type}:Link/{party_type}".format(party_type=party_type),
"{party_value_type}::150".format(party_value_type=frappe.unscrub(str(party_type_value))),
"Address Line 1",
Expand All @@ -43,34 +43,49 @@ def get_columns(filters):
"Email Id",
"Is Primary Contact:Check",
]
if filters.get("party_type") == "Supplier" and frappe.db.get_single_value(
"Buying Settings", "supp_master_name"
) == ["Naming Series", "Auto Name"]:
columns.insert(1, "Supplier Name:Data:150")
if filters.get("party_type") == "Customer" and frappe.db.get_single_value(
"Selling Settings", "cust_master_name"
) == ["Naming Series", "Auto Name"]:
columns.insert(1, "Customer Name:Data:150")
return columns


def get_data(filters):
party_type = filters.get("party_type")
party = filters.get("party_name")
party_group = get_party_group(party_type)

return get_party_addresses_and_contact(party_type, party, party_group)
return get_party_addresses_and_contact(party_type, party, party_group, filters)


def get_party_addresses_and_contact(party_type, party, party_group):
def get_party_addresses_and_contact(party_type, party, party_group, filters):
data = []
filters = None
query_filters = None
party_details = frappe._dict()

if not party_type:
return []

if party:
filters = {"name": party}
query_filters = {"name": party}
if filters.get("party_type") in ["Customer", "Supplier"]:
field = filters.get("party_type").lower() + "_name"
else:
field = "partner_name"

fetch_party_list = frappe.get_list(
party_type, filters=filters, fields=["name", party_group], as_list=True
party_type, filters=query_filters, fields=["name", party_group, field], as_list=True
)
party_list = [d[0] for d in fetch_party_list]
party_groups = {}
party_name_map = {}
for d in fetch_party_list:
party_groups[d[0]] = d[1]
party_name_map[d[0]] = d[2]

for d in party_list:
party_details.setdefault(d, frappe._dict())
Expand All @@ -84,6 +99,8 @@ def get_party_addresses_and_contact(party_type, party, party_group):
if not any([addresses, contacts]):
result = [party]
result.append(party_groups[party])
if filters.get("party_type") in ["Customer", "Supplier"]:
result.append(party_name_map[party])
result.extend(add_blank_columns_for("Contact"))
result.extend(add_blank_columns_for("Address"))
data.append(result)
Expand All @@ -95,11 +112,12 @@ def get_party_addresses_and_contact(party_type, party, party_group):
for idx in range(0, max_length):
result = [party]
result.append(party_groups[party])
if filters.get("party_type") in ["Customer", "Supplier"]:
result.append(party_name_map[party])
address = addresses[idx] if idx < len(addresses) else add_blank_columns_for("Address")
contact = contacts[idx] if idx < len(contacts) else add_blank_columns_for("Contact")
result.extend(address)
result.extend(contact)

data.append(result)
return data

Expand All @@ -115,7 +133,6 @@ def get_party_details(party_type, party_list, doctype, party_details):
for d in records:
details = party_details.get(d[0])
details.setdefault(frappe.scrub(doctype), []).append(d[1:])

return party_details


Expand Down

0 comments on commit ecc305d

Please sign in to comment.