forked from Yaltik/golem
[FIX]GOLEM Member number generation fixes on creation with usage of extension of create and write
This commit is contained in:
parent
fcdd8ac7fd
commit
c60feaf23a
@ -58,8 +58,7 @@ class GolemMember(models.Model):
|
|||||||
domain = [('is_default', '=', True)]
|
domain = [('is_default', '=', True)]
|
||||||
return self.env['golem.season'].search(domain)
|
return self.env['golem.season'].search(domain)
|
||||||
|
|
||||||
number = fields.Char('Member number', store=True, readonly=True,
|
number = fields.Char('Member number', store=True, readonly=True)
|
||||||
compute='_compute_number')
|
|
||||||
number_manual = fields.Char('Manual number', size=50, index=True,
|
number_manual = fields.Char('Manual number', size=50, index=True,
|
||||||
help='Manual number overwriting automatic '
|
help='Manual number overwriting automatic '
|
||||||
'numbering')
|
'numbering')
|
||||||
@ -79,18 +78,25 @@ class GolemMember(models.Model):
|
|||||||
'UNIQUE (number_manual)',
|
'UNIQUE (number_manual)',
|
||||||
_('This member number has already been used.'))]
|
_('This member number has already been used.'))]
|
||||||
|
|
||||||
@api.depends('number_manual', 'season_ids')
|
@api.depends('season_ids')
|
||||||
def _compute_number(self):
|
def _compute_is_current(self):
|
||||||
""" Computes number according to pre-existing number and chosen
|
""" Computes is current according to seasons """
|
||||||
seasons, or sets as manual """
|
default_s = self._default_season()
|
||||||
for member in self:
|
for m in self:
|
||||||
|
m.is_current = default_s in m.season_ids
|
||||||
|
|
||||||
|
@api.depends('number')
|
||||||
|
def _compute_is_number_manual(self):
|
||||||
conf = self.env['ir.config_parameter']
|
conf = self.env['ir.config_parameter']
|
||||||
if conf.get_param('golem_numberconfig_isautomatic') == '0':
|
is_num_man = (conf.get_param('golem_numberconfig_isautomatic') == '0')
|
||||||
member.number = member.number_manual
|
self.is_number_manual = is_num_man
|
||||||
else:
|
|
||||||
if member.id:
|
@api.one
|
||||||
member.number = ''
|
def _generate_number_perseason(self):
|
||||||
if conf.get_param('golem_numberconfig_isperseason') == '1':
|
""" Number generation in case of per season configuration """
|
||||||
|
res = None
|
||||||
|
conf = self.env['ir.config_parameter']
|
||||||
|
for member in self:
|
||||||
for s in member.season_ids:
|
for s in member.season_ids:
|
||||||
domain = ['&',
|
domain = ['&',
|
||||||
('member_id', '=', member.id),
|
('member_id', '=', member.id),
|
||||||
@ -108,16 +114,21 @@ class GolemMember(models.Model):
|
|||||||
'number': number}
|
'number': number}
|
||||||
mn = member_num.create(data)
|
mn = member_num.create(data)
|
||||||
if s.is_default:
|
if s.is_default:
|
||||||
member.number = mn.number
|
res = mn.number
|
||||||
else:
|
return res
|
||||||
|
|
||||||
|
@api.one
|
||||||
|
def _generate_number_global(self):
|
||||||
|
""" Number generation in case of global configuration """
|
||||||
|
for member in self:
|
||||||
|
conf = self.env['ir.config_parameter']
|
||||||
domain = ['&',
|
domain = ['&',
|
||||||
('member_id', '=', member.id),
|
('member_id', '=', member.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',
|
last = int(conf.get_param('golem_number_counter', 0))
|
||||||
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')
|
||||||
@ -126,20 +137,37 @@ class GolemMember(models.Model):
|
|||||||
'season_id': None,
|
'season_id': None,
|
||||||
'number': number}
|
'number': number}
|
||||||
mn = member_num.create(data)
|
mn = member_num.create(data)
|
||||||
member.number = mn.number
|
return mn.number
|
||||||
|
|
||||||
@api.depends('season_ids')
|
@api.one
|
||||||
def _compute_is_current(self):
|
def _generate_number(self):
|
||||||
""" Computes is current according to seasons """
|
""" Computes number according to pre-existing number and chosen
|
||||||
default_s = self._default_season()
|
seasons """
|
||||||
for m in self:
|
for member in self:
|
||||||
m.is_current = default_s in m.season_ids
|
|
||||||
|
|
||||||
@api.depends('lastname')
|
|
||||||
def _compute_is_number_manual(self):
|
|
||||||
conf = self.env['ir.config_parameter']
|
conf = self.env['ir.config_parameter']
|
||||||
is_num_man = (conf.get_param('golem_numberconfig_isautomatic') == '0')
|
if conf.get_param('golem_numberconfig_isautomatic') == '0':
|
||||||
self.is_number_manual = is_num_man
|
member.number = member.number_manual
|
||||||
|
else:
|
||||||
|
if conf.get_param('golem_numberconfig_isperseason') == '1':
|
||||||
|
mn = member._generate_number_perseason()
|
||||||
|
else:
|
||||||
|
mn = member._generate_number_global()
|
||||||
|
if mn:
|
||||||
|
member.number = mn[0]
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
@api.returns('self', lambda rec: rec.id)
|
||||||
|
def create(self, values):
|
||||||
|
new_member = super(GolemMember, self).create(values)
|
||||||
|
new_member._generate_number()
|
||||||
|
return new_member
|
||||||
|
|
||||||
|
@api.multi
|
||||||
|
def write(self, values):
|
||||||
|
res = super(GolemMember, self).write(values)
|
||||||
|
if 'season_ids' in values or 'number_manual' in values:
|
||||||
|
self._generate_number()
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
class GolemMemberNumber(models.Model):
|
class GolemMemberNumber(models.Model):
|
||||||
@ -205,4 +233,4 @@ class GolemNumberConfig(models.TransientModel):
|
|||||||
conf.set_param('golem_number_counter', '0')
|
conf.set_param('golem_number_counter', '0')
|
||||||
self.env['golem.member.number'].search([]).unlink()
|
self.env['golem.member.number'].search([]).unlink()
|
||||||
self.env['golem.season'].search([]).write({'member_counter': 0})
|
self.env['golem.season'].search([]).write({'member_counter': 0})
|
||||||
self.env['golem.member'].search([])._compute_number()
|
self.env['golem.member'].search([])._generate_number()
|
||||||
|
@ -70,7 +70,7 @@ class GolemSeason(models.Model):
|
|||||||
if 'golem.member' in self.env.registry:
|
if 'golem.member' in self.env.registry:
|
||||||
all_members = self.env['golem.member'].search([])
|
all_members = self.env['golem.member'].search([])
|
||||||
all_members._compute_is_current()
|
all_members._compute_is_current()
|
||||||
all_members._compute_number()
|
all_members._generate_number()
|
||||||
if 'golem.activity' in self.env.registry:
|
if 'golem.activity' in self.env.registry:
|
||||||
self.env['golem.activity'].search([])._compute_is_current()
|
self.env['golem.activity'].search([])._compute_is_current()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user