Browse Source

[IMP] using parent_id in date_range generator wizard (amended with unit

test)
pull/47/head
Nikos Tsirintanis 6 years ago
parent
commit
f38fe6f04d
  1. 4
      date_range/__init__.py
  2. 6
      date_range/__manifest__.py
  3. 4
      date_range/models/__init__.py
  4. 4
      date_range/models/date_range.py
  5. 4
      date_range/models/date_range_type.py
  6. 3
      date_range/readme/CONTRIBUTORS.rst
  7. 4
      date_range/tests/__init__.py
  8. 4
      date_range/tests/test_date_range.py
  9. 42
      date_range/tests/test_date_range_generator.py
  10. 4
      date_range/tests/test_date_range_type.py
  11. 22
      date_range/wizard/date_range_generator.py
  12. 1
      date_range/wizard/date_range_generator.xml

4
date_range/__init__.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 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

6
date_range/__manifest__.py

@ -1,9 +1,9 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 2016 ACSONE SA/NV (<https://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Date Range",
"summary": "Manage all kind of date range",
"version": "11.0.2.0.1",
"version": "11.0.3.0.0",
"category": "Uncategorized",
"website": "https://github.com/oca/server-ux",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",

4
date_range/models/__init__.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 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

4
date_range/models/date_range.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 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
from odoo.tools.translate import _

4
date_range/models/date_range_type.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 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
from odoo.tools.translate import _

3
date_range/readme/CONTRIBUTORS.rst

@ -1,8 +1,5 @@
* Laurent Mignon <laurent.mignon@acsone.eu>
* Alexis de Lattre <alexis.delattre@akretion.com>
* Miquel Raïch <miquel.raich@eficent.com>
<<<<<<< HEAD
* Andrea Stirpe <a.stirpe@onestein.nl>
=======
* Nikos Tsirintanis <ntsirintanis@therp.nl>
>>>>>>> 72713cb6... [IMP] Added hierarchical feature for date_range, via parent_id

4
date_range/tests/__init__.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# © 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

4
date_range/tests/test_date_range.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
# © 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
from odoo.exceptions import ValidationError

42
date_range/tests/test_date_range_generator.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)nses/agpl).
# © 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
from odoo.exceptions import ValidationError
@ -73,3 +73,41 @@ class DateRangeGeneratorTest(TransactionCase):
'count': 4,
'company_id': self.company_2.id,
})
def test_generator_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']
generator = self.env['date.range.generator']
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,
})
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 generator,
# which would also trigger onchange in date_range
values = {
'date_start': month_range.date_start,
'type_id': day_type.id,
}
on_change = generator._onchange_spec()
domain = generator.onchange(
values,
['type_id', 'date_start'],
on_change,
)
# check that with this search domain,
# only the month_range record is returned.
self.assertEqual(
date_range.search(domain['domain']['parent_id']),
month_range,
)

4
date_range/tests/test_date_range_type.py

@ -1,5 +1,5 @@
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
# © 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
from odoo.tools import mute_logger

22
date_range/wizard/date_range_generator.py

@ -37,6 +37,8 @@ class DateRangeGenerator(models.TransientModel):
duration_count = fields.Integer('Duration', required=True)
count = fields.Integer(
string="Number of ranges to generate", required=True)
parent_id = fields.Many2one(
comodel_name='date.range', string="Parent", index=1)
@api.multi
def _compute_date_ranges(self):
@ -59,7 +61,8 @@ class DateRangeGenerator(models.TransientModel):
'date_start': date_start,
'date_end': date_end,
'type_id': self.type_id.id,
'company_id': self.company_id.id})
'company_id': self.company_id.id,
'parent_id': self.parent_id.id})
return date_ranges
@api.onchange('company_id')
@ -87,3 +90,20 @@ class DateRangeGenerator(models.TransientModel):
self.env['date.range'].create(dr)
return self.env['ir.actions.act_window'].for_xml_id(
module='date_range', xml_id='date_range_action')
@api.multi
@api.onchange('type_id', 'date_start')
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

1
date_range/wizard/date_range_generator.xml

@ -15,6 +15,7 @@
</div>
<field name="date_start"/>
<field name="count"/>
<field name="parent_id" options="{'no_create': True}"/>
<field groups="base.group_multi_company"
name="company_id" options="{'no_create': True}"/>
</group>

Loading…
Cancel
Save