From 84906d26f72760a45083b6a8b654f87a0d886527 Mon Sep 17 00:00:00 2001 From: Fekete Mihai Date: Sat, 24 Mar 2018 17:39:10 +0200 Subject: [PATCH] Fix unlink date range type. --- date_range/models/date_range.py | 3 ++- date_range/tests/test_date_range_type.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/date_range/models/date_range.py b/date_range/models/date_range.py index 92ba83fe0..42796c544 100644 --- a/date_range/models/date_range.py +++ b/date_range/models/date_range.py @@ -19,7 +19,8 @@ class DateRange(models.Model): date_start = fields.Date(string='Start date', required=True) date_end = fields.Date(string='End date', required=True) type_id = fields.Many2one( - comodel_name='date.range.type', string='Type', index=1, required=True) + comodel_name='date.range.type', string='Type', index=1, required=True, + ondelete='restrict') type_name = fields.Char( string='Type', related='type_id.name', readonly=True, store=True) company_id = fields.Many2one( diff --git a/date_range/tests/test_date_range_type.py b/date_range/tests/test_date_range_type.py index 0816267f3..668cdc46b 100644 --- a/date_range/tests/test_date_range_type.py +++ b/date_range/tests/test_date_range_type.py @@ -3,6 +3,8 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) from odoo.tests.common import TransactionCase +from odoo.tools import mute_logger +from psycopg2 import IntegrityError class DateRangeTypeTest(TransactionCase): @@ -18,3 +20,17 @@ class DateRangeTypeTest(TransactionCase): 'company_id': False, 'allow_overlap': False}) self.assertFalse(drt.company_id) + + def test_unlink(self): + date_range = self.env['date.range'] + drt = self.env['date.range.type'].create( + {'name': 'Fiscal year', + 'allow_overlap': False}) + date_range.create({ + 'name': 'FS2016', + 'date_start': '2015-01-01', + 'date_end': '2016-12-31', + 'type_id': drt.id, + }) + with self.assertRaises(IntegrityError), mute_logger('odoo.sql_db'): + drt.unlink()