Commit 282d00cc by François COLOMBIER

Ajout fonctionnalité Export du capital détenu à une date donnée

parent 9904fbbe
Pipeline #3496 failed with stage
in 1 minute 26 seconds
......@@ -304,3 +304,14 @@ def get_odoo_account_export_report (export_id, final_format):
else:
report = generate_arithmethique_compatible_file(res[0])
return report
def get_members_capital_at_date(date,only_active):
try:
if only_active == 'on':
only_active = 1
else:
only_active = 0
return OdooAPI().execute("lacagette.exports", 'get_members_capital_at_date', {'date': date, 'only_active': only_active})
except Exception as e:
coop_logger.error("Erreur get_members_capital_at_date : %s", str(e))
return None
\ No newline at end of file
......@@ -21,6 +21,7 @@ from .views import FieldsView
from .views import ExportCompta
from .views import ExportPOS
from .views import ExportOrders
from .views import ExportCapital
urlpatterns = [
......@@ -33,6 +34,7 @@ urlpatterns = [
url(r'^export_compta$', ExportCompta.as_view(), name='export_compta'),
url(r'^export_pos$', ExportPOS.as_view(), name='Export POS'),
url(r'^export_orders$', ExportOrders.as_view(), name='export_orders'),
url(r'^export_capital$', ExportCapital.as_view(), name='export_capital'),
url(r'^monitor/$', monitor.index),
url(r'^monitor/js_errors$', monitor.js_errors),
url(r'^members/', include('members.urls')),
......
......@@ -435,3 +435,45 @@ class ExportOrders(View):
error = "Une erreur est survenue, merci de contacter le service informatique."
coop_logger.error("Erreur export_orders : %s", str(e))
return JsonResponse({'erreur': error, 'details': str(e)})
class ExportCapital(View):
def get(self, request, *args, **kwargs):
u"""Display form"""
template = loader.get_template('outils/export_capital.html')
context = {'title': 'Export Capital détenu'}
return HttpResponse(template.render(context, request))
def post(self, request, *args, **kwargs):
u"""Generate capital export at given date"""
date = request.POST.get('date')
only_active = request.POST.get('only_active')
capital_by_member_list_query = get_members_capital_at_date(date,only_active)
if 'data' in capital_by_member_list_query:
try:
wb = Workbook()
ws1 = wb.active
ws1.title = "Capital détenu par les membres à la date %s" % date
ws1.append(['Membre', 'Capital détenu (en euros)'])
for line in capital_by_member_list_query['data']:
ws1.append([line['membre'], line['capital_detenu']])
wb_name = 'export_capital_' + date + '.xlsx'
response = HttpResponse(content=save_virtual_workbook(wb),
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response['Content-Disposition'] = 'attachment; filename=' + wb_name
return response
except Exception as e:
error = "Une erreur est survenue, merci de contacter le service informatique."
coop_logger.error("Erreur export_capital : %s", str(e))
return JsonResponse({'erreur': error, 'details': str(e)})
else:
details = ''
if 'error' in capital_by_member_list_query:
details = capital_by_member_list_query['error']
return JsonResponse({'erreur': "La requête n'a pas aboutie", 'details': details})
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