Vous voici sur le Git Rural du CRAW

...
 
Commits (2)
......@@ -3,7 +3,7 @@ __email__ = 'p.houben@cra.wallonie.be'
__copyright__ = 'Copyright 2018-2020, Patrick HOUBEN'
__license__ = 'MIT'
__date__ = '2020-06-25'
__version__ = '1.4.1'
__version__ = '1.4.2'
__status__ = 'Stable'
# Version synonym
......
......@@ -67,7 +67,14 @@
<td>
<p>Majeur: Adaptations pour installation en local avec base de données SQLite</p>
</td>
</tr>
</tr>
<tr>
<td>1.4.2</td>
<td>15/07/2020</td>
<td>
<p>Mineur: Adaptations base de données SQLite</p>
</td>
</tr>
</tbody>
......
......@@ -273,6 +273,10 @@ def get_product(user, year):
"""
Specific query to get products
"""
if 'sqlite3' in DATABASES['default']['ENGINE']:
xdate_yyyymm = "strftime('%%Y-%%m', inputdate)"
else:
xdate_yyyymm = "to_char(inputdate, 'YYYY-MM')"
df = pd.DataFrame(columns=["xdate", "client_id", "client", "product", "atelier_id", "atelier", "amount", "amountvat"])
cursor = connection.cursor()
cursor.execute('''WITH rev AS (
......@@ -284,7 +288,7 @@ def get_product(user, year):
where r.profile_id = {0} and date_part('year', r.inputdate) = {1}
and cat.renta_exclude = False
)
SELECT strftime('%%Y-%%m', inputdate), c.id as client_id,
SELECT {2}, c.id as client_id,
c.company as client, t.name as product,
--CASE WHEN p.atelier_id is NULL THEN rev.atelier ELSE al.name END,
COALESCE(NULLIF(rev.atelier_id, al.id), rev.atelier_id),
......@@ -295,7 +299,7 @@ def get_product(user, year):
LEFT OUTER JOIN money_revenueproduct p ON (rev.id = p.revenue_id)
LEFT OUTER JOIN farm_atelier a ON (a.id = p.atelier_id)
LEFT OUTER JOIN farm_atelierlist al ON (a.atelier_id = al.id)
LEFT OUTER JOIN money_product t ON (p.product_id = t.id)'''.format(user.id, year)
LEFT OUTER JOIN money_product t ON (p.product_id = t.id)'''.format(user.id, year, xdate_yyyymm)
)
rows = cursor.fetchall()
if rows:
......