Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
third-party
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
third-party
Commits
cdb288c9
Commit
cdb288c9
authored
Oct 04, 2022
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
orders export module, between 2 dates
parent
eb1e61d0
Pipeline
#2402
passed with stage
in 1 minute 24 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
0 deletions
+91
-0
models.py
orders/models.py
+15
-0
urls.py
outils/urls.py
+2
-0
views.py
outils/views.py
+53
-0
export_orders.html
templates/outils/export_orders.html
+21
-0
No files found.
orders/models.py
View file @
cdb288c9
...
...
@@ -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
...
...
outils/urls.py
View file @
cdb288c9
...
...
@@ -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'
)),
...
...
outils/views.py
View file @
cdb288c9
...
...
@@ -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
)})
templates/outils/export_orders.html
0 → 100644
View file @
cdb288c9
{% 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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment