diff --git a/date_range/tests/test_date_range_generator.py b/date_range/tests/test_date_range_generator.py index 7764fd3e3..2ee643b6e 100644 --- a/date_range/tests/test_date_range_generator.py +++ b/date_range/tests/test_date_range_generator.py @@ -72,3 +72,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, + ) diff --git a/date_range/wizard/date_range_generator.py b/date_range/wizard/date_range_generator.py index 534263e0c..a32f42ea9 100644 --- a/date_range/wizard/date_range_generator.py +++ b/date_range/wizard/date_range_generator.py @@ -38,6 +38,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): @@ -60,7 +62,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') @@ -88,3 +91,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 diff --git a/date_range/wizard/date_range_generator.xml b/date_range/wizard/date_range_generator.xml index 73551151b..aea993b12 100644 --- a/date_range/wizard/date_range_generator.xml +++ b/date_range/wizard/date_range_generator.xml @@ -15,6 +15,7 @@ +