Browse Source

Fix unlink date range type.

pull/25/head
Fekete Mihai 7 years ago
committed by Pedro M. Baeza
parent
commit
c31ed03bfe
  1. 3
      date_range/models/date_range.py
  2. 16
      date_range/tests/test_date_range_type.py

3
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(

16
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()
Loading…
Cancel
Save