[IMP]GOLEM Member Number generation better handling

This commit is contained in:
Fabien Bourgeois 2016-08-02 19:33:58 +02:00
parent c60feaf23a
commit fb8ed0d211

View File

@ -120,40 +120,40 @@ class GolemMember(models.Model):
@api.one @api.one
def _generate_number_global(self): def _generate_number_global(self):
""" Number generation in case of global configuration """ """ Number generation in case of global configuration """
for member in self: self.ensure_one()
conf = self.env['ir.config_parameter'] conf = self.env['ir.config_parameter']
domain = ['&', domain = ['&',
('member_id', '=', member.id), ('member_id', '=', self.id),
('season_id', '=', None)] ('season_id', '=', None)]
member_num = self.env['golem.member.number'] member_num = self.env['golem.member.number']
mn = member_num.search(domain) mn = member_num.search(domain)
if not mn: if not mn:
last = int(conf.get_param('golem_number_counter', 0)) last = int(conf.get_param('golem_number_counter', 0))
last += 1 last += 1
conf.set_param('golem_number_counter', str(last)) conf.set_param('golem_number_counter', str(last))
pfx = conf.get_param('golem_numberconfig_prefix') pfx = conf.get_param('golem_numberconfig_prefix')
number = pfx + str(last) number = pfx + str(last)
data = {'member_id': member.id, data = {'member_id': self.id,
'season_id': None, 'season_id': None,
'number': number} 'number': number}
mn = member_num.create(data) mn = member_num.create(data)
return mn.number return mn.number
@api.one @api.one
def _generate_number(self): def _generate_number(self):
""" Computes number according to pre-existing number and chosen """ Computes number according to pre-existing number and chosen
seasons """ seasons """
for member in self: self.ensure_one()
conf = self.env['ir.config_parameter'] conf = self.env['ir.config_parameter']
if conf.get_param('golem_numberconfig_isautomatic') == '0': if conf.get_param('golem_numberconfig_isautomatic') == '0':
member.number = member.number_manual self.number = self.number_manual
else:
if conf.get_param('golem_numberconfig_isperseason') == '1':
mn = self._generate_number_perseason()
else: else:
if conf.get_param('golem_numberconfig_isperseason') == '1': mn = self._generate_number_global()
mn = member._generate_number_perseason() if mn:
else: self.number = mn[0]
mn = member._generate_number_global()
if mn:
member.number = mn[0]
@api.model @api.model
@api.returns('self', lambda rec: rec.id) @api.returns('self', lambda rec: rec.id)