Skip to content

Commit

Permalink
assuring the standard measures are always available
Browse files Browse the repository at this point in the history
  • Loading branch information
jdetaeye committed Jan 24, 2025
1 parent 4d050c9 commit 2ec49e7
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 4 deletions.
Binary file modified doc/examples/forecasting/forecast-method.xlsx
Binary file not shown.
Binary file modified doc/examples/forecasting/forecast-netting.xlsx
Binary file not shown.
Binary file modified doc/examples/forecasting/forecast-with-missing-data.xlsx
Binary file not shown.
Binary file modified doc/examples/forecasting/middle-out-forecast.xlsx
Binary file not shown.
11 changes: 11 additions & 0 deletions freppledb/execute/management/commands/importworkbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
from django.template.loader import render_to_string

from freppledb import __version__
from freppledb.boot import addAttributesFromDatabase
from freppledb.common.middleware import _thread_locals
from freppledb.common.models import User, Comment, Parameter
from freppledb.common.report import GridReport, matchesModelName
from freppledb.common.dataload import parseExcelWorksheet
from freppledb.execute.models import Task
from freppledb.forecast.models import ForecastPlan


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -306,6 +308,15 @@ def handle(self, **options):

print("%s" % _("Done"))
# yield '<div><strong>%s</strong></div>' % _("Done")

# Modify the database tables to reflect all attributes
if self.database == DEFAULT_DB_ALIAS:
addAttributesFromDatabase()

# Modify the forecastplan table to reflect all measures
if "freppledb.forecast" in settings.INSTALLED_APPS:
ForecastPlan.refreshTableColumns()

except GeneratorExit:
logger.warning("Connection Aborted")
except Exception as e:
Expand Down
13 changes: 11 additions & 2 deletions freppledb/execute/management/commands/loaddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@
from django.conf import settings
from django.core.management.base import CommandError
from django.core.management.commands import loaddata
from django.db import connections, transaction
from django.db import connections, transaction, DEFAULT_DB_ALIAS
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _

from freppledb.common.models import User
from freppledb.common.models import User, addAttributesFromDatabase
from freppledb.common.middleware import _thread_locals
from freppledb.common.report import getCurrentDate
from freppledb.execute.models import Task
from freppledb.forecast.models import ForecastPlan


class Command(loaddata.Command):
Expand Down Expand Up @@ -133,6 +134,14 @@ def handle(self, *fixture_labels, **options):
# Excecute the standard django command
super().handle(*fixture_labels, **options)

# Modify the database tables to reflect all attributes
if database == DEFAULT_DB_ALIAS:
addAttributesFromDatabase()

# Modify the forecastplan table to reflect all measures
if "freppledb.forecast" in settings.INSTALLED_APPS:
ForecastPlan.refreshTableColumns()

# if the fixture doesn't contain the 'demo' word, let's not apply loaddata post-treatments
if "FREPPLE_TEST" in os.environ:
return
Expand Down
2 changes: 1 addition & 1 deletion freppledb/execute/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def loadExcel(self, *filepath, webservice=False):
def writeResults(self, resultpath, opplans):
basename = resultpath[-1].replace(".expect", ".out")
with open(os.path.join(settings.FREPPLE_LOGDIR, basename), "wt") as outputfile:
print("\n Wrote results to logs/%s.log" % basename)
print("\n Wrote results to logs/%s" % basename)
for i in opplans:
print(i.strip(), file=outputfile)

Expand Down
14 changes: 13 additions & 1 deletion freppledb/forecast/fixtures/initial.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
[
{"model": "execute.dataexport", "fields": {"name":"forecastreport.csv.gz","report":"freppledb.forecast.views.OverviewReport","arguments":{"buckets": "month", "horizontype": true, "horizonunit": "month", "horizonlength": 6}}}
{"model": "execute.dataexport", "fields": {"name":"forecastreport.csv.gz","report":"freppledb.forecast.views.OverviewReport","arguments":{"buckets": "month", "horizontype": true, "horizonunit": "month", "horizonlength": 6}}},
{"model":"forecast.measure", "fields": {"name": "forecastbaselinevalue", "label": "forecast baseline value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, forecastbaselinevalue, forecastbaseline * cost)", "update_expression": "if(cost != 0, forecastbaseline := newvalue /cost, forecastbaselinevalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "forecastconsumedvalue", "label": "forecast consumed value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, forecastconsumedvalue, forecastconsumed * cost)", "update_expression": "if(cost != 0, forecastconsumed := newvalue / cost, forecastconsumedvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "forecastnetvalue", "label": "forecast net value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, forecastnetvalue, forecastnet * cost)", "update_expression": "if(cost != 0, forecastnet := newvalue /cost, forecastnetvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "forecastoverridevalue", "label": "forecast override value", "type": "computed", "overrides": "forecastbaselinevalue", "mode_future": "edit", "mode_past": "view", "compute_expression": "if(cost == 0, forecastoverridevalue, if(forecastoverride == -1, -1, forecastoverride * cost))", "update_expression": "if(cost != 0, forecastoverride := if(newvalue == -1, -1, newvalue / cost), forecastoverridevalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "-1.0"}},
{"model":"forecast.measure", "fields": {"name": "forecastplannedvalue", "label": "planned forecast value", "type": "computed", "mode_future": "view", "mode_past": "hide", "compute_expression": "if(cost == 0, forecastplannedvalue, forecastplanned * cost)", "update_expression": "if(cost != 0, forecastplanned := newvalue /cost, forecastplannedvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "forecasttotalvalue", "label": "forecast total value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, forecasttotalvalue, forecasttotal * cost)", "update_expression": "if(cost != 0, forecasttotal:= newvalue /cost, forecasttotalvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "ordersadjustmentvalue", "label": "orders adjustment value", "type": "computed", "mode_future": "hide", "mode_past": "edit", "compute_expression": "if(cost == 0, ordersadjustmentvalue, ordersadjustment * cost)", "update_expression": "if(cost != 0, ordersadjustment := newvalue /cost, ordersadjustmentvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "ordersopenvalue", "label": "orders open value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, ordersopenvalue, ordersopen * cost)", "update_expression": "if(cost != 0, ordersopen := newvalue /cost, ordersopenvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "discrete": false, "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "ordersplannedvalue", "label": "planned orders value", "type": "computed", "mode_future": "view", "mode_past": "hide", "compute_expression": "if(cost == 0, ordersplannedvalue, ordersplanned * cost)", "update_expression": "if(cost != 0, ordersplanned := newvalue /cost, ordersplannedvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "orderstotalvalue", "label": "orders total value", "type": "computed", "mode_future": "view", "mode_past": "view", "compute_expression": "if(cost == 0, orderstotalvalue, orderstotal * cost)", "update_expression": "if(cost != 0, orderstotal := newvalue /cost, orderstotalvalue := newvalue)", "initially_hidden": true, "formatter": "currency", "defaultvalue": "0"}},
{"model":"forecast.measure", "fields": {"name": "forecasttotal", "label": "total forecast", "type": "computed", "mode_future": "view", "mode_past": "view", "description": "This row is what we'll plan supply for", "compute_expression": "if(forecastoverride == -1, forecastbaseline, forecastoverride)", "initially_hidden": false, "formatter": "number", "defaultvalue": "0"}}
{"model":"forecast.measure", "fields": {"name": "nodata", "label": "no data", "type": "local", "mode_future": "edit", "mode_past": "edit", "description": "Indicates gaps in the sales history", "initially_hidden": true, "formatter": "number", "defaultvalue": "0"}}
]

0 comments on commit 2ec49e7

Please sign in to comment.