[FIX]GOLEM Number config : now correcly handling only for new

This commit is contained in:
Fabien Bourgeois 2017-06-28 15:38:36 +02:00
parent dcefa1dda6
commit 13a7785fe5
4 changed files with 24 additions and 5 deletions

View File

@ -23,6 +23,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
eval="('golem_numberconfig_isautomatic', '1')" />
<function model="ir.config_parameter" name="set_param"
eval="('golem_numberconfig_isperseason', '1')" />
<function model="ir.config_parameter" name="set_param"
eval="('golem_numberconfig_isfornewmembersonly', '0')" />
<function model="ir.config_parameter" name="set_param"
eval="('golem_numberconfig_prefix', '')" />
<function model="ir.config_parameter" name="set_param"

View File

@ -193,11 +193,14 @@ class GolemMember(models.Model):
""" Computes number according to pre-existing number and chosen
seasons """
conf = self.env['ir.config_parameter']
isauto = conf.get_param('golem_numberconfig_isautomatic') == '1'
isperseason = conf.get_param('golem_numberconfig_isperseason') == '1'
isfornew = conf.get_param('golem_numberconfig_isfornewmembersonly') == '1'
for member in self:
if conf.get_param('golem_numberconfig_isautomatic') == '0':
if not isauto or (isfornew and member.number_manual):
member.number = member.number_manual
else:
if conf.get_param('golem_numberconfig_isperseason') == '1':
if isperseason:
member_num = member.generate_number_perseason()
else:
member_num = member.generate_number_global()
@ -282,6 +285,13 @@ class GolemNumberConfig(models.TransientModel):
self.env['golem.season'].search([]).write({
'member_counter': int(self.number_from)
})
@api.multi
def apply_nocompute(self):
""" Apply new configuration only for new members (keep old numbers) """
self.ensure_one()
self.apply_config()
conf = self.env['ir.config_parameter']
conf.set_param('golem_numberconfig_isfornewmembersonly', '1')
@api.multi
def apply_recompute(self):
@ -289,6 +299,7 @@ class GolemNumberConfig(models.TransientModel):
self.ensure_one()
self.apply_config()
conf = self.env['ir.config_parameter']
conf.set_param('golem_numberconfig_isfornewmembersonly', '0')
conf.set_param('golem_number_counter', self.number_from)
self.env['golem.member.number'].search([]).unlink()
self.env['golem.season'].search([]).write({

View File

@ -142,7 +142,7 @@ class GolemMemberTestCase(TransactionCase):
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '0',
'prefix': False})
conf.apply_config()
conf.apply_nocompute()
self.assertEqual(self.member1.number, u'M01')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Buddy',
@ -158,7 +158,7 @@ class GolemMemberTestCase(TransactionCase):
'is_per_season': '0',
'prefix': False,
'number_from': 50})
conf.apply_config()
conf.apply_nocompute()
self.assertEqual(self.member1.number, u'M01')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Buddy',
@ -168,3 +168,9 @@ class GolemMemberTestCase(TransactionCase):
'season_ids': [self.season_current]})
self.assertEqual(new_m.number, u'50')
self.assertEqual(new_m2.number, u'51')
# After season changing
self.season_next.do_default_season()
self.assertEqual(self.member1.number, u'M01')
self.assertEqual(new_m.number, u'50')
self.member1.season_ids += self.season_next
self.assertEqual(self.member1.number, u'M01')

View File

@ -38,7 +38,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</group>
</sheet>
<footer>
<button type="object" name="apply_config"
<button type="object" name="apply_nocompute"
string="Apply for new members" />
<button type="object" name="apply_recompute"
string="Apply and recompute all member numbers"