[REF]GOLEM Member : age range small refactorings

This commit is contained in:
Fabien BOURGEOIS 2019-01-21 09:42:06 +01:00
parent 953d0bca3d
commit f1725b2096
3 changed files with 21 additions and 17 deletions

View File

@ -32,30 +32,34 @@ class GolemMemberAgeRange(models.Model):
_('This name has already been used. It must be unique.')
)]
name = fields.Char(compute='_compute_name', store=True)
lower_bound = fields.Integer(required=True, index=True)
higher_bound = fields.Integer(required=True, index=True)
name = fields.Char(required=True)
lower_bound = fields.Integer(required=True)
higher_bound = fields.Integer(required=True)
@api.constrains('lower_bound', 'higher_bound')
def check_bounds(self):
""" Check member age bounds coherence and conflits """
""" Check member age bounds coherence and conflicts """
for rng in self:
if rng.lower_bound > rng.higher_bound:
verr = _(u'The higher bound age must be higher than '
'the lower bound.')
verr = _(u'The higher bound age must be higher than the lower '
'bound.')
raise ValidationError(verr)
rngs = self.env['golem.member.age.range'].search([])
for each_rng in rngs:
if each_rng.lower_bound < rng.lower_bound < each_rng.higher_bound:
verr = _(u'Lower bound age in range of an '
'existing age range.')
verr = _(u'Lower bound age in range of an existing age '
'range.')
raise ValidationError(verr)
if each_rng.lower_bound < rng.higher_bound < each_rng.higher_bound:
verr = _(u'Higher bound age in range of an '
'existing age range.')
verr = _(u'Higher bound age in range of an existing age '
'range.')
raise ValidationError(verr)
@api.depends('lower_bound', 'higher_bound')
def _compute_name(self):
""" Computes age range name """
@api.onchange('lower_bound', 'higher_bound')
def onchange_name(self):
""" If no name, computes age range name """
for rec in self:
rec.name = u'{}-{} years'.format(rec.lower_bound, rec.higher_bound)
if not rec.name and rec.lower_bound and rec.higher_bound:
rec.name = _(u'{}-{} years').format(
rec.lower_bound, rec.higher_bound
)

View File

@ -39,7 +39,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Menus -->
<menuitem id="golem_member_age_range_menu" name="Age Ranges"
parent="golem_membership.menu_config_association" sequence="0"
parent="golem_membership.menu_config_association" sequence="30"
action="golem_member_age_range_action" />
</data>

View File

@ -45,10 +45,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<!-- Actions -->
<act_window id="golem_analysis_action" name="Analysis"
res_model="golem.member.analysis.wizard" view_mode="form"
target="new"/>
target="current"/>
<menuitem id="golem_analysis_menu" name="Members analysis"
parent="golem_membership.menu_association" sequence="15"
parent="golem_membership.menu_association" sequence="50"
action="golem_analysis_action"/>
</data>