oerppy-hackers team mailing list archive
-
oerppy-hackers team
-
Mailing list archive
-
Message #00023
[Branch ~oerppy-hackers/oerppy/trunk] Rev 43: * Added a script and export class for getting the list of project names in
------------------------------------------------------------
revno: 43
committer: duncan@xxxxxxxxxx
branch nick: trunk
timestamp: Thu 2011-06-09 09:25:17 -0600
message:
* Added a script and export class for getting the list of project names in
OpenERP.
* Fixed up the csv exporter function to use the simple csv writer in addition
to the dict writer and to allow for string-based rows (as opposed to just
list-based ones).
* Fixed a bad variable name in the Canonical query class for monthly export of
all project timesheets.
added:
bin/export_project_names
modified:
TODO
oerppy/addons/canonical/query.py
oerppy/export.py
oerppy/scripting/base.py
--
lp:oerppy
https://code.launchpad.net/~oerppy-hackers/oerppy/trunk
Your team oerppy Hackers is subscribed to branch lp:oerppy.
To unsubscribe from this branch go to https://code.launchpad.net/~oerppy-hackers/oerppy/trunk/+edit-subscription
=== modified file 'TODO'
--- TODO 2011-06-09 14:24:33 +0000
+++ TODO 2011-06-09 15:25:17 +0000
@@ -1,4 +1,2 @@
-* Create a convenience method on the base Query class for getting an addon.
* Update the data models per the email from James Jesudason regarding the
Canonical customizations.
-* Add a script for getting all the project names.
=== added file 'bin/export_project_names'
--- bin/export_project_names 1970-01-01 00:00:00 +0000
+++ bin/export_project_names 2011-06-09 15:25:17 +0000
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+"""
+This is an example of a script that uses the default addon, i.e., standard
+OpenERP data.
+"""
+from oerppy import query
+from oerppy.addons.project import project_query
+from oerppy.config import get_config_data
+from oerppy.reg import registry
+from oerppy.scripting import base
+
+
+# get configuration; note that option parsing is handled by the script
+# class(es)
+config_data = get_config_data()
+# setup any addons that we want
+registry.add("base", query.Query)
+registry.add("project", project_query.ProjectQuery)
+# run the exporter
+all_weeks_export = base.OpenERPProjectsExport(config_data)
+all_weeks_export.run()
=== modified file 'oerppy/addons/canonical/query.py'
--- oerppy/addons/canonical/query.py 2011-06-09 14:24:33 +0000
+++ oerppy/addons/canonical/query.py 2011-06-09 15:25:17 +0000
@@ -49,7 +49,6 @@
entity=entity_name,
query=[],
fields=[])
- import pdb;pdb.set_trace()
return raw_results[0].keys()
def get_oem_users(self):
@@ -206,7 +205,7 @@
records = []
project_names = registry.get_addon("project").get_project_names()
for project_name in project_names:
- records = self.get_month_project_timesheets(
+ project_records = self.get_month_project_timesheets(
month, year, project_name)
- records.extend(records)
+ records.extend(project_records)
return records
=== modified file 'oerppy/export.py'
--- oerppy/export.py 2011-06-09 03:06:38 +0000
+++ oerppy/export.py 2011-06-09 15:25:17 +0000
@@ -1,13 +1,31 @@
import csv
+def setup_csv_dictwriter(data, file_handle):
+ header_row = data[0].keys()
+ writer = csv.DictWriter(file_handle, header_row)
+ writer.writerow(dict(zip(header_row, header_row)))
+ return writer
+
+
+def setup_csv_writer(file_handle):
+ return csv.writer(file_handle)
+
+
def export_csv(data, file_handle):
+ """
+ Export the records to a CSV file.
+ """
if not data:
return
- # Export the records to a CSV file
- header_row = data[0].keys()
- writer = csv.DictWriter(file_handle, header_row)
- writer.writerow(dict(zip(header_row, header_row)))
+ # Do some dispatching...
+ if isinstance(data[0], dict):
+ writer = setup_csv_dictwriter(data, file_handle)
+ else:
+ writer = setup_csv_writer(file_handle)
# Output the records
for row in data:
- writer.writerow(row)
+ if isinstance(row, basestring):
+ writer.writerow([row])
+ else:
+ writer.writerow(row)
=== modified file 'oerppy/scripting/base.py'
--- oerppy/scripting/base.py 2011-06-09 14:24:33 +0000
+++ oerppy/scripting/base.py 2011-06-09 15:25:17 +0000
@@ -96,8 +96,20 @@
class OpenERPUsersExport(ExportScript):
-
+ """
+ Export a list of OpenERP users.
+ """
def run(self):
- addon = self.service.get_addon(const.DEFAULT_ADDON)
+ addon = self.service.get_addon("base")
data = addon.get_users()
self.export(data)
+
+
+class OpenERPProjectsExport(ExportScript):
+ """
+ Export a list of OpenERP projects.
+ """
+ def run(self):
+ addon = self.service.get_addon("project")
+ data = addon.get_project_names()
+ self.export(data)