Commits

Jesús Martín (Zikzakmedia) committed 4375ed9

Use a list of dictionaries in create()

Comments (0)

Files changed (3)

__init__.pyc

Binary file removed.
     'Subscription'
     __name__ = 'subscription.subscription'
 
-    def get_model(self):
+    @classmethod
+    def get_model(cls):
         cr = Transaction().cursor
         cr.execute('''\
             SELECT
             ('running','Running'),
             ('done','Done')], 'State', readonly=True, states=STATES)
     model_source = fields.Reference('Source Document',
-            selection=get_model, depends=['state'],
+            selection='get_model', depends=['state'],
             help='User can choose the source model on which he wants to ' \
                 'create models.', states=STATES)
     lines = fields.One2Many('subscription.line', 'subscription', 'Lines',
     @ModelView.button
     def set_process(self, subscriptions):
         RequestLink = Pool().get('res.request.link')
+        to_create = []
         for subscription in subscriptions:
             vals = {
                 'model': subscription.__name__,
             ]
             cron = Cron.search([domain])
             if not cron:
-                cron = Cron.create(vals)
+                cron = Cron.create([vals])[0]
             else:
                 vals['active'] = True
                 Cron.write(cron, vals)
                 model = Model.search([
                         ('model', '=', subscription.model_source.__name__),
                     ])
-                link_vals = {
+                to_create.append({
                     'model': subscription.model_source.__name__,
                     'priority': 5,
                     'name': model and model[0] and model[0].name or False,
-                }
-                RequestLink.create(link_vals)
+                })
+        if to_create:
+            RequestLink.create(to_create)
 
     @classmethod
     def model_copy(cls, subscription_id):
                         )]
             history_vals['document'] = (subscription.model_source.__name__,
                                         model[0].id)
-            History.create(history_vals)
+            History.create([history_vals])
 
             # Send requests to users in request_group
+            to_create = []
             for user in subscription.request_group.users:
                 if user != subscription.request_user and user.active:
                     language = (user.language.code if user.language
                     with contextlib.nested(Transaction().set_user(user.id),
                             Transaction().set_context(language=language)):
                         req_vals['act_to'] = user.id
+                        to_create.append(req_vals)
                         Cron._get_request_values(subscription.cron)
-                        Request.create(req_vals)
+            if to_create:
+                Request.create(to_create)
 
             # If it is the last cron execution, set the state of the
             # subscriptio to done
     __name__ = "subscription.history"
     _rec_name = 'date'
 
-    def get_model(self):
+    @classmethod
+    def get_model(cls):
         cr = Transaction().cursor
         cr.execute('''\
             SELECT
         return cr.fetchall()
 
     date = fields.DateTime('Date', readonly=True)
-    subscription = fields.Many2One('subscription.subscription',
-            'Subscription', readonly=True)
     log = fields.Char('Result', readonly=True)
     subscription = fields.Many2One('subscription.subscription',
             'Subscription', ondelete='CASCADE', readonly=True)
-    document = fields.Reference('Source Document', selection=get_model,
+    document = fields.Reference('Source Document', selection='get_model',
             readonly=True)
 
     @staticmethod

subscription.pyc

Binary file removed.