Browse Source

[FIX] Corrected parent_id domain get for wizard

pull/47/head
Nikos Tsirintanis 6 years ago
parent
commit
71e7eeb645
  1. 3
      date_range/__init__.py
  2. 2
      date_range/__manifest__.py
  3. 3
      date_range/models/__init__.py
  4. 14
      date_range/models/date_range.py
  5. 2
      date_range/models/date_range_type.py
  6. 3
      date_range/tests/__init__.py
  7. 38
      date_range/tests/test_date_range.py
  8. 19
      date_range/tests/test_date_range_generator.py
  9. 2
      date_range/tests/test_date_range_type.py
  10. 3
      date_range/wizard/__init__.py
  11. 28
      date_range/wizard/date_range_generator.py

3
date_range/__init__.py

@ -1,5 +1,2 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from . import wizard

2
date_range/__manifest__.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Date Range",

3
date_range/models/__init__.py

@ -1,5 +1,2 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import date_range_type
from . import date_range

14
date_range/models/date_range.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
@ -63,10 +63,10 @@ class DateRange(models.Model):
for this in self:
if not this.parent_id:
continue
start = this.parent_id.date_start <= this.date_start
end = this.parent_id.date_end >= this.date_end
child_range = start and end
if not child_range:
date_start_valid = this.parent_id.date_start <= this.date_start
date_end_valid = this.parent_id.date_end >= this.date_end
if date_start_valid and date_end_valid:
continue
text_dict = {
'name': this.name,
'start': this.date_start,
@ -75,13 +75,13 @@ class DateRange(models.Model):
'parent_start': this.parent_id.date_start,
'parent_end': this.parent_id.date_end,
}
if (not start) and end:
if (not date_start_valid) and date_end_valid:
text = _(
"Start date %(start)s of %(name)s must be greater than"
" or equal to "
"start date %(parent_start)s of %(parent_name)s"
) % text_dict
elif (not end) and start:
elif (not date_end_valid) and date_start_valid:
text = _(
"End date %(end)s of %(name)s must be smaller than"
" or equal to "

2
date_range/models/date_range_type.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models

3
date_range/tests/__init__.py

@ -1,6 +1,3 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_date_range_type
from . import test_date_range
from . import test_date_range_generator

38
date_range/tests/test_date_range.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.tests.common import TransactionCase
@ -271,3 +271,39 @@ class DateRangeTest(TransactionCase):
parent_range.type_id,
child_range2.parent_id.type_id
)
def test_partner_id_domain(self):
"""Check here domain returned for partner_id"""
date_range = self.env['date.range']
date_type = self.env['date.range.type']
month_type = date_type.create({
'name': 'month type'
})
day_type = date_type.create({
'name': 'day type',
'parent_type_id': month_type.id,
'company_id': self.company.id,
})
month_range = date_range.create({
'name': 'month range',
'type_id': month_type.id,
'date_start': '01-01-2050',
'date_end': '02-01-2050',
})
# now trigger onchange in date.range listview
values = {
'company_id': month_range.company_id.id,
'date_start': month_range.date_start,
'date_end': month_range.date_end,
'type_id': day_type.id,
}
on_change = date_range._onchange_spec()
domain = date_range.onchange(
values,
['company_id', 'type_id', 'date_start', 'date_end'],
on_change,
)
self.assertEqual(
date_range.search(domain['domain']['parent_id']),
month_range,
)

19
date_range/tests/test_date_range_generator.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)nses/agpl).
from odoo.tests.common import TransactionCase
@ -74,7 +74,7 @@ class DateRangeGeneratorTest(TransactionCase):
'company_id': self.company_2.id,
})
def test_generator_partner_id_domain(self):
def test_partner_id_domain(self):
"""Check here domain returned for partner_id
in both date.range and date.range.generator"""
date_range = self.env['date.range']
@ -111,3 +111,18 @@ class DateRangeGeneratorTest(TransactionCase):
date_range.search(domain['domain']['parent_id']),
month_range,
)
# the same applies to date.range treeview
values = {
'date_start': month_range.date_start,
'type_id': day_type.id,
}
on_change = date_range._onchange_spec()
domain = date_range.onchange(
values,
['type_id', 'date_start'],
on_change,
)
self.assertEqual(
date_range.search(domain['domain']['parent_id']),
month_range,
)

2
date_range/tests/test_date_range_type.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo.tests.common import TransactionCase

3
date_range/wizard/__init__.py

@ -1,4 +1 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import date_range_generator

28
date_range/wizard/date_range_generator.py

@ -1,4 +1,4 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
@ -96,14 +96,18 @@ class DateRangeGenerator(models.TransientModel):
def onchange_type_id(self):
self.ensure_one()
date_range = self.env['date.range']
values = {
'date_start': self.date_start,
'type_id': self.type_id.id,
}
on_change = date_range._onchange_spec()
domain = date_range.onchange(
values,
['type_id', 'date_start'],
on_change,
)
return domain
domain = []
if self.type_id:
domain.append(('type_id', '=', self.type_id.parent_type_id.id))
if self.date_start:
domain.append('|')
domain.append(('date_start', '<=', self.date_start))
domain.append(('date_start', '=', False))
if domain:
# If user did not select a parent already, autoselect the last
# (ordered by date_start) or only parent that applies.
if self.type_id and self.date_start and not self.parent_id:
possible_parent = date_range.search(
domain, limit=1, order='date_start desc')
self.parent_id = possible_parent # can be empty!
return {'domain': {'parent_id': domain}}
Loading…
Cancel
Save