From a6b65dfa53c8197df1902ce4a3510a67e9a85494 Mon Sep 17 00:00:00 2001 From: Fabien Bourgeois Date: Wed, 28 Jun 2017 16:25:00 +0200 Subject: [PATCH] [FIX]Season member number generation : avoid useless loop when default season is changed --- golem_member/models/golem_member.py | 11 +++++------ golem_member/tests/test_golem_member.py | 12 ++++++++---- golem_season/models/golem_season.py | 5 ++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/golem_member/models/golem_member.py b/golem_member/models/golem_member.py index 1341b89..4329236 100644 --- a/golem_member/models/golem_member.py +++ b/golem_member/models/golem_member.py @@ -201,10 +201,9 @@ class GolemMember(models.Model): member.number = member.number_manual else: if isperseason: - member_num = member.generate_number_perseason() + member.number = member.generate_number_perseason() else: - member_num = member.generate_number_global() - member.number = member_num + member.number = member.generate_number_global() @api.model def create(self, values): @@ -281,9 +280,10 @@ class GolemNumberConfig(models.TransientModel): conf.set_param('golem_numberconfig_isperseason', self.is_per_season) conf.set_param('golem_numberconfig_prefix', self.prefix or '') if self.number_from: - conf.set_param('golem_number_counter', self.number_from) + _LOGGER.warning('New number_from %s', self.number_from) + conf.set_param('golem_number_counter', unicode(self.number_from)) self.env['golem.season'].search([]).write({ - 'member_counter': int(self.number_from) + 'member_counter': self.number_from }) @api.multi def apply_nocompute(self): @@ -300,7 +300,6 @@ class GolemNumberConfig(models.TransientModel): 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({ 'member_counter': int(self.number_from) diff --git a/golem_member/tests/test_golem_member.py b/golem_member/tests/test_golem_member.py index 4c64978..d58cb81 100644 --- a/golem_member/tests/test_golem_member.py +++ b/golem_member/tests/test_golem_member.py @@ -26,7 +26,7 @@ class GolemMemberTestCase(TransactionCase): """ GOLEM member testing """ def setUp(self, *args, **kwargs): - """ Bootstrap season and memebers """ + """ Bootstrap season and members """ super(GolemMemberTestCase, self).setUp(*args, **kwargs) self.member_numberconfig_model = self.env['golem.member.numberconfig'] season_mdl = self.env['golem.season'].sudo() @@ -145,10 +145,10 @@ class GolemMemberTestCase(TransactionCase): conf.apply_nocompute() self.assertEqual(self.member1.number, u'M01') new_m = self.member_model.create({'lastname': 'NEW', - 'firstname': 'Buddy', + 'firstname': 'Dewie', 'season_ids': [self.season_current]}) new_m2 = self.member_model.create({'lastname': 'NEW', - 'firstname': 'Buddy', + 'firstname': 'Dowa', 'season_ids': [self.season_current]}) self.assertEqual(new_m.number, u'1') self.assertEqual(new_m2.number, u'2') @@ -164,7 +164,7 @@ class GolemMemberTestCase(TransactionCase): 'firstname': 'Buddy', 'season_ids': [self.season_current]}) new_m2 = self.member_model.create({'lastname': 'NEW', - 'firstname': 'Buddy', + 'firstname': 'Bobby', 'season_ids': [self.season_current]}) self.assertEqual(new_m.number, u'50') self.assertEqual(new_m2.number, u'51') @@ -174,3 +174,7 @@ class GolemMemberTestCase(TransactionCase): self.assertEqual(new_m.number, u'50') self.member1.season_ids += self.season_next self.assertEqual(self.member1.number, u'M01') + new_m3 = self.member_model.create({'lastname': 'NEW', + 'firstname': 'Barny', + 'season_ids': [self.season_current]}) + self.assertEqual(new_m3.number, u'52') diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py index 53d2d9f..a16d2fe 100644 --- a/golem_season/models/golem_season.py +++ b/golem_season/models/golem_season.py @@ -72,7 +72,10 @@ class GolemSeason(models.Model): if 'golem.member' in self.env.registry: all_members = self.env['golem.member'].search([]) all_members.compute_is_current() - all_members.generate_number() + conf = self.env['ir.config_parameter'] + if conf.get_param('golem_numberconfig_isautomatic') == '1' and \ + conf.get_param('golem_numberconfig_isperseason') == '1': + all_members.generate_number() if 'golem.activity' in self.env.registry: self.env['golem.activity'].search([]).compute_is_current()