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
0
Merge Requests
0
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
Alexis AOUN
third-party
Commits
e0c7746c
Commit
e0c7746c
authored
May 21, 2021
by
Damien Moulard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
script to import attached members
parent
4b64a1fe
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
202 additions
and
0 deletions
+202
-0
.gitignore
.gitignore
+1
-0
import_associated_members.py
outils/scripts/import_associated_members.py
+183
-0
scripts_settings_example.py
outils/scripts/scripts_settings_example.py
+18
-0
No files found.
.gitignore
View file @
e0c7746c
...
@@ -10,6 +10,7 @@ outils/settings_secret.py
...
@@ -10,6 +10,7 @@ outils/settings_secret.py
outils/config.py
outils/config.py
outils/texts/*
outils/texts/*
outils/js_errors.log
outils/js_errors.log
outils/scripts/scripts_settings.py
db.sqlite3
db.sqlite3
*/max_timeslot_carts.txt
*/max_timeslot_carts.txt
.gitlab-ci.yml
.gitlab-ci.yml
...
...
outils/scripts/import_associated_members.py
0 → 100644
View file @
e0c7746c
# coding: utf-8
import
sys
,
getopt
,
os
sys
.
path
.
append
(
os
.
path
.
abspath
(
'../..'
))
from
outils.common
import
OdooAPI
from
openpyxl
import
Workbook
from
openpyxl
import
load_workbook
from
openpyxl.styles
import
Alignment
import
datetime
from
openpyxl.utils.exceptions
import
InvalidFileException
def
main
():
""" Pass file as script arg """
if
len
(
sys
.
argv
)
<
2
:
print
(
"Il faut renseigner le chemin du fichier contenant les données des rattachés (format Excel)."
)
exit
(
2
)
api
=
OdooAPI
()
data_file
=
sys
.
argv
[
1
]
try
:
wb
=
load_workbook
(
data_file
)
except
InvalidFileException
:
print
(
"Le fichier fourni est invalide, il doit être au format Excel (.xlsx,.xlsm,.xltx,.xltm)"
)
exit
(
2
)
while
True
:
try
:
worksheet_number
=
input
(
f
'Numéro de la feuille contenant les données (entre 0 et {len(wb.worksheets)-1}) : '
)
worksheet_number
=
int
(
worksheet_number
)
ws
=
wb
.
worksheets
[
worksheet_number
]
except
ValueError
:
print
(
"Veuillez rentrer un numéro entier."
)
continue
except
IndexError
:
print
(
"Cette feuille n'existe pas."
)
continue
else
:
break
columns_valid
=
input
(
"""
Les colonnes doivent être les suivantes :
A: active*
B: barode_base*
C: name*
D: (ignorée)
E: date_inclusion
F: email
G: birthdate
H: mobile
I: phone
J: street
K: street2
L: zip
M: city
N: sex
O: (ignorée)
P: parent_member_id*
(* ces champs doivent être renseignés)
Vous confirmez ? (o/n) """
)
while
True
:
if
(
columns_valid
==
'n'
or
columns_valid
==
'N'
):
print
(
"Veuillez formatter correctement le fichier avant de continuer !"
)
exit
()
elif
(
columns_valid
==
'o'
or
columns_valid
==
'O'
):
break
else
:
columns_valid
=
input
(
"Vous confirmez ? (o/n) "
)
continue
users
=
[]
has_error
=
False
for
row
in
ws
.
iter_rows
(
min_row
=
2
,
values_only
=
True
):
# active
if
row
[
0
]
is
None
or
row
[
0
]
is
False
or
row
[
0
]
==
"=FALSE()"
or
row
[
0
]
==
"=false"
:
active
=
False
else
:
active
=
True
# If line is not empty (mandatory field check)
if
row
[
2
]
is
not
None
:
user
=
{
"is_member"
:
False
,
"is_associated_people"
:
True
,
"active"
:
active
,
"name"
:
row
[
2
],
"parent_id"
:
int
(
row
[
15
])
# for development, override with local existing member id
}
if
row
[
1
]
is
not
None
and
row
[
1
]
!=
"NON"
:
try
:
user
[
"barcode_base"
]
=
int
(
row
[
1
])
except
Exception
:
print
(
f
"[Mauvais format du champ 'barcode_base' pour l'utilisateur '{row[2]}' (Attendu : nombre entier)"
)
has_error
=
True
if
row
[
5
]
is
not
None
:
user
[
"email"
]
=
row
[
5
]
if
row
[
6
]
is
not
None
:
user
[
"birthdate"
]
=
str
(
row
[
6
]
.
date
())
if
row
[
7
]
is
not
None
:
try
:
mobile
=
str
(
row
[
7
])
.
replace
(
" "
,
""
)
if
mobile
[
0
]
!=
'+'
and
mobile
[
0
]
!=
'0'
:
mobile
=
'0'
+
mobile
user
[
"mobile"
]
=
mobile
except
Exception
:
print
(
f
"[Mauvais format du champ 'mobile' pour l'utilisateur '{row[2]}'"
)
has_error
=
True
if
row
[
8
]
is
not
None
:
try
:
phone
=
str
(
row
[
8
])
.
replace
(
" "
,
""
)
if
phone
[
0
]
!=
'+'
and
phone
[
0
]
!=
'0'
:
phone
=
'0'
+
phone
user
[
"phone"
]
=
phone
except
Exception
:
print
(
f
"[Mauvais format du champ 'phone' pour l'utilisateur '{row[2]}'"
)
has_error
=
True
if
row
[
9
]
is
not
None
:
user
[
"street"
]
=
row
[
9
]
if
row
[
10
]
is
not
None
:
user
[
"street2"
]
=
row
[
10
]
if
row
[
11
]
is
not
None
:
try
:
zipcode
=
str
(
int
(
row
[
11
]))
if
len
(
zipcode
)
==
4
:
zipcode
=
'0'
+
zipcode
user
[
"zip"
]
=
zipcode
except
Exception
:
print
(
f
"[Mauvais format du champ 'zipcode' pour l'utilisateur '{row[2]}'"
)
has_error
=
True
if
row
[
12
]
is
not
None
:
user
[
"city"
]
=
row
[
12
]
if
row
[
13
]
==
"Femme"
:
user
[
"sex"
]
=
"f"
elif
row
[
13
]
==
"Homme"
:
user
[
"sex"
]
=
"m"
users
.
append
(
user
)
if
has_error
:
print
(
"L'import a été interrompu, veuillez régler les erreurs."
)
exit
(
2
)
res
=
None
ids
=
[]
marshal_none_error
=
'cannot marshal None unless allow_none is enabled'
for
user
in
users
:
try
:
res
=
api
.
create
(
'res.partner'
,
user
)
if
res
:
print
(
f
"Rattaché.e importé.e avec succès : {user['name']} (id : {res})"
)
ids
.
append
(
res
)
except
Exception
as
e
:
if
not
(
marshal_none_error
in
str
(
e
)):
print
(
f
"Erreur lors de l'insertion de {user['name']}, vérifiez ses données dans le tableau ({str(e)})"
)
else
:
pass
# TODO : remove barcode?
# fields = {
# "barcode": ""
# }
# result_update = api.update('res.partner', ids, fields)
# TODO : "date_inclusion" (row[4])
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
outils/scripts/scripts_settings_example.py
0 → 100644
View file @
e0c7746c
SECRET_KEY
=
'Mettre_plein_de_caracteres_aleatoires_iezezezeezezci'
ODOO
=
{
'url'
:
'http://127.0.0.1:8069'
'user'
:
'api'
,
'passwd'
:
'xxxxxxxxxxxx'
,
'db'
:
'bd_test'
,
}
COUCHDB
=
{
'url'
:
'http://127.0.0.1:5984'
,
'dbs'
:
{
'member'
:
'coops'
,
'inventory'
:
'inventory'
,
'envelops'
:
'envelop'
,
'shop'
:
'shopping_carts'
}
}
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