Commit cdb288c9 by Damien Moulard

orders export module, between 2 dates

parent eb1e61d0
Pipeline #2402 passed with stage
in 1 minute 24 seconds
......@@ -351,6 +351,21 @@ class Orders(models.Model):
return labels_data
@staticmethod
def get_orders_between_dates(date_from, date_to):
"""@depends on Odoo module lacagette_purchase"""
o_api = OdooAPI()
params = {'date_from': date_from, 'date_to': date_to}
res = {}
try:
res = o_api.execute('purchase.order', 'get_received_orders_between_dates', [], params)
except Exception as e:
res["error"] = str(e)
return res
class CagetteSuppliers(models.Model):
@staticmethod
......
......@@ -20,6 +20,7 @@ from . import monitor
from .views import FieldsView
from .views import ExportCompta
from .views import ExportPOS
from .views import ExportOrders
urlpatterns = [
......@@ -31,6 +32,7 @@ urlpatterns = [
url(r'^entity/example$', views.entity_example, name='entity example'),
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'^monitor/$', monitor.index),
url(r'^monitor/js_errors$', monitor.js_errors),
url(r'^members/', include('members.urls')),
......
......@@ -15,6 +15,7 @@ from .forms import ExportComptaForm
from outils.lib.compta import *
from openpyxl import Workbook
from openpyxl.writer.excel import save_virtual_workbook
from orders.models import Orders
def test_compta(request):
......@@ -375,3 +376,55 @@ class ExportPOS(View):
if not (month is None):
response = self.__ca_sessions_ng(month)
return response
class ExportOrders(View):
def get(self, request, *args, **kwargs):
u"""Display form"""
template = loader.get_template('outils/export_orders.html')
context = {'title': 'Export Commandes Réceptionnées'}
return HttpResponse(template.render(context, request))
def post(self, request, *args, **kwargs):
u"""Generate orders export between two dates"""
date_from = request.POST.get('from')
date_to = request.POST.get('to')
orders = Orders.get_orders_between_dates(date_from, date_to)
if "error" in orders:
error = "Une erreur est survenue, merci de contacter le service informatique."
return JsonResponse({'erreur': error, 'details': orders["error"]})
try:
wb = Workbook()
ws1 = wb.active
ws1.title = "Commandes réceptionnées"
ws1.append(['Fournisseur', 'Réf commande', 'Statut', 'Montant HT', 'Montant Total', 'Date réception'])
for order in orders["data"]:
supplier_name = order['supplier_name']
id_po = order['id_po']
amount_untaxed = order['amount_untaxed']
amount_total = order['amount_total']
if order['state'] == "purchase":
state = "Commande fournisseur"
elif order['state'] == "done":
state = "Terminé"
else:
state = order['state']
date_done_obj = datetime.datetime.strptime(order['date_done'], '%Y-%m-%d %H:%M:%S')
date_done = date_done_obj.strftime("%d/%m/%Y")
ws1.append([supplier_name, id_po, state, amount_untaxed, amount_total, date_done])
wb_name = 'export_orders_' + date_from + '_' + date_to + '.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."
return JsonResponse({'erreur': error, 'details': str(e)})
{% extends "base.html" %}
{% load static %}
{% block additionnal_scripts %}
{% endblock %}
{% block content %}
<form enctype="multipart/form-data" action="/export_orders" method="post">
{% csrf_token %}
<label for="from">Entre :</label>
<input type="date" name="from">
<label for="to">et :</label>
<input type="date" name="to">
<input type="submit" class='btn--primary' value="OK">
</form>
<script src="{% static "js/all_common.js" %}?v=1651853225"></script>
{% endblock %}
\ No newline at end of file
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