From d6d81cbba737fda407569faf2f6acd619497ae17 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 09:43:04 +0100 Subject: [PATCH 01/20] ADD invoice workspace --- backend/workspaces/Invoice/actions/README.md | 0 backend/workspaces/Invoice/jobs/README.md | 0 backend/workspaces/Invoice/pages/README.md | 0 backend/workspaces/Invoice/permissions.py | 28 +++++++++++++++++ .../workspaces/Invoice/templates/README.md | 0 backend/workspaces/Invoice/views/README.md | 0 backend/workspaces/Invoice/workspace.py | 31 +++++++++++++++++++ backend/workspaces/Invoices/actions/README.md | 0 backend/workspaces/Invoices/jobs/README.md | 0 backend/workspaces/Invoices/pages/README.md | 0 backend/workspaces/Invoices/permissions.py | 28 +++++++++++++++++ .../workspaces/Invoices/templates/README.md | 0 backend/workspaces/Invoices/views/README.md | 0 backend/workspaces/Invoices/workspace.py | 31 +++++++++++++++++++ 14 files changed, 118 insertions(+) create mode 100644 backend/workspaces/Invoice/actions/README.md create mode 100644 backend/workspaces/Invoice/jobs/README.md create mode 100644 backend/workspaces/Invoice/pages/README.md create mode 100644 backend/workspaces/Invoice/permissions.py create mode 100644 backend/workspaces/Invoice/templates/README.md create mode 100644 backend/workspaces/Invoice/views/README.md create mode 100644 backend/workspaces/Invoice/workspace.py create mode 100644 backend/workspaces/Invoices/actions/README.md create mode 100644 backend/workspaces/Invoices/jobs/README.md create mode 100644 backend/workspaces/Invoices/pages/README.md create mode 100644 backend/workspaces/Invoices/permissions.py create mode 100644 backend/workspaces/Invoices/templates/README.md create mode 100644 backend/workspaces/Invoices/views/README.md create mode 100644 backend/workspaces/Invoices/workspace.py diff --git a/backend/workspaces/Invoice/actions/README.md b/backend/workspaces/Invoice/actions/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoice/jobs/README.md b/backend/workspaces/Invoice/jobs/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoice/pages/README.md b/backend/workspaces/Invoice/pages/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoice/permissions.py b/backend/workspaces/Invoice/permissions.py new file mode 100644 index 0000000..3824409 --- /dev/null +++ b/backend/workspaces/Invoice/permissions.py @@ -0,0 +1,28 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.permission import Permission + +# Define your Permissions here + +class AdministrateInvoices(Permission): + description = "Access to the invoice and consumption administration" diff --git a/backend/workspaces/Invoice/templates/README.md b/backend/workspaces/Invoice/templates/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoice/views/README.md b/backend/workspaces/Invoice/views/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoice/workspace.py b/backend/workspaces/Invoice/workspace.py new file mode 100644 index 0000000..e3bedaa --- /dev/null +++ b/backend/workspaces/Invoice/workspace.py @@ -0,0 +1,31 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.workspace import Workspace + +"""This plugin (workspace) is for the administration of the invoices +""" + + +class Invoices(Workspace): + uri = "invoices" + description = "Invoices and consumptions" diff --git a/backend/workspaces/Invoices/actions/README.md b/backend/workspaces/Invoices/actions/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/jobs/README.md b/backend/workspaces/Invoices/jobs/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/pages/README.md b/backend/workspaces/Invoices/pages/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/permissions.py b/backend/workspaces/Invoices/permissions.py new file mode 100644 index 0000000..3824409 --- /dev/null +++ b/backend/workspaces/Invoices/permissions.py @@ -0,0 +1,28 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.permission import Permission + +# Define your Permissions here + +class AdministrateInvoices(Permission): + description = "Access to the invoice and consumption administration" diff --git a/backend/workspaces/Invoices/templates/README.md b/backend/workspaces/Invoices/templates/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/views/README.md b/backend/workspaces/Invoices/views/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/workspace.py b/backend/workspaces/Invoices/workspace.py new file mode 100644 index 0000000..e3bedaa --- /dev/null +++ b/backend/workspaces/Invoices/workspace.py @@ -0,0 +1,31 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.workspace import Workspace + +"""This plugin (workspace) is for the administration of the invoices +""" + + +class Invoices(Workspace): + uri = "invoices" + description = "Invoices and consumptions" From 605aa2bc3f2e6eec7c130ad6330c9d25fec80cfb Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 09:47:05 +0100 Subject: [PATCH 02/20] REMOVE duplicate workspace files --- backend/workspaces/Invoice/actions/README.md | 0 backend/workspaces/Invoice/jobs/README.md | 0 backend/workspaces/Invoice/pages/README.md | 0 backend/workspaces/Invoice/permissions.py | 28 ----------------- .../workspaces/Invoice/templates/README.md | 0 backend/workspaces/Invoice/views/README.md | 0 backend/workspaces/Invoice/workspace.py | 31 ------------------- 7 files changed, 59 deletions(-) delete mode 100644 backend/workspaces/Invoice/actions/README.md delete mode 100644 backend/workspaces/Invoice/jobs/README.md delete mode 100644 backend/workspaces/Invoice/pages/README.md delete mode 100644 backend/workspaces/Invoice/permissions.py delete mode 100644 backend/workspaces/Invoice/templates/README.md delete mode 100644 backend/workspaces/Invoice/views/README.md delete mode 100644 backend/workspaces/Invoice/workspace.py diff --git a/backend/workspaces/Invoice/actions/README.md b/backend/workspaces/Invoice/actions/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/workspaces/Invoice/jobs/README.md b/backend/workspaces/Invoice/jobs/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/workspaces/Invoice/pages/README.md b/backend/workspaces/Invoice/pages/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/workspaces/Invoice/permissions.py b/backend/workspaces/Invoice/permissions.py deleted file mode 100644 index 3824409..0000000 --- a/backend/workspaces/Invoice/permissions.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -The roseguarden project - -Copyright (C) 2018-2020 Marcus Drobisch, - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -__authors__ = ["Marcus Drobisch"] -__contact__ = "roseguarden@fabba.space" -__credits__ = [] -__license__ = "GPLv3" - -from core.workspaces.permission import Permission - -# Define your Permissions here - -class AdministrateInvoices(Permission): - description = "Access to the invoice and consumption administration" diff --git a/backend/workspaces/Invoice/templates/README.md b/backend/workspaces/Invoice/templates/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/workspaces/Invoice/views/README.md b/backend/workspaces/Invoice/views/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/backend/workspaces/Invoice/workspace.py b/backend/workspaces/Invoice/workspace.py deleted file mode 100644 index e3bedaa..0000000 --- a/backend/workspaces/Invoice/workspace.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -The roseguarden project - -Copyright (C) 2018-2020 Marcus Drobisch, - -This program is free software: you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free Software -Foundation, either version 3 of the License, or (at your option) any later -version. - -This program is distributed in the hope that it will be useful, but WITHOUT -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License along with -this program. If not, see . -""" - -__authors__ = ["Marcus Drobisch"] -__contact__ = "roseguarden@fabba.space" -__credits__ = [] -__license__ = "GPLv3" - -from core.workspaces.workspace import Workspace - -"""This plugin (workspace) is for the administration of the invoices -""" - - -class Invoices(Workspace): - uri = "invoices" - description = "Invoices and consumptions" From a5de5588c6d03166ce6ed406e13f6ac84d91cefa Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 09:47:57 +0100 Subject: [PATCH 03/20] FIX format --- backend/workspaces/Invoices/permissions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/workspaces/Invoices/permissions.py b/backend/workspaces/Invoices/permissions.py index 3824409..b5e2f0a 100644 --- a/backend/workspaces/Invoices/permissions.py +++ b/backend/workspaces/Invoices/permissions.py @@ -24,5 +24,6 @@ # Define your Permissions here + class AdministrateInvoices(Permission): description = "Access to the invoice and consumption administration" From adeb22503ebf7a705bb262fee5bff015f5bb0e1a Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 12:28:37 +0100 Subject: [PATCH 04/20] ADD page entry in backend and vue file for the frontend --- .../workspaces/Invoices/pages/consumptions.py | 37 +++++++++++++++ frontend/pages/invoices/consumptions.vue | 45 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 backend/workspaces/Invoices/pages/consumptions.py create mode 100644 frontend/pages/invoices/consumptions.vue diff --git a/backend/workspaces/Invoices/pages/consumptions.py b/backend/workspaces/Invoices/pages/consumptions.py new file mode 100644 index 0000000..65dfce8 --- /dev/null +++ b/backend/workspaces/Invoices/pages/consumptions.py @@ -0,0 +1,37 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.page import Page + +""" The consumption overview page +""" + + +class Consumptions(Page): + title = "Consumptions" # Shown label of the page in the menu + group = "Admin" # groupname multiple pages + icon = "mdi-food-apple" # icon (in typeset of material design icons) + route = "/invoices/consumptions" # routing + builder = "frontend" # page get build by the client (frontend) + rank = 1.6 # ranks (double) the page higher values are at the top of the menu + # groups will be ranked by the sum of the rank-values of their entries + requireLogin = True # login is required to view the page diff --git a/frontend/pages/invoices/consumptions.vue b/frontend/pages/invoices/consumptions.vue new file mode 100644 index 0000000..0b91012 --- /dev/null +++ b/frontend/pages/invoices/consumptions.vue @@ -0,0 +1,45 @@ + + + + + From 441ee1ef95eb52c9e54e20b18f16f1bfefc707ce Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 12:29:21 +0100 Subject: [PATCH 05/20] REMOVE thepermission because its not needed --- backend/workspaces/Invoices/permissions.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/backend/workspaces/Invoices/permissions.py b/backend/workspaces/Invoices/permissions.py index b5e2f0a..b2fbc2e 100644 --- a/backend/workspaces/Invoices/permissions.py +++ b/backend/workspaces/Invoices/permissions.py @@ -23,7 +23,3 @@ from core.workspaces.permission import Permission # Define your Permissions here - - -class AdministrateInvoices(Permission): - description = "Access to the invoice and consumption administration" From a9751c54d689b6135045f64e8888cff0fd0f155f Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 17 Feb 2023 17:32:17 +0100 Subject: [PATCH 06/20] ADD consumption-log model --- backend/workspaces/Invoices/models/README.md | 0 .../workspaces/Invoices/models/__init__.py | 1 + .../Invoices/models/consumption_log.py | 48 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 backend/workspaces/Invoices/models/README.md create mode 100644 backend/workspaces/Invoices/models/__init__.py create mode 100644 backend/workspaces/Invoices/models/consumption_log.py diff --git a/backend/workspaces/Invoices/models/README.md b/backend/workspaces/Invoices/models/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/models/__init__.py b/backend/workspaces/Invoices/models/__init__.py new file mode 100644 index 0000000..6acd968 --- /dev/null +++ b/backend/workspaces/Invoices/models/__init__.py @@ -0,0 +1 @@ +from .consumption_log import * # noqa: F401, F403 diff --git a/backend/workspaces/Invoices/models/consumption_log.py b/backend/workspaces/Invoices/models/consumption_log.py new file mode 100644 index 0000000..e34d5b3 --- /dev/null +++ b/backend/workspaces/Invoices/models/consumption_log.py @@ -0,0 +1,48 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from sqlalchemy_utils import ArrowType +import arrow + +from core import db +from core.users.models import User + + +class ConsumptionLog(db.Model): + id = db.Column(db.Integer, primary_key=True, index=True, autoincrement=True, unique=True) + entry_as_guest = db.Column(db.Boolean, default=None) + linked_user_id = db.Column(db.Integer, db.ForeignKey(User.id, ondelete="SET NULL")) + linked_user = db.relationship("User", backref="consumptions", foreign_keys=linked_user_id) + guest_is_member = db.Column(db.Boolean, default=None) + guest_email = db.Column(db.String(128), default=None) + + consumed_at = db.Column(ArrowType, default=arrow.utcnow) + created_at = db.Column(ArrowType, default=arrow.utcnow) + + service_area = db.Column(db.String(128), default=None) + service_name = db.Column(db.String(128), default=None) + service_quantity = db.Column(db.Float, default=None) + service_unit = db.Column(db.String(128), default=None) + + project_name = db.Column(db.String(128), default=None) + project_purpose = db.Column(db.String(128), default=None) + project_details = db.Column(db.String(128), default=None) From ab03ab22f9af38b68f72d387633387122b41cdc0 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Sun, 19 Feb 2023 14:23:18 +0100 Subject: [PATCH 07/20] ADD specific name for table --- backend/workspaces/Invoices/models/consumption_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/workspaces/Invoices/models/consumption_log.py b/backend/workspaces/Invoices/models/consumption_log.py index e34d5b3..96211b1 100644 --- a/backend/workspaces/Invoices/models/consumption_log.py +++ b/backend/workspaces/Invoices/models/consumption_log.py @@ -28,6 +28,7 @@ class ConsumptionLog(db.Model): + __tablename__ = 'invoice_consumption_log' id = db.Column(db.Integer, primary_key=True, index=True, autoincrement=True, unique=True) entry_as_guest = db.Column(db.Boolean, default=None) linked_user_id = db.Column(db.Integer, db.ForeignKey(User.id, ondelete="SET NULL")) From ce92684f2481814e37423eba4184d77498497d3f Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Sun, 19 Feb 2023 14:58:47 +0100 Subject: [PATCH 08/20] ADD alembic environment and base migration --- backend/workspaces/Invoices/models/README.md | 25 +++ .../workspaces/Invoices/models/alembic.ini | 83 +++++++++ .../Invoices/models/migrations/README.md | 0 .../Invoices/models/migrations/env.py | 157 ++++++++++++++++++ .../Invoices/models/migrations/script.py.mako | 25 +++ .../models/migrations/versions/000001_base.py | 48 ++++++ 6 files changed, 338 insertions(+) create mode 100644 backend/workspaces/Invoices/models/alembic.ini create mode 100644 backend/workspaces/Invoices/models/migrations/README.md create mode 100644 backend/workspaces/Invoices/models/migrations/env.py create mode 100644 backend/workspaces/Invoices/models/migrations/script.py.mako create mode 100644 backend/workspaces/Invoices/models/migrations/versions/000001_base.py diff --git a/backend/workspaces/Invoices/models/README.md b/backend/workspaces/Invoices/models/README.md index e69de29..652063f 100644 --- a/backend/workspaces/Invoices/models/README.md +++ b/backend/workspaces/Invoices/models/README.md @@ -0,0 +1,25 @@ +# General + +Place your models in this folder. + +The core loads all models imported in `__init__.py`. + +# Migrations + +You might use the alembic command lines to setup migration here. + +Run the command in the specific `models` folder + +## Create a new revision in `versions`: + +`alembic revision -m "name" --autogenerate --rev-id REV_ID` + +Please use the actual naming convention. E.g. `-m "name" --autogenerate --rev-id 000001`. + +## Upgrade to a new revision: + +`alembic upgrade REV_ID` + +## Stamp to an actual version (may be needed before upgrade or create a new revision): + +`alembic stamp --purge REV_ID` \ No newline at end of file diff --git a/backend/workspaces/Invoices/models/alembic.ini b/backend/workspaces/Invoices/models/alembic.ini new file mode 100644 index 0000000..6be3947 --- /dev/null +++ b/backend/workspaces/Invoices/models/alembic.ini @@ -0,0 +1,83 @@ +# A generic, single database configuration. + +[alembic] +# path to migration scripts +script_location = migrations + +# template used to generate migration files +# file_template = %%(rev)s_%%(slug)s + +# timezone to use when rendering the date +# within the migration file as well as the filename. +# string value is passed to dateutil.tz.gettz() +# leave blank for localtime +# timezone = + +# max length of characters to apply to the +# "slug" field +# truncate_slug_length = 40 + +# set to 'true' to run the environment during +# the 'revision' command, regardless of autogenerate +# revision_environment = false + +# set to 'true' to allow .pyc and .pyo files without +# a source .py file to be detected as revisions in the +# versions/ directory +# sourceless = false + +# version location specification; this defaults +# to migrations/versions. When using multiple version +# directories, initial revisions must be specified with --version-path +# version_locations = %(here)s/bar %(here)s/bat migrations/versions + +# the output encoding used when revision files +# are written from script.py.mako +# output_encoding = utf-8 + + +[post_write_hooks] +# post_write_hooks defines scripts or Python functions that are run +# on newly generated revision scripts. See the documentation for further +# detail and examples + +# format using "black" - use the console_scripts runner, against the "black" entrypoint +# hooks=black +# black.type=console_scripts +# black.entrypoint=black +# black.options=-l 79 + +# Logging configuration +[loggers] +keys = root,sqlalchemy,alembic + +[handlers] +keys = console + +[formatters] +keys = generic + +[logger_root] +level = WARN +handlers = console +qualname = + +[logger_sqlalchemy] +level = WARN +handlers = +qualname = sqlalchemy.engine + +[logger_alembic] +level = INFO +handlers = +qualname = alembic + +[handler_console] +class = StreamHandler +args = (sys.stderr,) +level = NOTSET +formatter = generic + +[formatter_generic] +format = %(levelname)-5.5s [%(name)s] %(message)s +datefmt = %H:%M:%S diff --git a/backend/workspaces/Invoices/models/migrations/README.md b/backend/workspaces/Invoices/models/migrations/README.md new file mode 100644 index 0000000..e69de29 diff --git a/backend/workspaces/Invoices/models/migrations/env.py b/backend/workspaces/Invoices/models/migrations/env.py new file mode 100644 index 0000000..a05c2e5 --- /dev/null +++ b/backend/workspaces/Invoices/models/migrations/env.py @@ -0,0 +1,157 @@ +from logging.config import fileConfig +import logging +from sqlalchemy import engine_from_config +from sqlalchemy import pool +import sqlalchemy_utils # noqa: F401 + +from alembic import context + +# this is the Alembic Config object, which provides +# access to the values within the .ini file in use. +config = context.config + +# Interpret the config file for Python logging. +# This line sets up loggers basically. +fileConfig(config.config_file_name) +logger = logging.getLogger('alembic.env') + +al_logger = logging.getLogger('alembic.runtime.migration') +al_logger.setLevel(logging.ERROR) + +# add your model's MetaData object here +# for 'autogenerate' support +# from myapp import mymodel +# target_metadata = mymodel.Base.metadata +import os +import sys +from pathlib import Path + + +file = Path(__file__).resolve() +parent, top, root = file.parent, file.parents[4], file.parents[5] + +sys.path.append(str(top)) +sys.path.append(str(file.parents[2])) + +logger.info(f"cwd {os.getcwd()} {top} {root} {file.parents[2]}") + +# fixme: set this per workspace +alembic_datatable_name = 'alembic_version_invoices' + +from core import db +import models +from config import configure_app, load_config + +target_metadata = db.Model.metadata + +# fixme: this is probably fine for our use case, but in configure_app() +# we also allow setting from os.environ.get('DATABASE_URL') +app_config = load_config("config.ini") +database_path = app_config["SYSTEM"].get("database_path", None) +basedir = file.parents[4] +print("\nX:", basedir) + +config.set_main_option( + 'sqlalchemy.url', database_path or os.environ.get("DATABASE_URL") or "sqlite:///" + os.path.join(basedir, "app.db") + ) + +# other values from the config, defined by the needs of env.py, +# can be acquired: +# my_important_option = config.get_main_option("my_important_option") +# ... etc. + + +def run_migrations_offline(): + """Run migrations in 'offline' mode. + + This configures the context with just a URL + and not an Engine, though an Engine is acceptable + here as well. By skipping the Engine creation + we don't even need a DBAPI to be available. + + Calls to context.execute() here emit the given string to the + script output. + + """ + url = config.get_main_option("sqlalchemy.url") + context.configure( + url=url, + target_metadata=target_metadata, + literal_binds=True, + dialect_opts={"paramstyle": "named"}, + ) + + with context.begin_transaction(): + context.run_migrations() + + +def include_object(obj, name, type_, reflected, compare_to): + """ + Should you include this table or not? + """ + if reflected is False: + if type(obj) == type(compare_to): + logger.info(f'No changes on {name}') + else: + logger.info(f'Changes found for {name}') + return True + return False + + +def render_item(type_, obj, autogen_context): + # custom render for sqalchemy_utils ChoiceType column and params + # May be better to use: https://stackoverflow.com/questions/30132370/trouble-when-using-alembic-with-sqlalchemy-utils + print(type(obj)) + if type_ == 'type' and type(obj).__name__ == "IntEnum": + col_type = "sa.Integer(), default=0" + return col_type + if type_ == 'type' and type(obj).__name__ == "IntFlag": + col_type = "sa.Integer(), default=0" + return col_type + + # default rendering for other objects + return False + + +def run_migrations_online(): + """Run migrations in 'online' mode. + + In this scenario we need to create an Engine + and associate a connection with the context. + + """ + + # this callback is used to prevent an auto-migration from being generated + # when there are no changes to the schema + # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html + def process_revision_directives(context, revision, directives): + if getattr(config.cmd_opts, 'autogenerate', False): + script = directives[0] + if script.upgrade_ops.is_empty(): + directives[:] = [] + logger.info('No changes in schema detected.') + + connectable = engine_from_config( + config.get_section(config.config_ini_section), + prefix="sqlalchemy.", + poolclass=pool.NullPool, + ) + + with connectable.connect() as connection: + context.configure( + connection=connection, + target_metadata=target_metadata, + render_item=render_item, + include_object=include_object, + version_table=alembic_datatable_name, + process_revision_directives=process_revision_directives, + ) + + with context.begin_transaction(): + context.run_migrations() + + +if context.is_offline_mode(): + run_migrations_offline() +else: + run_migrations_online() diff --git a/backend/workspaces/Invoices/models/migrations/script.py.mako b/backend/workspaces/Invoices/models/migrations/script.py.mako new file mode 100644 index 0000000..ee5cea7 --- /dev/null +++ b/backend/workspaces/Invoices/models/migrations/script.py.mako @@ -0,0 +1,25 @@ +"""${message} + +Revision ID: ${up_revision} +Revises: ${down_revision | comma,n} +Create Date: ${create_date} + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +${imports if imports else ""} + +# revision identifiers, used by Alembic. +revision = ${repr(up_revision)} +down_revision = ${repr(down_revision)} +branch_labels = ${repr(branch_labels)} +depends_on = ${repr(depends_on)} + + +def upgrade(): + ${upgrades if upgrades else "pass"} + + +def downgrade(): + ${downgrades if downgrades else "pass"} diff --git a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py new file mode 100644 index 0000000..b9bd3d6 --- /dev/null +++ b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py @@ -0,0 +1,48 @@ +"""base + +Revision ID: 000001 +Revises: +Create Date: 2023-02-19 14:57:34.049936 + +""" +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils + + +# revision identifiers, used by Alembic. +revision = '000001' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('invoice_consumption_log', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('entry_as_guest', sa.Boolean(), nullable=True), + sa.Column('linked_user_id', sa.Integer(), nullable=True), + sa.Column('guest_is_member', sa.Boolean(), nullable=True), + sa.Column('guest_email', sa.String(length=128), nullable=True), + sa.Column('consumed_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), + sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), + sa.Column('service_area', sa.String(length=128), nullable=True), + sa.Column('service_name', sa.String(length=128), nullable=True), + sa.Column('service_quantity', sa.Float(), nullable=True), + sa.Column('service_unit', sa.String(length=128), nullable=True), + sa.Column('project_name', sa.String(length=128), nullable=True), + sa.Column('project_purpose', sa.String(length=128), nullable=True), + sa.Column('project_details', sa.String(length=128), nullable=True), + sa.ForeignKeyConstraint(['linked_user_id'], ['users.id'], ondelete='SET NULL'), + sa.PrimaryKeyConstraint('id') + ) + op.create_index(op.f('ix_invoice_consumption_log_id'), 'invoice_consumption_log', ['id'], unique=True) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_index(op.f('ix_invoice_consumption_log_id'), table_name='invoice_consumption_log') + op.drop_table('invoice_consumption_log') + # ### end Alembic commands ### From 2418f7f989ce1ffc91f29f1708b1cfa745a75d24 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Sun, 19 Feb 2023 15:12:01 +0100 Subject: [PATCH 09/20] IMPROVE env.py to get workspace name automatically --- backend/workspaces/Invoices/models/migrations/env.py | 5 ++--- .../Invoices/models/migrations/versions/000001_base.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/workspaces/Invoices/models/migrations/env.py b/backend/workspaces/Invoices/models/migrations/env.py index a05c2e5..4e0a957 100644 --- a/backend/workspaces/Invoices/models/migrations/env.py +++ b/backend/workspaces/Invoices/models/migrations/env.py @@ -36,8 +36,8 @@ logger.info(f"cwd {os.getcwd()} {top} {root} {file.parents[2]}") # fixme: set this per workspace -alembic_datatable_name = 'alembic_version_invoices' - +alembic_datatable_name = 'migration_version_' + (str(file.parents[2].name)).lower() +print(alembic_datatable_name) from core import db import models from config import configure_app, load_config @@ -49,7 +49,6 @@ app_config = load_config("config.ini") database_path = app_config["SYSTEM"].get("database_path", None) basedir = file.parents[4] -print("\nX:", basedir) config.set_main_option( 'sqlalchemy.url', database_path or os.environ.get("DATABASE_URL") or "sqlite:///" + os.path.join(basedir, "app.db") diff --git a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py index b9bd3d6..c16c213 100644 --- a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py +++ b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py @@ -2,7 +2,7 @@ Revision ID: 000001 Revises: -Create Date: 2023-02-19 14:57:34.049936 +Create Date: 2023-02-19 15:10:22.868852 """ from alembic import op From cca42b6b64044e5cbb7ce1809dfbdfb6119e8d10 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Sun, 19 Feb 2023 15:16:35 +0100 Subject: [PATCH 10/20] FIX format --- .../Invoices/models/consumption_log.py | 2 +- .../Invoices/models/migrations/env.py | 22 +++++----- .../models/migrations/versions/000001_base.py | 43 ++++++++++--------- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/backend/workspaces/Invoices/models/consumption_log.py b/backend/workspaces/Invoices/models/consumption_log.py index 96211b1..99326c6 100644 --- a/backend/workspaces/Invoices/models/consumption_log.py +++ b/backend/workspaces/Invoices/models/consumption_log.py @@ -28,7 +28,7 @@ class ConsumptionLog(db.Model): - __tablename__ = 'invoice_consumption_log' + __tablename__ = "invoice_consumption_log" id = db.Column(db.Integer, primary_key=True, index=True, autoincrement=True, unique=True) entry_as_guest = db.Column(db.Boolean, default=None) linked_user_id = db.Column(db.Integer, db.ForeignKey(User.id, ondelete="SET NULL")) diff --git a/backend/workspaces/Invoices/models/migrations/env.py b/backend/workspaces/Invoices/models/migrations/env.py index 4e0a957..112c31f 100644 --- a/backend/workspaces/Invoices/models/migrations/env.py +++ b/backend/workspaces/Invoices/models/migrations/env.py @@ -13,9 +13,9 @@ # Interpret the config file for Python logging. # This line sets up loggers basically. fileConfig(config.config_file_name) -logger = logging.getLogger('alembic.env') +logger = logging.getLogger("alembic.env") -al_logger = logging.getLogger('alembic.runtime.migration') +al_logger = logging.getLogger("alembic.runtime.migration") al_logger.setLevel(logging.ERROR) # add your model's MetaData object here @@ -36,7 +36,7 @@ logger.info(f"cwd {os.getcwd()} {top} {root} {file.parents[2]}") # fixme: set this per workspace -alembic_datatable_name = 'migration_version_' + (str(file.parents[2].name)).lower() +alembic_datatable_name = "migration_version_" + (str(file.parents[2].name)).lower() print(alembic_datatable_name) from core import db import models @@ -51,8 +51,8 @@ basedir = file.parents[4] config.set_main_option( - 'sqlalchemy.url', database_path or os.environ.get("DATABASE_URL") or "sqlite:///" + os.path.join(basedir, "app.db") - ) + "sqlalchemy.url", database_path or os.environ.get("DATABASE_URL") or "sqlite:///" + os.path.join(basedir, "app.db") +) # other values from the config, defined by the needs of env.py, # can be acquired: @@ -90,9 +90,9 @@ def include_object(obj, name, type_, reflected, compare_to): """ if reflected is False: if type(obj) == type(compare_to): - logger.info(f'No changes on {name}') + logger.info(f"No changes on {name}") else: - logger.info(f'Changes found for {name}') + logger.info(f"Changes found for {name}") return True return False @@ -101,10 +101,10 @@ def render_item(type_, obj, autogen_context): # custom render for sqalchemy_utils ChoiceType column and params # May be better to use: https://stackoverflow.com/questions/30132370/trouble-when-using-alembic-with-sqlalchemy-utils print(type(obj)) - if type_ == 'type' and type(obj).__name__ == "IntEnum": + if type_ == "type" and type(obj).__name__ == "IntEnum": col_type = "sa.Integer(), default=0" return col_type - if type_ == 'type' and type(obj).__name__ == "IntFlag": + if type_ == "type" and type(obj).__name__ == "IntFlag": col_type = "sa.Integer(), default=0" return col_type @@ -124,11 +124,11 @@ def run_migrations_online(): # when there are no changes to the schema # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html def process_revision_directives(context, revision, directives): - if getattr(config.cmd_opts, 'autogenerate', False): + if getattr(config.cmd_opts, "autogenerate", False): script = directives[0] if script.upgrade_ops.is_empty(): directives[:] = [] - logger.info('No changes in schema detected.') + logger.info("No changes in schema detected.") connectable = engine_from_config( config.get_section(config.config_ini_section), diff --git a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py index c16c213..ec4a789 100644 --- a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py +++ b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py @@ -11,7 +11,7 @@ # revision identifiers, used by Alembic. -revision = '000001' +revision = "000001" down_revision = None branch_labels = None depends_on = None @@ -19,30 +19,31 @@ def upgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.create_table('invoice_consumption_log', - sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), - sa.Column('entry_as_guest', sa.Boolean(), nullable=True), - sa.Column('linked_user_id', sa.Integer(), nullable=True), - sa.Column('guest_is_member', sa.Boolean(), nullable=True), - sa.Column('guest_email', sa.String(length=128), nullable=True), - sa.Column('consumed_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), - sa.Column('created_at', sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), - sa.Column('service_area', sa.String(length=128), nullable=True), - sa.Column('service_name', sa.String(length=128), nullable=True), - sa.Column('service_quantity', sa.Float(), nullable=True), - sa.Column('service_unit', sa.String(length=128), nullable=True), - sa.Column('project_name', sa.String(length=128), nullable=True), - sa.Column('project_purpose', sa.String(length=128), nullable=True), - sa.Column('project_details', sa.String(length=128), nullable=True), - sa.ForeignKeyConstraint(['linked_user_id'], ['users.id'], ondelete='SET NULL'), - sa.PrimaryKeyConstraint('id') + op.create_table( + "invoice_consumption_log", + sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), + sa.Column("entry_as_guest", sa.Boolean(), nullable=True), + sa.Column("linked_user_id", sa.Integer(), nullable=True), + sa.Column("guest_is_member", sa.Boolean(), nullable=True), + sa.Column("guest_email", sa.String(length=128), nullable=True), + sa.Column("consumed_at", sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), + sa.Column("created_at", sqlalchemy_utils.types.arrow.ArrowType(), nullable=True), + sa.Column("service_area", sa.String(length=128), nullable=True), + sa.Column("service_name", sa.String(length=128), nullable=True), + sa.Column("service_quantity", sa.Float(), nullable=True), + sa.Column("service_unit", sa.String(length=128), nullable=True), + sa.Column("project_name", sa.String(length=128), nullable=True), + sa.Column("project_purpose", sa.String(length=128), nullable=True), + sa.Column("project_details", sa.String(length=128), nullable=True), + sa.ForeignKeyConstraint(["linked_user_id"], ["users.id"], ondelete="SET NULL"), + sa.PrimaryKeyConstraint("id"), ) - op.create_index(op.f('ix_invoice_consumption_log_id'), 'invoice_consumption_log', ['id'], unique=True) + op.create_index(op.f("ix_invoice_consumption_log_id"), "invoice_consumption_log", ["id"], unique=True) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### - op.drop_index(op.f('ix_invoice_consumption_log_id'), table_name='invoice_consumption_log') - op.drop_table('invoice_consumption_log') + op.drop_index(op.f("ix_invoice_consumption_log_id"), table_name="invoice_consumption_log") + op.drop_table("invoice_consumption_log") # ### end Alembic commands ### From 9b71829380033d32b2b8059bd20e0da7964d3a84 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Sun, 19 Feb 2023 15:18:06 +0100 Subject: [PATCH 11/20] FIX format --- backend/workspaces/Invoices/models/consumption_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/workspaces/Invoices/models/consumption_log.py b/backend/workspaces/Invoices/models/consumption_log.py index 96211b1..99326c6 100644 --- a/backend/workspaces/Invoices/models/consumption_log.py +++ b/backend/workspaces/Invoices/models/consumption_log.py @@ -28,7 +28,7 @@ class ConsumptionLog(db.Model): - __tablename__ = 'invoice_consumption_log' + __tablename__ = "invoice_consumption_log" id = db.Column(db.Integer, primary_key=True, index=True, autoincrement=True, unique=True) entry_as_guest = db.Column(db.Boolean, default=None) linked_user_id = db.Column(db.Integer, db.ForeignKey(User.id, ondelete="SET NULL")) From 6f0b2132d976a0d089abaf9e7166170a7a3ae700 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Thu, 2 Mar 2023 16:57:28 +0100 Subject: [PATCH 12/20] IMPROVE naming for guest to consume --- backend/workspaces/Invoices/models/consumption_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/workspaces/Invoices/models/consumption_log.py b/backend/workspaces/Invoices/models/consumption_log.py index 99326c6..354e5ef 100644 --- a/backend/workspaces/Invoices/models/consumption_log.py +++ b/backend/workspaces/Invoices/models/consumption_log.py @@ -30,7 +30,7 @@ class ConsumptionLog(db.Model): __tablename__ = "invoice_consumption_log" id = db.Column(db.Integer, primary_key=True, index=True, autoincrement=True, unique=True) - entry_as_guest = db.Column(db.Boolean, default=None) + consumed_as_guest = db.Column(db.Boolean, default=None) linked_user_id = db.Column(db.Integer, db.ForeignKey(User.id, ondelete="SET NULL")) linked_user = db.relationship("User", backref="consumptions", foreign_keys=linked_user_id) guest_is_member = db.Column(db.Boolean, default=None) From 1c2886a002d8e23293251fe20c896491ba900878 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Thu, 2 Mar 2023 17:14:41 +0100 Subject: [PATCH 13/20] FIX migration script --- .../Invoices/models/migrations/versions/000001_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py index ec4a789..9413f06 100644 --- a/backend/workspaces/Invoices/models/migrations/versions/000001_base.py +++ b/backend/workspaces/Invoices/models/migrations/versions/000001_base.py @@ -22,7 +22,7 @@ def upgrade(): op.create_table( "invoice_consumption_log", sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), - sa.Column("entry_as_guest", sa.Boolean(), nullable=True), + sa.Column("consumed_as_guest", sa.Boolean(), nullable=True), sa.Column("linked_user_id", sa.Integer(), nullable=True), sa.Column("guest_is_member", sa.Boolean(), nullable=True), sa.Column("guest_email", sa.String(length=128), nullable=True), From 2a6f527a35b63d95ff700170e2acfc0968a9e074 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Thu, 2 Mar 2023 17:22:58 +0100 Subject: [PATCH 14/20] ADD an action to add a consumption log --- .../Invoices/actions/createConsumptionLog.py | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 backend/workspaces/Invoices/actions/createConsumptionLog.py diff --git a/backend/workspaces/Invoices/actions/createConsumptionLog.py b/backend/workspaces/Invoices/actions/createConsumptionLog.py new file mode 100644 index 0000000..5789e92 --- /dev/null +++ b/backend/workspaces/Invoices/actions/createConsumptionLog.py @@ -0,0 +1,53 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.actions.action import Action +from core.logs import logManager +from core.actions import webclientActions +from core.users import userManager +from core.messages import send_mail, send_message +from core.actions import generateActionLink + +from workspaces.Invoices.models import ConsumptionLog + + +class CreateConsumptionLog(Action): + def __init__(self, app): + # logManager.info("Register of type Action created") + super().__init__(app, uri="createConsumptionLog") + + def handle(self, action, user, workspace, actionManager): + replyActions = [] + + consumption_log = ConsumptionLog() + consumption_log.consumed_as_guest = True + consumption_log.guest_email = "konglomerat@konglomerat.org" + consumption_log.guest_is_member = True + consumption_log.service_area = "Laser" + consumption_log.service_name = "Cameo" + consumption_log.service_quantity = 42.0 + consumption_log.service_unit = "min" + + workspace.db.session.add(consumption_log) + + replyActions.append(webclientActions.NotificationAction.generate("Consumption log created", "success")) + return "success", replyActions From b42c51819821479458ad0e76cdeb24c3a4de9dcc Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Thu, 2 Mar 2023 17:38:14 +0100 Subject: [PATCH 15/20] IMPROVE action --- .../Invoices/actions/createConsumptionLog.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/workspaces/Invoices/actions/createConsumptionLog.py b/backend/workspaces/Invoices/actions/createConsumptionLog.py index 5789e92..f18d26d 100644 --- a/backend/workspaces/Invoices/actions/createConsumptionLog.py +++ b/backend/workspaces/Invoices/actions/createConsumptionLog.py @@ -39,13 +39,13 @@ def handle(self, action, user, workspace, actionManager): replyActions = [] consumption_log = ConsumptionLog() - consumption_log.consumed_as_guest = True - consumption_log.guest_email = "konglomerat@konglomerat.org" - consumption_log.guest_is_member = True - consumption_log.service_area = "Laser" - consumption_log.service_name = "Cameo" - consumption_log.service_quantity = 42.0 - consumption_log.service_unit = "min" + consumption_log.consumed_as_guest = action.get("consumedAsGuest", True) + consumption_log.guest_email = action.get("guestEmail", "") + consumption_log.guest_is_member = action.get("guestIsMember", False) + consumption_log.service_area = action.get("serviceAreas", "") + consumption_log.service_name = action.get("serviceName", "") + consumption_log.service_quantity = action.get("serviceQuantity", 0.0) + consumption_log.service_unit = action.get("serviceUnit", "") workspace.db.session.add(consumption_log) From de39d8b0bb5c08e2bd290eb3419bc35889a3fc09 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Thu, 2 Mar 2023 20:57:28 +0100 Subject: [PATCH 16/20] ADD custom response --- backend/workspaces/Invoices/actions/createConsumptionLog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/workspaces/Invoices/actions/createConsumptionLog.py b/backend/workspaces/Invoices/actions/createConsumptionLog.py index f18d26d..f758bd5 100644 --- a/backend/workspaces/Invoices/actions/createConsumptionLog.py +++ b/backend/workspaces/Invoices/actions/createConsumptionLog.py @@ -50,4 +50,4 @@ def handle(self, action, user, workspace, actionManager): workspace.db.session.add(consumption_log) replyActions.append(webclientActions.NotificationAction.generate("Consumption log created", "success")) - return "success", replyActions + return "success", replyActions, {"custom": "customResponse"} From a5eb9541bb1aa49120c05dfa3380f3a6097b9839 Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Fri, 3 Mar 2023 21:31:55 +0100 Subject: [PATCH 17/20] ADD consume log view --- backend/workspaces/Invoices/views/consumed.py | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 backend/workspaces/Invoices/views/consumed.py diff --git a/backend/workspaces/Invoices/views/consumed.py b/backend/workspaces/Invoices/views/consumed.py new file mode 100644 index 0000000..92dc00d --- /dev/null +++ b/backend/workspaces/Invoices/views/consumed.py @@ -0,0 +1,81 @@ +""" +The roseguarden project + +Copyright (C) 2018-2020 Marcus Drobisch, + +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +You should have received a copy of the GNU General Public License along with +this program. If not, see . +""" + +__authors__ = ["Marcus Drobisch"] +__contact__ = "roseguarden@fabba.space" +__credits__ = [] +__license__ = "GPLv3" + +from core.workspaces.workspace import Workspace +from core.workspaces.dataView import DataView + +from core.common.deface import deface_string_end, deface_string_middle + +from core.users.models import User + +from workspaces.Invoices.models import ConsumptionLog + +""" A view contaning a list of all consumed logs +""" + + +class ConsumedList(DataView): + uri = "consumedList" + requireLogin = True + + def defineProperties(self): + self.addIntegerProperty(name="id", label="Id", isKey=True, hide=True) + self.addDatetimeProperty(name="consumed_at", label="Date") + self.addStringProperty(name="consumed_by", label="User") + self.addStringProperty(name="service", label="Service") + self.addStringProperty(name="amount", label="Amount") + self.addStringProperty(name="details", label="Details") + + def getViewHandler(self, user: User, workspace: Workspace, query=None): + print("getDataViewHandler for AuthenticatorRequestList") + + entrylist = [] + all_consume_logs = ConsumptionLog.query.all() + cl: ConsumptionLog + for cl in all_consume_logs: + # get new empty entry + entry = self.createEntry() + + # fill entry + entry.id = cl.id + entry.consumed_at = cl.consumed_at.format("YYYY-MM-DD HH:mm") + entry.service = f"[{cl.service_area}] {cl.service_name}" + entry.amount = f"{cl.service_quantity} {cl.service_unit}" + if cl.linked_user is None or cl.consumed_as_guest: + entry.consumed_by = "(Guest) " + str(cl.guest_email) + else: + entry.consumed_by = f"{cl.linked_user.firstname} {cl.linked_user.lastname} ({cl.linked_user.email})" + entry.details = f"{cl.project_purpose}" + + entrylist.append(entry.extract()) + return entrylist + + def __repr__(self): + return "<{} with {} properties>".format(self.name, len(self.properties)) + + # Handler for a request to create a new view entry + def createViewEntryHandler(self, user, workspace, entry): + print("Handle createViewEntry request for " + self.uri) + + # Handler for a request to update a single view entry + def updateViewEntryHandler(self, user, workspace, key, entry): + print("Handle updateViewEntryHandler request for " + self.uri) From a63f99960d1a95d4fcae3b3cc92f915a6a762b6e Mon Sep 17 00:00:00 2001 From: mdrobisch Date: Mon, 6 Mar 2023 23:56:02 +0100 Subject: [PATCH 18/20] ADD data request at mount and parsing after load --- frontend/pages/invoices/consumptions.vue | 62 ++++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/frontend/pages/invoices/consumptions.vue b/frontend/pages/invoices/consumptions.vue index 0b91012..0fa61f1 100644 --- a/frontend/pages/invoices/consumptions.vue +++ b/frontend/pages/invoices/consumptions.vue @@ -1,11 +1,21 @@ @@ -46,10 +62,11 @@ export default { components: {}, data: () => ({ info: "", - isUserDataLoading: true, - userData : [], - userHeaders : [], - userActions : [] + search: '', + isConsumptionsDataLoading: true, + consumptionsData : [], + consumptionsHeaders : [], + consumptionsActions : [] }), methods: { ok() {}, @@ -62,10 +79,10 @@ export default { } // updates local data for state change if(newValue['invoices/consumedList'] === 'ready') { - this.userData = viewParser.parseEntries('invoices/consumedList', this.viewDictionary); - this.userHeaders = viewParser.parseHeader('invoices/consumedList', this.viewDictionary); - this.userActions = viewParser.parseActions('invoices/consumedList', this.viewDictionary); - this.isUserDataLoading = false; + this.consumptionsData = viewParser.parseEntries('invoices/consumedList', this.viewDictionary); + this.consumptionsHeaders = viewParser.parseHeader('invoices/consumedList', this.viewDictionary); + this.consumptionsActions = viewParser.parseActions('invoices/consumedList', this.viewDictionary); + this.isConsumptionsDataLoading = false; } } },