Merge pull request #22796 from anupamvs/variance-report-fix
fix: Target variance report signs
diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
index 3ec4d30..f547ca6 100644
--- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
+++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js
@@ -71,7 +71,22 @@
fieldtype: "Check",
default: 0,
},
- ]
+ ],
+ "formatter": function (value, row, column, data, default_formatter) {
+ value = default_formatter(value, row, column, data);
+
+ if (column.fieldname.includes('variance')) {
+
+ if (data[column.fieldname] < 0) {
+ value = "<span style='color:red'>" + value + "</span>";
+ }
+ else if (data[column.fieldname] > 0) {
+ value = "<span style='color:green'>" + value + "</span>";
+ }
+ }
+
+ return value;
+ }
}
erpnext.dimension_filters.forEach((dimension) => {
diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py
index 857b982..ae216ca 100644
--- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py
+++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/item_group_wise_sales_target_variance.py
@@ -63,13 +63,13 @@
"label": _(partner_doctype),
"fieldtype": "Link",
"options": partner_doctype,
- "width": 100
+ "width": 150
}, {
"fieldname": "item_group",
"label": _("Item Group"),
"fieldtype": "Link",
"options": "Item Group",
- "width": 100
+ "width": 150
}]
for period in period_list:
@@ -81,19 +81,19 @@
"label": _("Target ({})").format(period.label),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}, {
"fieldname": period.key,
"label": _("Achieved ({})").format(period.label),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}, {
"fieldname": variance_key,
"label": _("Variance ({})").format(period.label),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}])
columns.extend([{
@@ -101,19 +101,19 @@
"label": _("Total Target"),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}, {
"fieldname": "total_achieved",
"label": _("Total Achieved"),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}, {
"fieldname": "total_variance",
"label": _("Total Variance"),
"fieldtype": fieldtype,
"options": options,
- "width": 100
+ "width": 150
}])
return columns
@@ -154,10 +154,10 @@
if (r.get(sales_field) == d.parent and r.item_group == d.item_group and
period.from_date <= r.get(date_field) and r.get(date_field) <= period.to_date):
details[p_key] += r.get(qty_or_amount_field, 0)
- details[variance_key] = details.get(target_key) - details.get(p_key)
+ details[variance_key] = details.get(p_key) - details.get(target_key)
details["total_achieved"] += details.get(p_key)
- details["total_variance"] = details.get("total_target") - details.get("total_achieved")
+ details["total_variance"] = details.get("total_achieved") - details.get("total_target")
return rows
diff --git a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js
index f99f68c..38bb127 100644
--- a/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js
+++ b/erpnext/selling/report/sales_partner_target_variance_based_on_item_group/sales_partner_target_variance_based_on_item_group.js
@@ -44,5 +44,20 @@
options: "Quantity\nAmount",
default: "Quantity"
},
- ]
+ ],
+ "formatter": function (value, row, column, data, default_formatter) {
+ value = default_formatter(value, row, column, data);
+
+ if (column.fieldname.includes('variance')) {
+
+ if (data[column.fieldname] < 0) {
+ value = "<span style='color:red'>" + value + "</span>";
+ }
+ else if (data[column.fieldname] > 0) {
+ value = "<span style='color:green'>" + value + "</span>";
+ }
+ }
+
+ return value;
+ }
}
diff --git a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js
index 9f6bfc4..a8e2fad 100644
--- a/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js
+++ b/erpnext/selling/report/sales_person_target_variance_based_on_item_group/sales_person_target_variance_based_on_item_group.js
@@ -44,5 +44,20 @@
options: "Quantity\nAmount",
default: "Quantity"
},
- ]
+ ],
+ "formatter": function (value, row, column, data, default_formatter) {
+ value = default_formatter(value, row, column, data);
+
+ if (column.fieldname.includes('variance')) {
+
+ if (data[column.fieldname] < 0) {
+ value = "<span style='color:red'>" + value + "</span>";
+ }
+ else if (data[column.fieldname] > 0) {
+ value = "<span style='color:green'>" + value + "</span>";
+ }
+ }
+
+ return value;
+ }
}
diff --git a/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js b/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js
index dd9607f..263391a 100644
--- a/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js
+++ b/erpnext/selling/report/territory_target_variance_based_on_item_group/territory_target_variance_based_on_item_group.js
@@ -44,5 +44,20 @@
options: "Quantity\nAmount",
default: "Quantity"
},
- ]
+ ],
+ "formatter": function (value, row, column, data, default_formatter) {
+ value = default_formatter(value, row, column, data);
+
+ if (column.fieldname.includes('variance')) {
+
+ if (data[column.fieldname] < 0) {
+ value = "<span style='color:red'>" + value + "</span>";
+ }
+ else if (data[column.fieldname] > 0) {
+ value = "<span style='color:green'>" + value + "</span>";
+ }
+ }
+
+ return value;
+ }
}