Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Odoo scripts
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo scripts
Commits
09606471
Commit
09606471
authored
3 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
import_jsonrpc: Add --allow-import-errors
parent
27db41a4
No related branches found
No related tags found
1 merge request
!68
🔖 14.0.0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
NEWS.rst
+1
-1
1 addition, 1 deletion
NEWS.rst
odoo_scripts/import_jsonrpc.py
+40
-10
40 additions, 10 deletions
odoo_scripts/import_jsonrpc.py
with
41 additions
and
11 deletions
NEWS.rst
+
1
−
1
View file @
09606471
...
...
@@ -11,7 +11,7 @@
``docker_build`` also tag with any current tag if any.
``import_jsonrpc``: Add ``--allow-missing-refs`` to log warnings
on missing XMLIDs instead of stopping
with
a
blocking error.
``import_jsonrpc``: Add
``--allow-import-errors`` &
``--allow-missing-refs`` to log warnings with
out
blocking error
s
.
13.3.0
------
...
...
This diff is collapsed.
Click to expand it.
odoo_scripts/import_jsonrpc.py
+
40
−
10
View file @
09606471
...
...
@@ -36,6 +36,7 @@
model_filenames
:
List
[
Dict
[
str
,
str
]],
delimiter
:
str
=
"
,
"
,
extra_context
:
Dict
[
str
,
str
]
=
dict
(),
allow_import_errors
:
bool
=
False
,
allow_missing_refs
:
bool
=
False
,
)
->
int
:
o
,
session_id
=
odoo_login
(
...
...
@@ -119,6 +120,9 @@
else
[(
5
,
0
,
0
)]
)
def
_one_line_error
(
error
):
return
str
(
error
).
replace
(
"
\n
"
,
"
"
).
replace
(
"
\r
"
,
"
"
)
o
.
env
.
context
[
"
tz
"
]
=
""
o
.
env
.
context
.
update
(
extra_context
)
# this dictionary is used to store the import.yaml loaded data to avoid
...
...
@@ -163,6 +167,7 @@
o
.
env
.
context
[
"
lang
"
]
=
lang
created
:
List
[
int
]
=
list
()
wrote
:
List
[
int
]
=
list
()
import_errors
:
List
[
str
]
=
list
()
# used with allow_import_errors
this_file_delimiter
=
yaml_delimiter
if
yaml_delimiter
else
delimiter
with
open
(
csv_file
,
"
r
"
)
as
csvfile
:
reader
=
csv
.
DictReader
(
...
...
@@ -235,9 +240,14 @@
_logger
.
debug
(
"
Write %s (%d)
"
,
model
,
write_id
)
try
:
o
.
env
[
model
].
write
(
write_id
,
values
)
except
RPCError
:
_logger
.
error
(
"
Current values (%s): %s
"
,
xmlid
,
values
)
raise
wrote
.
append
(
write_id
)
wrote
.
append
(
write_id
)
except
RPCError
as
error
:
if
allow_import_errors
:
error_msg
=
f
"
{
xmlid
}
:
{
_one_line_error
(
error
)
}
"
_logger
.
warning
(
error_msg
)
import_errors
.
append
(
error_msg
)
else
:
_logger
.
error
(
"
Values (%s): %s
"
,
xmlid
,
values
)
raise
else
:
_logger
.
debug
(
"
Creating a %s
"
,
model
)
...
...
@@ -242,4 +252,5 @@
else
:
_logger
.
debug
(
"
Creating a %s
"
,
model
)
created_id
=
None
try
:
created_id
=
o
.
env
[
model
].
create
(
values
)
...
...
@@ -244,10 +255,15 @@
try
:
created_id
=
o
.
env
[
model
].
create
(
values
)
except
RPCError
:
_logger
.
error
(
"
Current values (%s): %s
"
,
xmlid
,
values
)
raise
created
.
append
(
created_id
)
if
xmlid
:
created
.
append
(
created_id
)
except
RPCError
as
error
:
if
allow_import_errors
:
error_msg
=
f
"
{
xmlid
}
:
{
_one_line_error
(
error
)
}
"
_logger
.
warning
(
error_msg
)
import_errors
.
append
(
error_msg
)
else
:
_logger
.
error
(
"
Values (%s): %s
"
,
xmlid
,
values
)
raise
if
created_id
and
xmlid
:
_logger
.
debug
(
"
Adding xmlid %s for %d
"
,
xmlid
,
created_id
)
...
...
@@ -260,7 +276,7 @@
}
)
xmlid_cache
[
xmlid
]
=
created_id
if
(
len
(
created
)
+
len
(
wrote
))
%
100
==
0
:
if
(
len
(
created
)
+
len
(
wrote
)
+
len
(
import_errors
)
)
%
100
==
0
:
_logger
.
info
(
"
%s progress: created %d, wrote %d
"
,
model
,
...
...
@@ -271,6 +287,10 @@
_logger
.
info
(
"
%s: created %d, wrote %d
"
,
model
,
len
(
created
),
len
(
wrote
)
)
if
import_errors
:
_logger
.
warning
(
"
%s: %d errors
"
,
model
,
len
(
import_errors
))
with
open
(
f
"
{
csv_file
}
-errors.txt
"
,
"
w
"
)
as
error_f
:
error_f
.
write
(
"
\n
"
.
join
(
import_errors
))
if
old_context
:
key_to_pop
=
list
()
for
k
in
o
.
env
.
context
:
...
...
@@ -318,6 +338,15 @@
"
--context
"
,
help
=
"
Extra context (key=value)
"
,
action
=
"
append
"
)
parser
.
add_argument
(
"
--allow-import-errors
"
,
help
=
(
"
Log errors when a record could not be created / updated but keep
"
"
going through the rest of the file; then write them into
"
'"
<filename>-errors.txt
"
.
'
),
action
=
"
store_true
"
,
)
parser
.
add_argument
(
"
--allow-missing-refs
"
,
help
=
(
"
Log warnings on missing XMLIDs instead of stopping with a
"
...
...
@@ -348,6 +377,7 @@
),
delimiter
=
nmspc
.
delimiter
,
extra_context
=
extra_context
,
allow_import_errors
=
nmspc
.
allow_import_errors
,
allow_missing_refs
=
nmspc
.
allow_missing_refs
,
)
...
...
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