Vous voici sur le Git Rural du CRAW

Commit 1a1b7a89 authored by Patrick Houben's avatar Patrick Houben

to_char4sqlite

parent a40c144c
......@@ -2,7 +2,7 @@ __author__ = 'Patrick HOUBEN'
__email__ = 'p.houben@cra.wallonie.be'
__copyright__ = 'Copyright 2018-2020, Patrick HOUBEN'
__license__ = 'MIT'
__date__ = '2020-05-01'
__date__ = '2020-06-25'
__version__ = '1.4.1'
__status__ = 'Stable'
......
......@@ -262,10 +262,10 @@ class ProfileList(MyLoginRequiredMixin, ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
if 'postgresql' in DATABASES['default']['ENGINE']:
context['jours'] = 'jours'
else:
if 'sqlite3' in DATABASES['default']['ENGINE']:
context['jours'] = ''
else:
context['jours'] = 'jours'
return context
......
......@@ -57,13 +57,13 @@ if SERVER_NAME == "pythonprod":
SECURE_CONTENT_TYPE_NOSNIFF = True
CONN_MAX_AGE = 1800
else:
SETTINGS_FILE = 'config/settings_localhost.json'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'tresoferme.sqlite3'),
}
}
SETTINGS_FILE = 'config/settings.json'
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'tresoferme.sqlite3'),
# }
# }
# Import local parameters from JSON file
......@@ -78,6 +78,7 @@ def get_local_setting(setting, mysettings=local_settings):
raise ImproperlyConfigured(error_msg)
DATABASES = get_local_setting("DATABASES")
PROJECT_NAME = get_local_setting('PROJECT_NAME')
AUTH_USER_MODEL = get_local_setting('AUTH_USER_MODEL')
SECRET_KEY = get_local_setting('SECRET_KEY')
......
......@@ -10,6 +10,7 @@ import pandas as pd
from django.db import connection
from money.models import Expense, Revenue, Loan
from . import graph_display
from config.settings import DATABASES
LOG = logging.getLogger(__name__)
LOG_DEBUG = logging.getLogger("mydebug")
......@@ -43,13 +44,15 @@ class CollectRenta(object):
loanqs = Loan.objects.for_user(self.user).filter(closedate=None).exclude(loantype__id="EMP_CAI")
if loanqs:
if 'sqlite3' in DATABASES['default']['ENGINE']:
xdate_yyyymm = "strftime('%%Y-%%m', debitdate)"
else:
xdate_yyyymm = "to_char(debitdate, 'YYYY-MM')"
for loan in loanqs:
# rfd = loan.loanrefund_set.filter(debitdate__year=self.year).order_by("debitdate").extra(
# select={"xdate": "to_char(debitdate, 'YYYY-MM')"}
# )
rfd = loan.loanrefund_set.filter(debitdate__year=self.year).order_by("debitdate").extra(
select={"xdate": "strftime('%%Y-%%m', debitdate)"}
)
select={"xdate": xdate_yyyymm}
)
if rfd:
rfd_select = rfd.values("xdate", "expense__atelier__atelier__id",
......@@ -133,8 +136,14 @@ class CollectRenta(object):
df_loan = pd.DataFrame
model = eval(modeltxt)
qs = model.objects.for_user(self.user).filter(inputdate__year=self.year)
if 'sqlite3' in DATABASES['default']['ENGINE']:
xdate_yyyymm = "strftime('%%Y-%%m', inputdate)"
else:
xdate_yyyymm = "to_char(inputdate, 'YYYY-MM')"
qs = qs.order_by("inputdate").extra(
select={"xdate": "strftime('%%Y-%%m', inputdate)"}
select={"xdate": xdate_yyyymm}
)
if modeltxt == "Revenue":
# qs = qs.exclude(revcat="FRM_BDC").exclude(revcatgrp="EMP")
......@@ -208,11 +217,17 @@ class CollectTreso(object):
df = pd.DataFrame()
qs = model.objects.for_user(self.user).filter(inputdate__year=self.year)
if qs:
# Init xdate_yyyymm
if 'sqlite3' in DATABASES['default']['ENGINE']:
xdate_yyyymm = "strftime('%%Y-%%m', inputdate)"
else:
xdate_yyyymm = "to_char(inputdate, 'YYYY-MM')"
if model.__name__ == "Revenue":
qs = qs.exclude(revcat__id="FRM_BDC")
qs = qs.order_by("inputdate").extra(
select={"xdate": "strftime('%%Y-%%m', inputdate)", suffixvat: "amountvat", suffix: "amount"}
select={"xdate": xdate_yyyymm, suffixvat: "amountvat", suffix: "amount"}
)
qs = qs.values("xdate", group_column, suffixvat, suffix)
df = pd.DataFrame(list(qs))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment