From e4c6bebdeb94b1debe5c7e7e49b22bfac73429b3 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 d0c609b..4e60e39 100644 --- a/date_range/models/date_range.py +++ b/date_range/models/date_range.py @@ -18,7 +18,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 7a612e7..37a03b3 100644 --- a/date_range/tests/test_date_range_type.py +++ b/date_range/tests/test_date_range_type.py @@ -2,6 +2,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): @@ -17,3 +19,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()