Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
E
export_boxtal
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse du dépôt
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Le Filament
export_boxtal
Validations
57aa3edc
Valider
57aa3edc
rédigé
Il y a 7 mois
par
Benjamin - Le Filament
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
[REF] export data format
parent
31c130c1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
controllers/main.py
+53
-62
53 ajouts, 62 suppressions
controllers/main.py
avec
53 ajouts
et
62 suppressions
controllers/main.py
+
53
−
62
Voir le fichier @
57aa3edc
...
...
@@ -7,73 +7,70 @@ from io import BytesIO
from
odoo
import
http
from
odoo.http
import
content_disposition
,
request
from
odoo.tools.misc
import
xl
wt
from
odoo.tools.misc
import
xl
sxwriter
class
BoxtalExporter
(
http
.
Controller
):
def
export_xls
(
self
,
lignes_export
,
header
,
filename_
):
workbook
=
xlwt
.
Workbook
(
encoding
=
"
utf-8
"
)
worksheet
=
workbook
.
add_sheet
(
filename_
)
def
export_xlsx
(
self
,
lignes_export
,
header
,
filename_
):
output
=
BytesIO
()
workbook
=
xlsxwriter
.
Workbook
(
output
,
{
"
in_memory
"
:
True
})
worksheet
=
workbook
.
add_worksheet
(
filename_
)
for
i
,
fieldname
in
enumerate
(
header
):
worksheet
.
write
(
0
,
i
,
fieldname
)
worksheet
.
col
(
i
).
width
=
8000
# around 220 pixels
header_bold
=
workbook
.
add_format
(
{
"
bold
"
:
True
,
"
pattern
"
:
1
,
"
bg_color
"
:
"
#AAAAAA
"
}
)
base_style
=
xlwt
.
easyxf
(
"
align: wrap yes
"
)
for
i
,
fieldname
in
enumerate
(
header
):
worksheet
.
write
(
0
,
i
,
fieldname
,
header_bold
)
for
row_index
,
line
in
enumerate
(
lignes_export
):
for
cell_index
,
_h
in
enumerate
(
header
):
cell_style
=
base_style
if
line
[
cell_index
]
is
False
:
cell_value
=
""
elif
isinstance
(
line
[
cell_index
],
str
):
cell_value
=
re
.
sub
(
"
\r
"
,
"
"
,
line
[
cell_index
])
else
:
cell_value
=
line
[
cell_index
]
worksheet
.
write
(
row_index
+
1
,
cell_index
,
cell_value
,
cell_style
)
fp
=
BytesIO
()
workbook
.
save
(
fp
)
fp
.
seek
(
0
)
data
=
fp
.
read
()
fp
.
close
()
filename
=
filename_
+
"
.xls
"
csvhttpheaders
=
[
(
"
Content-Type
"
,
"
text/csv;charset=utf8
"
),
(
"
Content-Disposition
"
,
content_disposition
(
filename
)),
]
worksheet
.
write
(
row_index
+
1
,
cell_index
,
cell_value
,
)
return
request
.
make_response
(
data
,
headers
=
csvhttpheaders
)
workbook
.
close
()
xlsx_data
=
output
.
getvalue
()
return
request
.
make_response
(
xlsx_data
,
headers
=
[
(
"
Content-Type
"
,
"
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
"
,
),
(
"
Content-Disposition
"
,
content_disposition
(
filename_
+
"
.xlsx
"
)),
],
)
@http.route
(
"
/web/export_boxtal/
"
,
type
=
"
http
"
,
auth
=
"
user
"
)
@http.route
(
"
/web/export_boxtal/
"
,
type
=
"
http
"
,
auth
=
"
user
"
,
methods
=
[
"
GET
"
]
)
def
export_boxtal
(
self
,
sale_id
,
**
kwargs
):
header
=
[
"
Civilité
"
,
"
Nom
"
,
"
Prénom
"
,
"
Société
"
,
"
Adresse
"
,
"
Complément
"
,
"
Suite
"
,
"
Code postal
"
,
"
Ville
"
,
"
Etat ou province format ISO
"
,
"
Pays format ISO
"
,
"
Téléphone
"
,
"
Email
"
,
"
Informations importantes sur l
'
adresse
"
,
"
Catégorie du contenu
"
,
"
Description détaillée du contenu
"
,
"
Quantité
"
,
"
Poids (kg)
"
,
"
Largeur (cm)
"
,
"
Longueur (cm)
"
,
"
Hauteur (cm)
"
,
"
Valeur
"
,
"
Code point relais livraison
"
,
"
Référence interne
"
,
"
recipient_first_name
"
,
"
recipient_last_name
"
,
"
recipient_company
"
,
"
recipient_address_line_1
"
,
"
recipient_address_line_2
"
,
"
recipient_postal_code
"
,
"
recipient_city
"
,
"
recipient_country_iso_code
"
,
"
recipient_additional_information
"
,
"
recipient_phone
"
,
"
recipient_email
"
,
"
recipient_proximity_point
"
,
"
package_1_weight
"
,
"
package_1_length
"
,
"
package_1_width
"
,
"
package_1_height
"
,
"
package_1_value
"
,
"
external_reference
"
,
]
line
=
[]
filename_
=
""
...
...
@@ -81,29 +78,23 @@ class BoxtalExporter(http.Controller):
for
s
in
sale_ids
:
line
.
append
(
[
s
.
partner_id
.
title
.
shortcut
,
s
.
partner_id
.
lastname
,
s
.
partner_id
.
firstname
,
s
.
partner_id
.
parent_id
.
name
,
s
.
partner_id
.
lastname
,
s
.
partner_id
.
parent_id
.
name
or
""
,
s
.
partner_shipping_id
.
street
,
s
.
partner_shipping_id
.
street2
,
""
,
s
.
partner_shipping_id
.
zip
,
s
.
partner_shipping_id
.
city
,
s
.
partner_shipping_id
.
country_id
.
code
,
""
,
"
FR
"
,
s
.
partner_id
.
phone
,
s
.
partner_id
.
mobile
or
s
.
partner_id
.
phone
,
s
.
partner_id
.
email
,
""
,
"
Objets et tableaux courants
"
,
"
Refuges en bois pour petits animaux
"
,
"
1
"
,
s
.
partner_shipping_id
.
ref
[
3
:]
if
s
.
partner_shipping_id
.
ref
else
""
,
""
,
""
,
""
,
""
,
str
(
int
(
s
.
amount_total
)),
s
.
partner_shipping_id
.
ref
[
3
:],
s
.
amount_total
,
s
.
name
,
]
)
...
...
@@ -114,4 +105,4 @@ class BoxtalExporter(http.Controller):
+
datetime
.
now
().
strftime
(
"
%Y%m%d
"
)
)
return
self
.
export_xls
(
line
,
header
,
filename_
)
return
self
.
export_xls
x
(
line
,
header
,
filename_
)
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter