From 3f9aa5799996c3b33548bb5cf0153904cf1e121c Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 11 Jul 2017 14:53:36 +0200 Subject: [PATCH 1/3] date_range: improve 'name' for generator wizard ir.rule should be active by default --- date_range/__manifest__.py | 2 +- date_range/security/date_range_security.xml | 28 ++++++++------------- date_range/wizard/date_range_generator.py | 5 +++- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/date_range/__manifest__.py b/date_range/__manifest__.py index 6b048952e..df33594f2 100644 --- a/date_range/__manifest__.py +++ b/date_range/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Date Range", "summary": "Manage all kind of date range", - "version": "10.0.1.0.0", + "version": "10.0.1.0.1", "category": "Uncategorized", "website": "https://odoo-community.org/", "author": "ACSONE SA/NV, Odoo Community Association (OCA)", diff --git a/date_range/security/date_range_security.xml b/date_range/security/date_range_security.xml index 20bea9bfe..87862f84b 100644 --- a/date_range/security/date_range_security.xml +++ b/date_range/security/date_range_security.xml @@ -1,19 +1,13 @@ - - - - Date Range Type multi-company - - - ['|',('company_id','=',user.company_id.id),('company_id','=',False)] - - - - Date Range multi-company - - - ['|',('company_id','=',user.company_id.id),('company_id','=',False)] - - - + + + Date Range Type multi-company + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + + + Date Range multi-company + + ['|',('company_id','=',user.company_id.id),('company_id','=',False)] + diff --git a/date_range/wizard/date_range_generator.py b/date_range/wizard/date_range_generator.py index 7abfba99d..c4c37415d 100644 --- a/date_range/wizard/date_range_generator.py +++ b/date_range/wizard/date_range_generator.py @@ -43,6 +43,7 @@ class DateRangeGenerator(models.TransientModel): count=self.count+1) vals = list(vals) date_ranges = [] + month_digits = len(unicode(self.count)) for idx, dt_start in enumerate(vals[:-1]): date_start = fields.Date.to_string(dt_start.date()) # always remove 1 day for the date_end since range limits are @@ -50,7 +51,9 @@ class DateRangeGenerator(models.TransientModel): dt_end = vals[idx+1].date() - relativedelta(days=1) date_end = fields.Date.to_string(dt_end) date_ranges.append({ - 'name': '%s-%d' % (self.name_prefix, idx + 1), + 'name': '%s-%s' % ( + self.name_prefix, + unicode(idx + 1).zfill(month_digits)), 'date_start': date_start, 'date_end': date_end, 'type_id': self.type_id.id, From 0e3587d81cd721bae3b57e184bf0440775d5af84 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 11 Jul 2017 17:40:57 +0200 Subject: [PATCH 2/3] date_range: don't auto-add '-' after prefix when generating date ranges via wizard --- date_range/wizard/date_range_generator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/date_range/wizard/date_range_generator.py b/date_range/wizard/date_range_generator.py index c4c37415d..919b07b5e 100644 --- a/date_range/wizard/date_range_generator.py +++ b/date_range/wizard/date_range_generator.py @@ -51,7 +51,7 @@ class DateRangeGenerator(models.TransientModel): dt_end = vals[idx+1].date() - relativedelta(days=1) date_end = fields.Date.to_string(dt_end) date_ranges.append({ - 'name': '%s-%s' % ( + 'name': '%s%s' % ( self.name_prefix, unicode(idx + 1).zfill(month_digits)), 'date_start': date_start, From 72a1ea0b900c15e3c30ff88259ef32e7f0a01d20 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 11 Jul 2017 23:02:11 +0200 Subject: [PATCH 3/3] date_range: code fine tuning suggested by Sylvain Garancher --- date_range/wizard/date_range_generator.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/date_range/wizard/date_range_generator.py b/date_range/wizard/date_range_generator.py index 919b07b5e..970af6b71 100644 --- a/date_range/wizard/date_range_generator.py +++ b/date_range/wizard/date_range_generator.py @@ -43,7 +43,7 @@ class DateRangeGenerator(models.TransientModel): count=self.count+1) vals = list(vals) date_ranges = [] - month_digits = len(unicode(self.count)) + count_digits = len(unicode(self.count)) for idx, dt_start in enumerate(vals[:-1]): date_start = fields.Date.to_string(dt_start.date()) # always remove 1 day for the date_end since range limits are @@ -51,9 +51,8 @@ class DateRangeGenerator(models.TransientModel): dt_end = vals[idx+1].date() - relativedelta(days=1) date_end = fields.Date.to_string(dt_end) date_ranges.append({ - 'name': '%s%s' % ( - self.name_prefix, - unicode(idx + 1).zfill(month_digits)), + 'name': '%s%0*d' % ( + self.name_prefix, count_digits, idx + 1), 'date_start': date_start, 'date_end': date_end, 'type_id': self.type_id.id,