Merge pull request #21992 from rohitwaghchaure/fixed-forecasting-data-and-changed-columns-pre-release

refactor: display the order's data for past period
This commit is contained in:
rohitwaghchaure 2020-05-28 09:59:23 +05:30 committed by GitHub
commit 02a2bb77a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,6 @@ class ExponentialSmoothingForecast(object):
if value.get(period.key) and not forecast_data: if value.get(period.key) and not forecast_data:
value[forecast_key] = flt(value.get("avg", 0)) or flt(value.get(period.key)) value[forecast_key] = flt(value.get("avg", 0)) or flt(value.get(period.key))
# will be use to forecaset next period
forecast_data.append([value.get(period.key), value.get(forecast_key)])
elif forecast_data: elif forecast_data:
previous_period_data = forecast_data[-1] previous_period_data = forecast_data[-1]
value[forecast_key] = (previous_period_data[1] + value[forecast_key] = (previous_period_data[1] +
@ -31,6 +29,10 @@ class ExponentialSmoothingForecast(object):
) )
) )
if value.get(forecast_key):
# will be use to forecaset next period
forecast_data.append([value.get(period.key), value.get(forecast_key)])
class ForecastingReport(ExponentialSmoothingForecast): class ForecastingReport(ExponentialSmoothingForecast):
def __init__(self, filters=None): def __init__(self, filters=None):
self.filters = frappe._dict(filters or {}) self.filters = frappe._dict(filters or {})
@ -78,7 +80,9 @@ class ForecastingReport(ExponentialSmoothingForecast):
list_of_period_value = [value.get(p.key, 0) for p in self.period_list] list_of_period_value = [value.get(p.key, 0) for p in self.period_list]
if list_of_period_value: if list_of_period_value:
value["avg"] = sum(list_of_period_value) / len(list_of_period_value) total_qty = [1 for d in list_of_period_value if d]
if total_qty:
value["avg"] = flt(sum(list_of_period_value)) / flt(sum(total_qty))
def get_data_for_forecast(self): def get_data_for_forecast(self):
cond = "" cond = ""
@ -152,15 +156,19 @@ class ForecastingReport(ExponentialSmoothingForecast):
"width": 130 "width": 130
}] }]
width = 150 if self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] else 100 width = 180 if self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] else 100
for period in self.period_list: for period in self.period_list:
if (self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"] if (self.filters.periodicity in ['Yearly', "Half-Yearly", "Quarterly"]
or period.from_date >= getdate(self.filters.from_date)): or period.from_date >= getdate(self.filters.from_date)):
forecast_key = 'forecast_' + period.key forecast_key = period.key
label = _(period.label)
if period.from_date >= getdate(self.filters.from_date):
forecast_key = 'forecast_' + period.key
label = _(period.label) + " " + _("(Forecast)")
columns.append({ columns.append({
"label": _(period.label), "label": label,
"fieldname": forecast_key, "fieldname": forecast_key,
"fieldtype": self.fieldtype, "fieldtype": self.fieldtype,
"width": width, "width": width,