← Back to team overview

oerppy-hackers team mailing list archive

[Branch ~oerppy-hackers/oerppy/trunk] Rev 38: * Massive name change and clarification of meaning: the term "addons" is now

 

------------------------------------------------------------
revno: 38
committer: duncan@xxxxxxxxxx
branch nick: trunk
timestamp: Fri 2011-06-03 16:03:45 -0600
message:
  * Massive name change and clarification of meaning: the term "addons" is now
    only used at the directory level just under "oerppy" for all addons. It no
    longer shows up in class names. Those that used to have the AddOn name (e.g.,
    ProjectAddOn) have been renamed to use "Query" instead (e.g.,
    ProjectQuery).
  * Removed addon base module.
  * Replaced const references to adding and getting addons to just be strings.
  * Massive change in behaviour for addons: removed the subclassing and instead
    am now using the registry to get the addons (and execute the methods)
    required.
  * Changed the behaviour of the HRQuery departments method to be a getter
    instead of a setter.
  * Added get_first convenience method to the ResultSet class.
  * Added a class and script for getting OEM users.
  * Added a new model for Canonical OEM users and converted the OEM methods in
    the CanonicalQuery addon to use the model instead of the raw results.
removed:
  oerppy/addons/base.py
modified:
  bin/export_all_weeks_timesheets
  bin/export_month_timesheets
  bin/export_users
  oerppy/addons/canonical/__init__.py
  oerppy/addons/canonical/model.py
  oerppy/addons/canonical/query.py
  oerppy/addons/canonical/scripting/export.py
  oerppy/addons/hr/__init__.py
  oerppy/addons/hr/query.py
  oerppy/addons/project/__init__.py
  oerppy/addons/project/query.py
  oerppy/model.py
  oerppy/query.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_all_weeks_timesheets'
--- bin/export_all_weeks_timesheets	2011-06-03 18:46:30 +0000
+++ bin/export_all_weeks_timesheets	2011-06-03 22:03:45 +0000
@@ -1,17 +1,24 @@
 #!/usr/bin/env python
+from oerppy import query
 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 import const
+from oerppy.addons.canonical import canonical_query
 from oerppy.addons.canonical.scripting import export
+from oerppy.addons.hr import hr_query
+from oerppy.addons.project import project_query
 
 
 # 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.CanonicalAddOn)
+registry.add("base", query.Query)
+registry.add("hr", hr_query.HRQuery)
+registry.add("project", project_query.ProjectQuery)
+registry.add("canonical", canonical_query.CanonicalQuery)
 # run the exporter
 all_weeks_export = export.AllWeeksExport(config_data)
 all_weeks_export.run()

=== modified file 'bin/export_month_timesheets'
--- bin/export_month_timesheets	2011-06-03 18:46:30 +0000
+++ bin/export_month_timesheets	2011-06-03 22:03:45 +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 const, query
+from oerppy.addons.canonical import query
 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(const.CANONICAL, query.CanonicalAddOn)
+registry.add("canonical", query.CanonicalQuery)
 # run the exporter
 monthly_export = export.MonthlyExport(config_data)
 monthly_export.run()

=== modified file 'bin/export_users'
--- bin/export_users	2011-06-03 20:29:11 +0000
+++ bin/export_users	2011-06-03 22:03:45 +0000
@@ -3,7 +3,7 @@
 This is an example of a script that uses the default addon, i.e., standard
 OpenERP data.
 """
-from oerppy import const, query
+from oerppy import query
 from oerppy.config import get_config_data
 from oerppy.reg import registry
 from oerppy.scripting import base
@@ -13,7 +13,7 @@
 # class(es)
 config_data = get_config_data()
 # setup any addons that we want
-registry.add(const.DEFAULT_ADDON, query.Query)
+registry.add("base", query.Query)
 # run the exporter
 all_weeks_export = base.OpenERPUsersExport(config_data)
 all_weeks_export.run()

=== removed file 'oerppy/addons/base.py'
--- oerppy/addons/base.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/base.py	1970-01-01 00:00:00 +0000
@@ -1,10 +0,0 @@
-from oerppy.query import Query
-
-
-class AddOn(Query):
-    """
-    The addons should only need access to the client object, since through
-    it, one will have access to al the endpoints, the dbname, the
-    credentials, and the basic client query methods.
-    """
-    pass

=== modified file 'oerppy/addons/canonical/__init__.py'
--- oerppy/addons/canonical/__init__.py	2011-06-02 15:49:02 +0000
+++ oerppy/addons/canonical/__init__.py	2011-06-03 22:03:45 +0000
@@ -0,0 +1,4 @@
+from oerppy.addons.canonical import model, query
+
+
+canonical_query = query

=== modified file 'oerppy/addons/canonical/model.py'
--- oerppy/addons/canonical/model.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/canonical/model.py	2011-06-03 22:03:45 +0000
@@ -1,4 +1,23 @@
 from oerppy import model
 
 
-
+class UserCategory(model.Model):
+
+    def __init__(self, row):
+        self.id = row.get("id")
+        self.code = row.get("code")
+        self.name = row.get("name")
+        self.complete_name = row.get("complete_name")
+        self.child_ids = row.get("child_ids")
+        self.user_ids = row.get("user_ids")
+        self.parent_left = row.get("parent_left")
+        self.parent_right = row.get("parent_right")
+        self.active = row.get("active")
+        # The following are key/value pairs, each with .key and .value
+        # attributes
+        self.parent_id = model.KeyValuePairField(row.get("parent_id")) 
+
+
+class UserCategoriesSet(model.ResultSet):
+
+    model = UserCategory

=== modified file 'oerppy/addons/canonical/query.py'
--- oerppy/addons/canonical/query.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/canonical/query.py	2011-06-03 22:03:45 +0000
@@ -1,11 +1,13 @@
-from oerppy import model
-from oerppy.addons import hr, project
-from oerppy.addons.canonical import const
-from oerppy.addons.hr.query import HRAddOn
-from oerppy.addons.project.query import ProjectAddOn
-
-
-class CanonicalAddOn(HRAddOn, ProjectAddOn):
+from oerppy import query
+from oerppy.addons.canonical import const, model
+from oerppy.reg import registry
+
+
+class CanonicalQuery(query.Query):
+
+    def __init__(self, *args, **kwargs):
+        super(CanonicalQuery, self).__init__(*args, **kwargs)
+        self.user_dept = None
 
     def views(self):
         return const.TIMESHEET_VIEWS
@@ -18,7 +20,7 @@
         if not domains:
             domains = []
         if not self.user_dept:
-            self.set_departments()
+            self.user_dept = registry.get_addon("hr").get_departments()
         if report == const.TIMESHEET_HOURS:
             records = self.timesheet_hours(domains)
         elif report == const.TIMESHEETS_WEEKLY:
@@ -27,25 +29,36 @@
             raise OpenERPPyParameterError("Unknown value for 'report.'")
         return records
 
+    def get_oem_users(self):
+        """
+        Get the IDs for everyone who uses the OEM timesheets.
+        """
+        raw_results = self.client.searchfields(
+            entity='canonical.user.category',
+            query=[],
+            fields=[])
+        results = model.UserCategoriesSet(raw_results)
+        return results
+
     def get_oem_user_ids(self):
         """
         Get the IDs for everyone who uses the OEM timesheets.
         """
-        user_fields = self.client.searchfields(
-            'canonical.user.category',
-            [('code','=','OEMTIMESHEET')],
-            ['user_ids'])
-        return user_fields[0]['user_ids']
+        raw_results = self.client.searchfields(
+            entity='canonical.user.category',
+            query=[('code','=','OEMTIMESHEET')],
+            fields=['user_ids'])
+        result = model.UserCategoriesSet(raw_results).get_first()
+        return result.user_ids
 
     def weekly_timesheets(self, domains):
         """
         Get the weekly timeentry records, highlighting the missing weeks.
         """
         # get user IDs of timesheet users and the weeks we're interested in
-
-        weeks = self.get_all_timeentry_weeks()
+        weeks = registry.get_addon("project").get_all_timeentry_weeks()
         user_ids = self.get_oem_user_ids()
-        users = self.get_user_names(user_ids)
+        users = registry.get_addon("base").get_user_names(user_ids)
         # build list of names for each user id
         user_list = {}
         for u in users:
@@ -54,7 +67,8 @@
         records = []
         for week in weeks:
             # get timesheets for the week
-            timesheets = self.get_users_timeentry(week, user_ids)
+            timesheets = registry.get_addon("project").get_users_timeentry(
+                week, user_ids)
             # store lookup of total time by user for this week
             total_time = {}
             if timesheets:

=== modified file 'oerppy/addons/canonical/scripting/export.py'
--- oerppy/addons/canonical/scripting/export.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/canonical/scripting/export.py	2011-06-03 22:03:45 +0000
@@ -27,7 +27,7 @@
         return parser
 
     def run(self):
-        addon = self.service.get_addon(const.CANONICAL)
+        addon = self.service.get_addon("canonical")
         data = addon.get_monthly_timesheets(self.month, self.year)
         self.export(data)
 
@@ -52,6 +52,18 @@
         # 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)
+        addon = self.service.get_addon("canonical")
         data = addon.query(options.report_style)
         self.export(data)
+
+
+class OEMUsersExport(ExportScript):
+
+    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("canonical")
+        data = addon.get_oem_users()
+        self.export(data)

=== modified file 'oerppy/addons/hr/__init__.py'
--- oerppy/addons/hr/__init__.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/hr/__init__.py	2011-06-03 22:03:45 +0000
@@ -1,1 +1,4 @@
 from oerppy.addons.hr import model, query
+
+
+hr_query = query

=== modified file 'oerppy/addons/hr/query.py'
--- oerppy/addons/hr/query.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/hr/query.py	2011-06-03 22:03:45 +0000
@@ -1,15 +1,11 @@
-from oerppy.addons import base
+from oerppy import query
 from oerppy.addons.hr import model
 
 
-class HRAddOn(base.AddOn):
-    """
-    """
-    def __init__(self, *args, **kwargs):
-        super(HRAddOn, self).__init__(*args, **kwargs)
-        self.user_dept = None
-
-    def set_departments(self):
+class HRQuery(query.Query):
+    """
+    """
+    def get_departments(self):
         """
         Build a lookup dictionary of department vs user_id.
         """
@@ -19,4 +15,4 @@
             fields=['name','department_id','resource_id','user_id'])
         results = model.EmployeeSet(raw_results)
         # build dictionary of resource_id vs department
-        self.user_dept = results.build_department_lookup_table()
+        return results.build_department_lookup_table()

=== modified file 'oerppy/addons/project/__init__.py'
--- oerppy/addons/project/__init__.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/project/__init__.py	2011-06-03 22:03:45 +0000
@@ -1,1 +1,4 @@
 from oerppy.addons.project import model, query
+
+
+project_query = query

=== modified file 'oerppy/addons/project/query.py'
--- oerppy/addons/project/query.py	2011-06-03 18:46:30 +0000
+++ oerppy/addons/project/query.py	2011-06-03 22:03:45 +0000
@@ -1,10 +1,10 @@
 from datetime import date, timedelta
 
-from oerppy.addons import base
+from oerppy import query
 from oerppy.addons.project import model
 
 
-class ProjectAddOn(base.AddOn):
+class ProjectQuery(query.Query):
     """
     """
     def timesheet_hours(self, domains):

=== modified file 'oerppy/model.py'
--- oerppy/model.py	2011-06-03 20:29:11 +0000
+++ oerppy/model.py	2011-06-03 22:03:45 +0000
@@ -40,8 +40,12 @@
             try:
                 self.append(self.model(row, *args, **kwds))
             except Exception, error:
+                print error
                 import pdb;pdb.set_trace()
 
+    def get_first(self):
+        return self[0]
+
 
 class User(Model):
 

=== modified file 'oerppy/query.py'
--- oerppy/query.py	2011-06-03 20:29:11 +0000
+++ oerppy/query.py	2011-06-03 22:03:45 +0000
@@ -6,9 +6,14 @@
     A wrapper class for RPC requests (queries) that are more
     involved/complicated than the ones implemented in the client class.
 
-    AddOn classes use this as a baseclass.
+    AddOn classes use this as a base class.
     """
     def __init__(self, client):
+        """
+        Query classes should only need access to the client object, since
+        through it, one will have access to all the endpoints, the dbname, the
+        credentials, and the basic client query methods.
+        """
         self.client = client
 
     def query(self, report, domains=None):