fix: Target variance report signs

This commit is contained in:
Anupam K 2020-07-24 02:32:45 +05:30
parent d6615248a8
commit 5d5f026a0d
4 changed files with 58 additions and 13 deletions

View File

@ -63,13 +63,13 @@ def get_columns(filters, period_list, partner_doctype):
"label": _(partner_doctype), "label": _(partner_doctype),
"fieldtype": "Link", "fieldtype": "Link",
"options": partner_doctype, "options": partner_doctype,
"width": 100 "width": 150
}, { }, {
"fieldname": "item_group", "fieldname": "item_group",
"label": _("Item Group"), "label": _("Item Group"),
"fieldtype": "Link", "fieldtype": "Link",
"options": "Item Group", "options": "Item Group",
"width": 100 "width": 150
}] }]
for period in period_list: for period in period_list:
@ -81,19 +81,19 @@ def get_columns(filters, period_list, partner_doctype):
"label": _("Target ({})").format(period.label), "label": _("Target ({})").format(period.label),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}, { }, {
"fieldname": period.key, "fieldname": period.key,
"label": _("Achieved ({})").format(period.label), "label": _("Achieved ({})").format(period.label),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}, { }, {
"fieldname": variance_key, "fieldname": variance_key,
"label": _("Variance ({})").format(period.label), "label": _("Variance ({})").format(period.label),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}]) }])
columns.extend([{ columns.extend([{
@ -101,19 +101,19 @@ def get_columns(filters, period_list, partner_doctype):
"label": _("Total Target"), "label": _("Total Target"),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}, { }, {
"fieldname": "total_achieved", "fieldname": "total_achieved",
"label": _("Total Achieved"), "label": _("Total Achieved"),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}, { }, {
"fieldname": "total_variance", "fieldname": "total_variance",
"label": _("Total Variance"), "label": _("Total Variance"),
"fieldtype": fieldtype, "fieldtype": fieldtype,
"options": options, "options": options,
"width": 100 "width": 150
}]) }])
return columns return columns
@ -154,10 +154,10 @@ def prepare_data(filters, sales_users_data, actual_data, date_field, period_list
if (r.get(sales_field) == d.parent and r.item_group == d.item_group and 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): 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[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_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 return rows

View File

@ -44,5 +44,20 @@ frappe.query_reports["Sales Partner Target Variance based on Item Group"] = {
options: "Quantity\nAmount", options: "Quantity\nAmount",
default: "Quantity" 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;
}
} }

View File

@ -44,5 +44,20 @@ frappe.query_reports["Sales Person Target Variance Based On Item Group"] = {
options: "Quantity\nAmount", options: "Quantity\nAmount",
default: "Quantity" 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;
}
} }

View File

@ -44,5 +44,20 @@ frappe.query_reports["Territory Target Variance Based On Item Group"] = {
options: "Quantity\nAmount", options: "Quantity\nAmount",
default: "Quantity" 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;
}
} }