fix(controllers): report a Prospect quotation's territory (#59133)

This commit is contained in:
Mihir Kandoi
2026-09-17 13:51:59 +05:30
committed by GitHub
parent 60913b722a
commit 228bbe845f
2 changed files with 51 additions and 1 deletions

View File

@@ -400,13 +400,15 @@ def quotation_party_name_expr():
def quotation_territory_expr():
"""Only Customer and Lead carry a territory; other party types have none."""
"""Territory from the party master. CRM Deal has none here: it ships with the CRM app."""
return (
"case "
"when t1.quotation_to = 'Customer' then "
"(select c.territory from `tabCustomer` c where c.name = t1.party_name) "
"when t1.quotation_to = 'Lead' then "
"(select l.territory from `tabLead` l where l.name = t1.party_name) "
"when t1.quotation_to = 'Prospect' then "
"(select p.territory from `tabProspect` p where p.name = t1.party_name) "
"end"
)

View File

@@ -119,6 +119,54 @@ class TestQuotationTrends(ERPNextTestSuite):
self.assertEqual(len(lead_rows), 1)
self.assertEqual(lead_rows[0][name_idx], lead.company_name or lead_name)
def test_prospect_quotation_reports_its_master_territory(self):
"""Prospect stores a territory, so its quotations must report it, not a blank cell.
The CASE resolved territory for Customer and Lead only, so a Prospect quotation fell through
to NULL even though the master carries the field.
"""
territory = "_Test Trends Prospect Territory"
if not frappe.db.exists("Territory", territory):
frappe.get_doc(
{
"doctype": "Territory",
"territory_name": territory,
"parent_territory": "All Territories",
"is_group": 0,
}
).insert()
prospect_name = "_Test Trends Prospect Party"
if not frappe.db.exists("Prospect", prospect_name):
frappe.get_doc(
{
"doctype": "Prospect",
"company_name": prospect_name,
"company": "_Test Company",
"territory": territory,
}
).insert()
quotation = frappe.new_doc("Quotation")
quotation.company = "_Test Company"
quotation.transaction_date = TXN_DATE
quotation.currency = "INR"
quotation.quotation_to = "Prospect"
quotation.party_name = prospect_name
quotation.append(
"items",
{"item_code": "_Test Item", "qty": 1, "rate": 100, "warehouse": "_Test Warehouse - _TC"},
)
quotation.insert()
quotation.submit()
labels, rows = self.run_report(based_on="Customer")
party_idx, territory_idx = labels.index("Party"), labels.index("Territory")
prospect_rows = [row for row in rows if row[party_idx] == prospect_name]
self.assertEqual(len(prospect_rows), 1)
self.assertEqual(prospect_rows[0][territory_idx], territory)
def test_group_by_chart_matches_table_total_with_mixed_group_sizes(self):
# _Test Item is quoted to two customers -> two detail rows under one header row.
# _Test Item 2 is quoted to only one customer -> exactly one detail row under its