Reviewers: ,


Please review this at http://codereview.tryton.org/39002/

Affected files:
  M cron.py
  M cron.xml


Index: cron.py
===================================================================

--- a/cron.py
+++ b/cron.py
@@ -10,17 +10,20 @@
             'Companies', help='Companies registered for this cron')

     def _callback(self, cron):
-        cursor = Transaction().cursor
-        cursor.execute("SELECT company from cron_company_rel "
-                       "WHERE cron = %s", (cron['id'],))
-        for company, in cursor.fetchall():
-            cursor.execute(
-                "UPDATE res_user SET company = %s, main_company = %s "
-                "WHERE id = %s", (company, company, cron['user']))
+        user_obj = self.pool.get('res.user')
+        if not cron.companies:
+            return super(Cron, self)._callback(cron)
+        # TODO replace with context
+        for company in cron.companies:
+            user_obj.write(cron.user.id, {
+                'company': company.id,
+                'main_company': company.id,
+            })
             super(Cron, self)._callback(cron)
-        cursor.execute(
-            "UPDATE res_user SET company = NULL, main_company = NULL "
-            "WHERE id = %s", (cron['user'],))
+        user_obj.write(cron.user.id, {
+            'company': False,
+            'main_company': False,
+        })

     def default_companies(self):
         company_obj = self.pool.get('company.company')

Index: cron.xml
===================================================================

--- a/cron.xml
+++ b/cron.xml
@@ -13,8 +13,8 @@
                     <xpath
                        expr="/form/field[@name=&quot;args&quot;]"
                        position="after">
-                      <separator name="companies" colspan="6"/>
-                      <field name="companies" colspan="6"/>
+                      <separator name="companies" colspan="4"/>
+                      <field name="companies" colspan="4"/>
                     </xpath>
                 </data>
                 ]]>



--
[email protected] mailing list

Reply via email to