Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cgscop_riga_import
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Le Filament
Confédération Générale des SCOP
cgscop_riga_import
Commits
0ab9dacd
Commit
0ab9dacd
authored
5 years ago
by
Benjamin
Browse files
Options
Downloads
Patches
Plain Diff
modif algo pour check riga sur coopérative
parent
2a34e6a7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
models/riga_odoo_import.py
+61
-60
61 additions, 60 deletions
models/riga_odoo_import.py
with
61 additions
and
60 deletions
models/riga_odoo_import.py
+
61
−
60
View file @
0ab9dacd
...
...
@@ -83,69 +83,70 @@ class CgscopRigaOdooImport(models.Model):
:param parent_id (string): header du fichier CSV pour lequel on va
rechercher l
'
ID RIGA de l
'
organisme
"""
# try:
file
.
seek
(
0
)
# Création du lecteur CSV.
reader
=
csv
.
DictReader
(
io
.
TextIOWrapper
(
file
,
encoding
=
"
utf-8-sig
"
,
newline
=
None
),
delimiter
=
'
;
'
)
model_obj
=
self
.
env
[
model
.
model
]
crea_nb
=
0
maj_nb
=
0
log
=
""
# Lecture de chaque ligne
for
row
in
reader
:
# Création de l'objet
vals
=
{}
for
field
in
table
:
vals
.
update
({
field
[
0
]:
self
.
_cast_type
(
model
=
model
,
field
=
field
[
0
],
value
=
row
[
field
[
1
]])
})
# Vérification de la ligne dans la base
line
=
model_obj
.
search
([
[
'
id_riga
'
,
'
=
'
,
row
[
primary_key
]]])
# Si il y a un enregistrement, on met à jour
if
line
:
line
.
write
(
vals
)
maj_nb
+=
1
else
:
# Check d'un organisme dans la base
partner
=
self
.
env
[
'
res.partner
'
].
search
([
[
'
id_riga
'
,
'
=
'
,
row
[
header_key
]]])
# Si l'organisme existe, on crée un enregistrement
if
partner
:
try
:
file
.
seek
(
0
)
# Création du lecteur CSV.
reader
=
csv
.
DictReader
(
io
.
TextIOWrapper
(
file
,
encoding
=
"
utf-8-sig
"
,
newline
=
None
),
delimiter
=
'
;
'
)
model_obj
=
self
.
env
[
model
.
model
]
crea_nb
=
0
maj_nb
=
0
log
=
""
# Lecture de chaque ligne
for
row
in
reader
:
# Création de l'objet
vals
=
{}
for
field
in
table
:
vals
.
update
({
'
partner_id
'
:
partner
.
id
field
[
0
]:
self
.
_cast_type
(
model
=
model
,
field
=
field
[
0
],
value
=
row
[
field
[
1
]])
})
model_obj
.
create
(
vals
)
crea_nb
+=
1
# Vérification de la ligne dans la base
line
=
model_obj
.
search
([
[
'
id_riga
'
,
'
=
'
,
row
[
primary_key
]],
[
'
is_cooperative
'
,
'
=
'
,
True
]])
# Si il y a un enregistrement, on met à jour
if
line
:
line
.
write
(
vals
)
maj_nb
+=
1
else
:
log
+=
(
"
Pas d
'
enredistrement trouvé pour l
'
id
"
+
row
[
primary_key
]
+
"
avec l
'
id riga
"
+
row
[
header_key
]
+
"
\n
"
)
# Création du log
self
.
create
({
'
model_id
'
:
model
.
id
,
'
is_sync
'
:
True
,
'
log
'
:
(
"
Import du fichier réussi :
\n
"
+
"
- Création de
"
+
str
(
crea_nb
)
+
"
lignes
\n
"
+
"
- Mise à jour de
"
+
str
(
maj_nb
)
+
"
lignes
\n\n
"
+
log
),
'
is_warning
'
:
True
if
log
else
False
,
})
# except Exception as e:
# _logger.error(e.__str__())
# # Création du log
# self.create({
# 'model_id': model.id,
# 'is_sync': False,
# 'is_error': True,
# 'log': str(e)
# })
# Check d'un organisme dans la base
partner
=
self
.
env
[
'
res.partner
'
].
search
([
[
'
id_riga
'
,
'
=
'
,
row
[
header_key
]]])
# Si l'organisme existe, on crée un enregistrement
if
partner
:
vals
.
update
({
'
partner_id
'
:
partner
.
id
})
model_obj
.
create
(
vals
)
crea_nb
+=
1
else
:
log
+=
(
"
Pas d
'
enredistrement trouvé pour l
'
id
"
+
row
[
primary_key
]
+
"
avec l
'
id riga
"
+
row
[
header_key
]
+
"
\n
"
)
# Création du log
self
.
create
({
'
model_id
'
:
model
.
id
,
'
is_sync
'
:
True
,
'
log
'
:
(
"
Import du fichier réussi :
\n
"
+
"
- Création de
"
+
str
(
crea_nb
)
+
"
lignes
\n
"
+
"
- Mise à jour de
"
+
str
(
maj_nb
)
+
"
lignes
\n\n
"
+
log
),
'
is_warning
'
:
True
if
log
else
False
,
})
except
Exception
as
e
:
_logger
.
error
(
e
.
__str__
())
# Création du log
self
.
create
({
'
model_id
'
:
model
.
id
,
'
is_sync
'
:
False
,
'
is_error
'
:
True
,
'
log
'
:
str
(
e
)
})
def
_cast_type
(
self
,
model
,
field
,
value
):
"""
Détermine en fonction du champ la valeur typée à renvoyer
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment