Skip to main content

Python CSV to OpenERP importation library

Project description

csv2oerp is a convenient library to import data from CSV format to an OpenERP instance.

csv2oerp is a simple and rapid method to perform an import. Through a dictionary (dict-mapping) consisting of OpenERP fields bound to a column of the csv file and includes a search option, you can easily ordered your data before coding any lines as the manner of OpenERP. The structure of this dictionary is simple and intuitive. You can perform processing on a post-import field in particular, omit or modify it. You can also according to criterias, skip a line or do not decide to create an object being processed.

Quick start

Import csv2oerp and some callbacks:

>>> from csv2oerp import Import
>>> from csv2oerp.fields import Column, Custom, Relation
>>> from csv2oerp.callbacks import get_id, get_ids

Configure OpenERP connection:

>>> host = '198.168.0.1'
>>> port = 8069
>>> dbname = 'database'
>>> user = 'admin'
>>> pwd = 'admin'
>>> csv2oerp.connect(host, port, user, pwd, dbname)

Create a new importation instance:

>>> example_file = Import()

Set the CSV file to use:

>>> example_file.set_input_file('example_file.csv', ',', '"', 'utf-8')

Define a custom callback:

>>> def country_code(self, model, field, value, line):
...     """Return the first two uppered characters
...     """
...     return value[:2].upper()

Define your mapping to link both csv and OpenERP:

>>> example_file.set_mapping({

...     # Define a base model (Always in list form)
...     'res.partner.address': [{
...
...         # Custom field's value
...         'type':         Custom('default', search=True),

...         # Concatenated columns fields
...         'street':       Column([7, 6]),
...         'street2':      Column([8, 5]),

...         # Simple fields
...         'zip':          Column(9),
...         'city':         Column(10),
...         'cedex':        Column(68),
...         'phone':        Column(14),
...         'fax':          Column(15),
...         'email':        Column(17),

...         # Model's relation with dynamic insertion from OpenERP database
...         # Not native object from OpenERP framework
...         'region_id':    Custom(11, get_id('res.region', 'name'))
...         'dep_id':       Custom(12, get_id('res.dep', 'name'))

...         # Model's relations not updated if exists
...         'country_id':   Relation('REL_res_partner_address,NO_UPDATE::res.country'),

...         # Model's relations with unique value between objects
...         'partner_id':   Relation('REL_res_partner_address::res.partner', search=True),

...         },
...     ],

...     # Define relations between models
...     'REL_res_partner_address::res.partner': {
...         'name':         Column(1),
...         'siren':        Column(2),
...         'website':      Column(16),
...         'comment':      Column(56),
...         },

...     # Relation without write if exists
...     'REL_res_partner_address,NO_UPDATE::res.country':  {
...         'code':         Column(13, callback=_country_code, search=True),
...         'name':         Column(13, search=True),
...         },
...     })

Finally start the import process:

>>> example_file.start()

And show statistics of objects’s activities during the importation process:

>>> csv2oerp.show_stats()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csv2oerp-0.5.tar.gz (20.2 kB view details)

Uploaded Source

File details

Details for the file csv2oerp-0.5.tar.gz.

File metadata

  • Download URL: csv2oerp-0.5.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for csv2oerp-0.5.tar.gz
Algorithm Hash digest
SHA256 91ba5a092555341bc618b4e6dcffcad71acc08ec9898fe048c5507b33360cdba
MD5 54fd3067a937fc7e925abfa64f1afe31
BLAKE2b-256 fb4ed0ef21d9ffa3b93a319bb271e5ae2d4a2e8e5ce8519820dfaa9bf7158aac

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page