fix: resolve analytics backport conflicts

This commit is contained in:
Sudharsanan11
2026-08-26 16:10:33 +05:30
parent 0dddd00073
commit 605918d3a2
4 changed files with 41 additions and 37 deletions

View File

@@ -85,8 +85,6 @@ frappe.query_reports["Purchase Analytics"] = {
default: "Monthly",
reqd: 1,
},
<<<<<<< HEAD
=======
{
fieldname: "curves",
label: __("Curves"),
@@ -100,12 +98,6 @@ frappe.query_reports["Purchase Analytics"] = {
default: "select",
reqd: 1,
},
{
fieldname: "show_aggregate_value_from_subsidiary_companies",
label: __("Show Aggregate Value from Subsidiary Companies"),
fieldtype: "Check",
},
>>>>>>> 3f29cdf (feat(analytics): filter sales and purchase analytics by entity (#58402))
],
get_datatable_options(options) {
return Object.assign(options, {

View File

@@ -2,11 +2,11 @@
# See license.txt
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import flt
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.buying.report.purchase_analytics.purchase_analytics import execute
from erpnext.tests.utils import ERPNextTestSuite
COMPANY = "_Test Company"
SUPPLIER = "_Test Supplier"
@@ -16,7 +16,7 @@ FROM_DATE = "2019-04-01"
TO_DATE = "2019-06-30"
class TestPurchaseAnalytics(ERPNextTestSuite):
class TestPurchaseAnalytics(FrappeTestCase):
"""purchase_analytics reuses the shared Analytics engine; these tests lock its
wiring (doc_type=Purchase Order) across the Supplier Group / Item Group trees."""

View File

@@ -18,12 +18,7 @@ def execute(filters=None):
class Analytics:
def __init__(self, filters=None):
self.filters = frappe._dict(filters or {})
<<<<<<< HEAD
=======
self.entities = self.filters.get("entity") or []
if self.filters.doc_type == "Payment Entry" and self.filters.value_quantity == "Quantity":
frappe.throw(_("Only Value available for Payment Entry"))
>>>>>>> 3f29cdf (feat(analytics): filter sales and purchase analytics by entity (#58402))
self.date_field = (
"transaction_date"
if self.filters.doc_type in ["Sales Order", "Purchase Order"]

View File

@@ -3,12 +3,12 @@
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils import flt
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
from erpnext.selling.report.sales_analytics.sales_analytics import execute
from erpnext.tests.utils import ERPNextTestSuite
# Bootstrap masters reused as-is (see erpnext/tests/utils.py):
# "_Test Customer" -> customer_group "_Test Customer Group", territory "_Test Territory"
@@ -24,28 +24,48 @@ FROM_DATE = "2019-04-01"
TO_DATE = "2019-06-30"
class TestSalesAnalytics(ERPNextTestSuite):
class TestSalesAnalytics(FrappeTestCase):
def setUp(self):
frappe.set_user("Administrator")
self.created_docs = []
# Two submitted Sales Orders for the bootstrap customer inside the report window.
# These roll up into the tree roots the converted tree/order-type queries build.
self.orders = [
make_sales_order(
company=COMPANY,
customer=CUSTOMER,
qty=5,
rate=100,
transaction_date="2019-04-10",
),
make_sales_order(
company=COMPANY,
customer=CUSTOMER,
qty=3,
rate=100,
transaction_date="2019-05-15",
),
self.make_so(qty=5, rate=100, transaction_date="2019-04-10"),
self.make_so(qty=3, rate=100, transaction_date="2019-05-15"),
]
def tearDown(self):
for doctype, name in reversed(self.created_docs):
if not frappe.db.exists(doctype, name):
continue
doc = frappe.get_doc(doctype, name)
if doc.docstatus == 1:
doc.cancel()
frappe.delete_doc(doctype, name, force=True)
super().tearDown()
def make_so(self, qty, rate, transaction_date, order_type=None):
so = make_sales_order(
company=COMPANY,
customer=CUSTOMER,
qty=qty,
rate=rate,
transaction_date=transaction_date,
do_not_save=True,
)
# v15's test helper does not populate these hidden analytics dimensions.
so.customer_group = CUSTOMER_GROUP
so.territory = TERRITORY
if order_type:
so.order_type = order_type
so.insert()
so.submit()
self.created_docs.append((so.doctype, so.name))
return so
def _base_filters(self, **overrides):
filters = {
"doc_type": "Sales Order",
@@ -160,16 +180,12 @@ class TestSalesAnalytics(ERPNextTestSuite):
postgres, so the report sorts the order-type rows in python (key=str.casefold) to keep them in a
deterministic, case-insensitive order identical on both engines."""
for order_type in ("Shopping Cart", "Maintenance", "Sales"): # created out of sorted order
so = make_sales_order(
company=COMPANY,
customer=CUSTOMER,
self.make_so(
qty=1,
rate=100,
transaction_date="2019-04-12",
do_not_submit=True,
order_type=order_type,
)
so.order_type = order_type
so.submit()
columns, data, *_ = execute(self._base_filters(tree_type="Order Type"))
@@ -213,6 +229,7 @@ class TestSalesAnalytics(ERPNextTestSuite):
rate=250,
transaction_date="2019-04-10",
)
self.created_docs.append((po.doctype, po.name))
po_value = flt(po.base_net_total)
self.assertGreater(po_value, 0)