purchase analytics based on pur order/pur receipt/pur invoice
diff --git a/buying/page/purchase_analytics/purchase_analytics.js b/buying/page/purchase_analytics/purchase_analytics.js
index 6919ad3..7d8171e 100644
--- a/buying/page/purchase_analytics/purchase_analytics.js
+++ b/buying/page/purchase_analytics/purchase_analytics.js
@@ -35,8 +35,10 @@
page: wrapper,
parent: $(wrapper).find('.layout-main'),
appframe: wrapper.appframe,
- doctypes: ["Item", "Item Group", "Supplier", "Supplier Type", "Company",
- "Purchase Invoice", "Purchase Invoice Item", "Fiscal Year"],
+ doctypes: ["Item", "Item Group", "Supplier", "Supplier Type", "Company", "Fiscal Year",
+ "Purchase Invoice", "Purchase Invoice Item",
+ "Purchase Order", "Purchase Order Item[Purchase Analytics]",
+ "Purchase Receipt", "Purchase Receipt Item[Purchase Analytics]"],
tree_grid: { show: true }
});
@@ -102,6 +104,8 @@
filter: function(val, item, opts, me) {
return me.apply_zero_filter(val, item, opts, me);
}},
+ {fieldtype:"Select", label: "Based On", options:["Purchase Invoice",
+ "Purchase Order", "Purchase Receipt"]},
{fieldtype:"Select", label: "Value or Qty", options:["Value", "Quantity"]},
{fieldtype:"Select", label: "Company", link:"Company",
default_value: "Select Company..."},
@@ -124,7 +128,11 @@
this.filter_inputs.tree_type.change(function() {
me.filter_inputs.refresh.click();
});
-
+
+ this.filter_inputs.based_on.change(function() {
+ me.filter_inputs.refresh.click();
+ });
+
this.show_zero_check()
this.setup_plot_check();
},
@@ -135,8 +143,6 @@
prepare_data: function() {
var me = this;
if (!this.tl) {
- this.make_transaction_list("Purchase Invoice", "Purchase Invoice Item");
-
// add 'Not Set' Supplier & Item
// Add 'All Supplier Types' Supplier Type
// (Supplier / Item are not mandatory!!)
@@ -164,6 +170,11 @@
});
}
+ if (!this.tl || !this.tl[this.based_on]) {
+ this.make_transaction_list(this.based_on, this.based_on + " Item");
+ }
+
+
if(!this.data || me.item_type != me.tree_type) {
if(me.tree_type=='Supplier') {
var items = wn.report_dump.data["Supplier"];
@@ -214,11 +225,12 @@
var to_date = dateutil.str_to_obj(this.to_date);
var is_val = this.value_or_qty == 'Value';
- $.each(this.tl, function(i, tl) {
+ $.each(this.tl[this.based_on], function(i, tl) {
if (me.is_default('company') ? true : me.apply_filter(tl, "company")) {
var posting_date = dateutil.str_to_obj(tl.posting_date);
if (posting_date >= from_date && posting_date <= to_date) {
- var item = me.item_by_name[tl[me.tree_grid.item_key]] || me.item_by_name['Not Set'];
+ var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
+ me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.amount : tl.qty);
}
}
diff --git a/startup/report_data_map.py b/startup/report_data_map.py
index feffae7..dc1833d 100644
--- a/startup/report_data_map.py
+++ b/startup/report_data_map.py
@@ -254,7 +254,42 @@
"item_code": ["Item", "name"]
}
},
-
+ "Purchase Order": {
+ "columns": ["name", "supplier", "transaction_date as posting_date", "company"],
+ "conditions": ["docstatus=1"],
+ "order_by": "posting_date",
+ "links": {
+ "supplier": ["Supplier", "name"],
+ "company":["Company", "name"]
+ }
+ },
+ "Purchase Order Item[Purchase Analytics]": {
+ "columns": ["parent", "item_code", "qty", "amount"],
+ "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
+ "order_by": "parent",
+ "links": {
+ "parent": ["Purchase Order", "name"],
+ "item_code": ["Item", "name"]
+ }
+ },
+ "Purchase Receipt": {
+ "columns": ["name", "supplier", "posting_date", "company"],
+ "conditions": ["docstatus=1"],
+ "order_by": "posting_date",
+ "links": {
+ "supplier": ["Supplier", "name"],
+ "company":["Company", "name"]
+ }
+ },
+ "Purchase Receipt Item[Purchase Analytics]": {
+ "columns": ["parent", "item_code", "qty", "amount"],
+ "conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
+ "order_by": "parent",
+ "links": {
+ "parent": ["Purchase Receipt", "name"],
+ "item_code": ["Item", "name"]
+ }
+ },
# Support
"Support Ticket": {
"columns": ["name","status","creation","resolution_date","first_responded_on"],