oerppy-hackers team mailing list archive
-
oerppy-hackers team
-
Mailing list archive
-
Message #00011
[Branch ~oerppy-hackers/oerppy/trunk] Rev 31: * Added a script (and dependent classes/code) for the weekly reports.
------------------------------------------------------------
revno: 31
committer: duncan@xxxxxxxxxx
branch nick: trunk
timestamp: Thu 2011-06-02 11:25:28 -0600
message:
* Added a script (and dependent classes/code) for the weekly reports.
* Moved set_service into base scripting class.
* Moved export logic into base export scripting class.
added:
bin/export_weekly_timesheets
modified:
bin/export_month_timesheets
oerppy/addons/canonical/const.py
oerppy/addons/canonical/query.py
oerppy/addons/canonical/scripting/export.py
oerppy/client.py
oerppy/exceptions.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 'bin/export_month_timesheets'
--- bin/export_month_timesheets 2011-06-02 16:51:35 +0000
+++ bin/export_month_timesheets 2011-06-02 17:25:28 +0000
@@ -3,7 +3,7 @@
from oerppy.reg import registry
# XXX we probably want to eventually put these addons in their own project
-from oerppy.addons.canonical import query
+from oerppy.addons.canonical import query, const
from oerppy.addons.canonical.scripting import export
@@ -11,7 +11,7 @@
# class(es)
config_data = get_config_data()
# setup any addons that we want
-registry.add("canonical", query.CanonicalAddOns)
+registry.add(const.CANONICAL, query.CanonicalAddOns)
# run the exporter
monthly_export = export.MonthlyExport(config_data)
monthly_export.run()
=== added file 'bin/export_weekly_timesheets'
--- bin/export_weekly_timesheets 1970-01-01 00:00:00 +0000
+++ bin/export_weekly_timesheets 2011-06-02 17:25:28 +0000
@@ -0,0 +1,17 @@
+#!/usr/bin/env python
+from oerppy.config import get_config_data
+from oerppy.reg import registry
+
+# XXX we probably want to eventually put these addons in their own project
+from oerppy.addons.canonical import const, query
+from oerppy.addons.canonical.scripting import export
+
+
+# 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(const.CANONICAL, query.CanonicalAddOns)
+# run the exporter
+weekly_export = export.WeeklyExport(config_data)
+weekly_export.run()
=== modified file 'oerppy/addons/canonical/const.py'
--- oerppy/addons/canonical/const.py 2011-06-02 16:51:35 +0000
+++ oerppy/addons/canonical/const.py 2011-06-02 17:25:28 +0000
@@ -1,6 +1,7 @@
from oerppy.const import *
+CANONICAL = "canonical"
TIMESHEET_HOURS = "Timesheet Hours"
TIMESHEETS_WEEKLY = "Weekly Timesheets"
TIMESHEET_VIEWS = [
=== modified file 'oerppy/addons/canonical/query.py'
--- oerppy/addons/canonical/query.py 2011-06-02 16:51:35 +0000
+++ oerppy/addons/canonical/query.py 2011-06-02 17:25:28 +0000
@@ -30,7 +30,7 @@
elif report == const.TIMESHEETS_WEEKLY:
records = self.weekly_timesheets(domains)
else:
- records = []
+ raise OpenERPPyParameterError("Unknown value for 'report.'")
return records
# XXX many of these methods will become more simplified through the use of
=== modified file 'oerppy/addons/canonical/scripting/export.py'
--- oerppy/addons/canonical/scripting/export.py 2011-06-02 16:51:35 +0000
+++ oerppy/addons/canonical/scripting/export.py 2011-06-02 17:25:28 +0000
@@ -1,9 +1,10 @@
from datetime import datetime
-from oerppy import config, export, scripting, service
-
-
-class MonthlyExport(scripting.ExportScript):
+from oerppy import config, export, service
+from oerppy.scripting import ExportScript
+
+
+class MonthlyExport(ExportScript):
"""
Generate an export of a given month's timesheet data.
"""
@@ -23,33 +24,31 @@
help="the year to export")
return parser
- def set_service(self, config_data):
- options = self.get_options()
- server_config = config.get_server(options.host, options.dbname)
- url = server_config.get("url")
- user = server_config.get("username")
- password = server_config.get("password")
- self.service = service.Service(url, options.dbname, user, password)
- # note that we could add the addon (self) to the registry at this
- # point, but we'd have to hard code a name here, as opposed to how it's
- # currently done (the executable setting the name associated with the
- # addon when it's added to the registry).
-
- def export(self, data):
- options = self.get_options()
- # create the filehandle
- if options.output_filename == const.STDOUT_FILENAME:
- fd = sys.stdout
- else:
- fd = open(options.output_filename, "w+")
- # dispatch the appropriate export based on the format option
- if options.export_format == const.EXPORT_RAW:
- fd.write(data)
- elif options.export_format == const.EXPORT_CSV:
- export.export_csv(data, fd)
- #elif options.export_format == const.EXPORT_GOOGLE_DOCS:
- # export.export_google(user, pass, data, ..., ?)
-
- def run(self):
- data = self.service.get_monthly_timesheets(self.month, self.year)
+ def run(self):
+ addon = self.service.get_addon(const.CANONICAL)
+ data = addon.get_monthly_timesheets(self.month, self.year)
+ self.export(data)
+
+
+class WeeklyExport(ExportScript):
+
+ def get_option_parser(self):
+ """
+ Options for monthly exports.
+ """
+ now = datetime.now()
+ parser = super(WeeklyExport, self).get_option_parser()
+ parser.add_option(
+ "-s", "--report-style", dest="report_style", action="store",
+ help=("the report style to present in export (e.g., 'hours' "
+ "or 'weekly'"))
+ return parser
+
+ def run(self):
+ # we need to set purge to true here, since the options will have
+ # already been gotten by the parent class at this time, and we need the
+ # options of this class added to those
+ options = self.get_options(purge=True)
+ addon = self.service.get_addon(const.CANONICAL)
+ data = addon.query(options.report_style)
self.export(data)
=== modified file 'oerppy/client.py'
--- oerppy/client.py 2011-06-02 15:16:11 +0000
+++ oerppy/client.py 2011-06-02 17:25:28 +0000
@@ -22,7 +22,7 @@
"""
uid = self.endpoints.common.login(self.dbname, self.credentials)
self.credentials.set_uid(uid)
-
+
# cache the object proxy and prepare the execute callable
self.endpoints.object.get_proxy()
self.endpoints.object.prepare(self.dbname, self.credentials)
@@ -37,7 +37,7 @@
def search(self, entity, query):
return self.endpoints.object.execute(entity, "search", query)
-
+
def update(self, entity, record, ids):
"""Update an entity"""
return self.endpoints.object.execute(entity, "write", ids, record)
@@ -54,20 +54,22 @@
def read(self, entity, ids, fields):
"""
- Read an entity when provided a list of Ids
+ Read an entity when provided a list of Ids
"""
return self.endpoints.object.execute(entity, "read", ids, fields)
def searchfields(self, entity, query, fields):
- ids = self.search(entity, query)
- if ids:
- # Get the fields for the records
- records = self.endpoints.object.execute(entity, "read", ids,
- fields)
- return records
- else:
- return None
-
+ """
+ """
+ ids = self.search(entity, query)
+ if ids:
+ # Get the fields for the records
+ records = self.endpoints.object.execute(entity, "read", ids,
+ fields)
+ return records
+ else:
+ return None
+
def report(self, model, ids, report_name, form):
# Get the model's records and context
if not ids:
@@ -76,7 +78,7 @@
# Run the report
data = {
"model": model,
- "form": form,
+ "form": form,
}
rep_id = self.endpoints.report.execute(report_name, ids, data, context)
=== modified file 'oerppy/exceptions.py'
--- oerppy/exceptions.py 2011-06-01 18:55:24 +0000
+++ oerppy/exceptions.py 2011-06-02 17:25:28 +0000
@@ -4,3 +4,7 @@
class OpenERPPyConfigError(OpenERPPyError):
pass
+
+
+class OpenERPPyParameterError(OpenERPPyError):
+ pass
=== modified file 'oerppy/scripting/base.py'
--- oerppy/scripting/base.py 2011-06-02 16:51:35 +0000
+++ oerppy/scripting/base.py 2011-06-02 17:25:28 +0000
@@ -1,6 +1,6 @@
from optparse import OptionParser
-from oerppy import const
+from oerppy import config, const, service
class Script(object):
@@ -13,10 +13,16 @@
self.set_service(config_data)
def set_service(self, config_data):
- """
- This method needs to be implemented by all scripting classes.
- """
- raise NotImplementedError("Method implementation missing!")
+ options = self.get_options()
+ server_config = config.get_server(options.host, options.dbname)
+ url = server_config.get("url")
+ user = server_config.get("username")
+ password = server_config.get("password")
+ self.service = service.Service(url, options.dbname, user, password)
+ # note that we could add the addon (self) to the registry at this
+ # point, but we'd have to hard code a name here, as opposed to how it's
+ # currently done (the executable setting the name associated with the
+ # addon when it's added to the registry).
def get_option_parser(self):
"""
@@ -67,3 +73,21 @@
default=const.EXPORT_RAW,
help="the format to export the data in")
return parser
+
+ def export(self, data):
+ # we need to set purge to true here, since the options will have
+ # already been gotten by the parent class at this time, and we need the
+ # options of this class added to those
+ options = self.get_options(purge=True)
+ # create the filehandle
+ if options.output_filename == const.STDOUT_FILENAME:
+ fd = sys.stdout
+ else:
+ fd = open(options.output_filename, "w+")
+ # dispatch the appropriate export based on the format option
+ if options.export_format == const.EXPORT_RAW:
+ fd.write(data)
+ elif options.export_format == const.EXPORT_CSV:
+ export.export_csv(data, fd)
+ #elif options.export_format == const.EXPORT_GOOGLE_DOCS:
+ # export.export_google(user, pass, data, ..., ?)