Browse Source

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

test)
pull/1431/head
Nikos Tsirintanis 6 years ago
committed by Laurent Mignon (ACSONE)
parent
commit
b39a0c4420
  1. 38
      date_range/tests/test_date_range_generator.py
  2. 22
      date_range/wizard/date_range_generator.py
  3. 1
      date_range/wizard/date_range_generator.xml

38
date_range/tests/test_date_range_generator.py

@ -72,3 +72,41 @@ class DateRangeGeneratorTest(TransactionCase):
'count': 4, 'count': 4,
'company_id': self.company_2.id, '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,
)

22
date_range/wizard/date_range_generator.py

@ -38,6 +38,8 @@ class DateRangeGenerator(models.TransientModel):
duration_count = fields.Integer('Duration', required=True) duration_count = fields.Integer('Duration', required=True)
count = fields.Integer( count = fields.Integer(
string="Number of ranges to generate", required=True) string="Number of ranges to generate", required=True)
parent_id = fields.Many2one(
comodel_name='date.range', string="Parent", index=1)
@api.multi @api.multi
def _compute_date_ranges(self): def _compute_date_ranges(self):
@ -60,7 +62,8 @@ class DateRangeGenerator(models.TransientModel):
'date_start': date_start, 'date_start': date_start,
'date_end': date_end, 'date_end': date_end,
'type_id': self.type_id.id, '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 return date_ranges
@api.onchange('company_id') @api.onchange('company_id')
@ -88,3 +91,20 @@ class DateRangeGenerator(models.TransientModel):
self.env['date.range'].create(dr) self.env['date.range'].create(dr)
return self.env['ir.actions.act_window'].for_xml_id( return self.env['ir.actions.act_window'].for_xml_id(
module='date_range', xml_id='date_range_action') 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> </div>
<field name="date_start"/> <field name="date_start"/>
<field name="count"/> <field name="count"/>
<field name="parent_id" options="{'no_create': True}"/>
<field groups="base.group_multi_company" <field groups="base.group_multi_company"
name="company_id" options="{'no_create': True}"/> name="company_id" options="{'no_create': True}"/>
</group> </group>

Loading…
Cancel
Save