diff --git a/runbot/models/commit.py b/runbot/models/commit.py index f04228ed..b9cdfaa0 100644 --- a/runbot/models/commit.py +++ b/runbot/models/commit.py @@ -34,6 +34,13 @@ class Commit(models.Model): dname = fields.Char('Display name', compute='_compute_dname') rebase_on_id = fields.Many2one('runbot.commit', 'Rebase on commit') + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if 'date' not in vals: + vals['date'] = fields.Datetime.now() + return super().create(vals_list) + def _get(self, name, repo_id, vals=None, rebase_on_id=False): commit = self.search([('name', '=', name), ('repo_id', '=', repo_id), ('rebase_on_id', '=', rebase_on_id)]) if not commit: diff --git a/runbot/tests/test_commit.py b/runbot/tests/test_commit.py index 96b3f505..6185c759 100644 --- a/runbot/tests/test_commit.py +++ b/runbot/tests/test_commit.py @@ -6,6 +6,17 @@ from werkzeug.urls import url_parse from odoo.tests.common import HttpCase, new_test_user, tagged from odoo.tools import mute_logger +from .common import RunbotCaseMinimalSetup + +class TestCommitDate(RunbotCaseMinimalSetup): + + def test_commit_has_date(self): + commit = self.Commit.create({ + 'name': 'caca00caca00ffffffffffffffffffffffffffff', + 'repo_id': self.repo_server.id + }) + + self.assertNotEqual(commit.date, False, "A commit should always have a date") @tagged('post_install', '-at_install') class TestCommitStatus(HttpCase):