From 2488228b7bb218b69887998ac80e1593059f9937 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 17 Mar 2023 11:18:44 +0100 Subject: [PATCH] [IMP] runbot: make params work in create multi The main motivation is to allow to create params from data the "new" method was called with a value list instead of a dict. Also, makes it possible to update params when the registry is not laoded --- runbot/models/build.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index b63b915e..41333dfc 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -107,18 +107,25 @@ class BuildParameters(models.Model): for params in self: params.commit_ids = params.commit_link_ids.commit_id - def create(self, values): - params = self.new(values) - match = self._find_existing(params.fingerprint) - if match: - return match - values = self._convert_to_write(params._cache) - return super().create(values) + @api.model_create_multi + def create(self, values_list): + records = self.browse() + for values in values_list: + params = self.new(values) + record = self._find_existing(params.fingerprint) + if record: + records |= record + else: + values = self._convert_to_write(params._cache) + records |= super().create(values) + return records def _find_existing(self, fingerprint): return self.env['runbot.build.params'].search([('fingerprint', '=', fingerprint)], limit=1) def write(self, vals): + if not self.env.registry.loaded: + return raise UserError('Params cannot be modified')