← Back to team overview

oerppy-hackers team mailing list archive

[Branch ~oerppy-hackers/oerppy/trunk] Rev 20: * Filled in most of the remaining logic for the script/export.py Monthly class;

 

------------------------------------------------------------
revno: 20
committer: duncan@xxxxxxxxxx
branch nick: trunk
timestamp: Wed 2011-06-01 10:42:38 -0600
message:
  * Filled in most of the remaining logic for the script/export.py Monthly class;
    it still needs options parsing.
  * Changed the export code to be a quick guess at what we're going to need.
  * Stubbed out a method for getting a month's timesheets.
  * Added some more notes about refactoring.
modified:
  oerppy/addons/canonical.py
  oerppy/client.py
  oerppy/export.py
  oerppy/scripts/export.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 'oerppy/addons/canonical.py'
--- oerppy/addons/canonical.py	2011-06-01 08:25:27 +0000
+++ oerppy/addons/canonical.py	2011-06-01 16:42:38 +0000
@@ -1,4 +1,4 @@
-from oerppy imort const
+from oerppy import const
 
 
 class CanonicalAddOns(object):
@@ -16,22 +16,22 @@
     def views(self):
         return const.VIEWS
 
-    # XXX this isn't a query method so much as a dispatch one; it should be
-    # renamed
+    # XXX this isn't a query method so much as a dispatch one; maybe it should
+    # be renamed?
+    # XXX on second thought... this is an addon and needs some sort of
+    # well-defined, user-sensical method name for running queries :-)
     def query(self, report, domain):
         """
         Run the query and return the grid.
         """
         if not self.user_dept:
             self._get_departments()
-
         if report == "Timesheet Hours":
             records = self._timesheet_hours(domain)
         elif report == "Weekly Timesheets":
             records = self._weekly_timesheets(domain)
         else:
             records = []
-
         return records
 
     # XXX many of these methods will become more simplified through the use of
@@ -158,3 +158,7 @@
         d = datetime.date(int(date[:4]), int(date[5:7]), int(date[8:10]))
         monday = d + datetime.timedelta(days=-d.weekday())
         return monday.isoformat()
+
+    # XXX fill this in
+    def get_month_timesheets(self, month, year):
+        pass

=== modified file 'oerppy/client.py'
--- oerppy/client.py	2011-06-01 08:15:23 +0000
+++ oerppy/client.py	2011-06-01 16:42:38 +0000
@@ -11,8 +11,6 @@
     Connection details for OpenERP.
     """
     def __init__(self, endpoints, dbname, creds):
-        # XXX these guys and their related logics need to be moved into
-        # endpoint code
         self.endpoints = endpoints
         self.dbname = dbname
         self.credentials = creds

=== modified file 'oerppy/export.py'
--- oerppy/export.py	2011-06-01 01:11:22 +0000
+++ oerppy/export.py	2011-06-01 16:42:38 +0000
@@ -1,29 +1,17 @@
-    def on_toolbuttonExport_clicked(self, widget, data=None):
-        if not self.grid:
-            return
-
-        # Display the 'Save' file dialog
-        filename = file_browse('save', 'Export results')
-        if len(filename)==0:
-            return
-
-        # Get the records fro the grid
-        recs = self.grid.rows
-        if len(recs)==0:
-            return
-
-        # Export the records to a CSV file
-        f = open(filename, 'wt')
-        writer = csv.DictWriter(f, recs[0].keys())
-
-        # Create the header row
-        header = {}
-        for k in recs[0].keys():
-            header[k] = k 
-        writer.writerow(header)
-
-        # Output the records
-        for r in recs:
-            writer.writerow(r)
-    
-        self.builder.get_object('labelStatus').set_text("Data exported to %s" % filename)
\ No newline at end of file
+def export_csv(self, service, data=None, filename):
+    if not data:
+        return
+
+    # Export the records to a CSV file
+    file_handle = open(filename, 'wt')
+    writer = csv.DictWriter(file_handle, data)
+
+    # Create the header row
+    header = {}
+    for key in data.keys():
+        header[key] = key
+    writer.writerow(header)
+
+    # Output the records
+    for row in data:
+        writer.writerow(row)

=== modified file 'oerppy/scripts/export.py'
--- oerppy/scripts/export.py	2011-06-01 04:07:52 +0000
+++ oerppy/scripts/export.py	2011-06-01 16:42:38 +0000
@@ -1,11 +1,29 @@
-from oerppy import model, scripts
-from oerppy.config import get_config_data
+from oerppy import config, scripts, service
 
 
 class Monthly(scripts.Script):
+    """
+    """
+    def __init__(self, config_data, options):
+        self.set_service(config_data, options)
+        # XXX get the month for the timesheet from the options
+        self.month = None
+        # XXX get the year for the timesheet from the options
+        self.year = None
+        # XXX get the output file frome the options
+        self.output_filename = ""
 
-    def __init__(self, config_data):
-        self.openerp = model.Model(config_data)
+    def set_service(self, config_data, options):
+        # XXX get host from options
+        host = ""
+        # XXX get dbname from options
+        dbname = ""
+        server_config = config.get_server(host, dbname)
+        url = server_config.get("url")
+        user = server_config.get("user")
+        password = server_config.get("password")
+        self.service = service.Service(url, dbname, user, password)
 
     def run(self):
-        pass
+        data = self.service.get_monthly_timesheets(self.month, self.year)
+        export.export_csv(data, self.output_filename)