Best practices on how to import data into OpenERP. Cyril Morisse, Audaxis
1. BEST PRACTICES ON HOW TO
IMPORT DATA INTO OPENERP
Why
you
should
love
CSV
Import
Cyril
MORISSE
(
@cmorisse
)
2.
Introduc*on
¨ With
Test
Driven
Development
and
Data
Migra*on,
we
need
to
gather
and
enter
real
data
owned
by
users
¨ We
need
a
data
format
within
user’s
reach
(compared
to
XML)
¨ As
of
version
7.0
OpenERP
has
redesigned
the
import
system
(“base_import”
module):
¤ It
has
nearly
everything
right
out
of
the
box
¤ Only
missing
feature
is
user
oriented
documenta*on
¨ This
talk
is
an
overview
of
the
module
3. Installa*on
¨ Export
func*onality
is
available
right
out
of
the
box
¨ BUT
import
func*onality
must
be
installed:
¤ Import
is
covered
by
“base_import”
module
¤ Import
must
be
installed
via
SeTngs
/
Configura*on
/
General
SeTngs
¨ Then
“Import”
link
is
available
in
all
list/tree
views
4. CSV
import
issues
¨ When
impor*ng
data
using
CSV,
you
will
face
3
main
issues:
¤ Iden*fy
the
fields
required
for
an
import
¤ Understand
“OpenERP
External
IDs”
¤ Understand
how
to
import
the
different
type
of
fields
n Simple
fields
(
date,
text,
numbers,
boolean,…)
n Rela*onal
fields:
n Many2many
n Many2One
n One2many
5. Iden*fy
fields
to
import
¨ To
iden*fy
the
columns
required
to
import
an
object:
1. Ac*vate
“Developer
Mode”
2. Write
down
all
the
fields
you
must
enter
manually
3. Export
a
file
with
all
these
fields
4. Delete
values
in
the
id
column
then
re-‐import
the
file
to
check
everything
is
ok
5. If
a
column
is
missing
;
do
it
again
from
step
3
and
add
the
column
6. Understand
IDs
¨ Example
Product
categories
¨ CSV
Import
allows
User
Defined
External
IDs
¤ External
IDs
are
symbolic
names
for
records
¤ Format
is
module_name.id_name
7. Understand
IDs
(con*nued)
¨ User
defined
IDs
are
saved
in
the
database
and
can
be
retrieved
via:
¤ SeTngs
/
Technical
/
Sequences
&
Iden*fiers
/
External
Iden*fiers
8. Understand
IDs
(end)
¨ User
defined
IDs
allow
to
manage
Import
/
Update
of
data
¨ During
import:
¤ If
a
record
exists
with
this
ID,
OpenERP
will
update
the
record
¤ If
no
record
exists
with
this
ID,
OpenERP
will
create
a
new
record
¨ Export
IDs
¤ During
Export,
OpenERP
creates
an
export
ID
for
all
records
without
IDs
(manually
created
records)
¨ In
the
database
all
External
IDs
are
stored
in
table
ir_model_data
9. Import
simple
Fields
Field type Cell content Example
char, text Content surrounded by “ “This is a text ""value”"."
float Number with . as decimal
separator
3.15
boolean True or False “0” or 0 or “False” or False
or “1” or 1 or “True” or True
date YYYY-MM-DD 2013-06-10
datetime YYYY-MM-DD HH:MM:SS 2013-06-10 07:07
selection Value as given by
“developer mode” inspector
reference Value in database is
“object,id”
10. Import
rela*ons:
Many2One
¨ Many2one
¨ This
is
the
simplest
rela*on
to
import
in
CSV
¤ Just
use
id
of
referenced
object
id
parent_id
product_category
...
11. Import
rela*ons:
Many2Many
¨ Eg.
Customer
Tags
¨ Many2many
involves
3
tables
¨ Really
simple
in
CSV
;
enter
all
values
separated
by
comma
with
no
space
...
id
res_partner
id
...
res_partner_category
category_idpartner_id
res_partner_res_partner_category_rel
12. Import
rela*ons:
One2Many
¨ Eg.
Quota*ons/
Quota*ons
Lines
¨ In
CSV:
Enter
lines
while
you
don’t
repeat
header
object
fields
¤ Child
objects
column
format
is
“one2many_fieldname/child_object_field”
...
id
sale_order
id
order_id
sale_order_line
...
13. Integrate
CSV
in
your
development
workflow
¨ Create
a
set
of
shared
Google
Spreadsheet
that
your
users
will
complete
with
project
data
¨ Organize
your
OpenERP
project
in
3
modules:
¤ project_core
with
code
and
technical
parameters
¤ project_data
:
will
contains
only
data
in
CSV
files
¤ project_test
:
contains
your
test
code
and
test
specific
data
¨ Use
a
tool
to
automate
export
and
download
of
the
Google
Spreadsheet
into
the
project_data
module
¤ hkp://bitbucket.org/cmorisse/edgdd
¨ Your
users
will
be
able
to
“coopera*vely”
enter
their
data
and
you
will
be
able
to
seamlessly
integrate
and
use
this
data
in
your
project