From 654d2de6b4240c68c1ab1e318bbee11db0f9c798 Mon Sep 17 00:00:00 2001 From: Fabien BOURGEOIS Date: Fri, 25 May 2018 16:32:44 +0200 Subject: [PATCH] [REF][IMP]GOLEM Resource Report : huge refactoring of report model and data with representation per date, then, resource, then dates, then periods --- .../reports/golem_reservation_report.py | 39 +++++++---- .../reports/golem_reservation_report.xml | 64 ++++++++++++------- .../wizard/golem_resource_report_wizard.py | 8 +-- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py index 8e94b7a..3faa007 100644 --- a/golem_resource_report/reports/golem_reservation_report.py +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -20,7 +20,9 @@ import time from random import randint -from odoo import models, api +from odoo import models, fields, api + +# FIXME: usage of Odoo fields will be needed for i18n awareness def get_client_color(partner_number): """ Get Client Color """ @@ -44,13 +46,13 @@ class GolemResevationReport(models.AbstractModel): def get_data(self, data): """ Get Resevation Data """ - res = [] domain = [('date_start', '>', data['date_start']), ('date_stop', '<', data['date_stop']), ('resource_id', 'in', data['resource_ids'])] reservations = self.env['golem.resource.reservation'].search(domain, order='date_start') total_reservations = len(reservations) - resources = list(reservations.mapped('resource_id.name')) + resources = {r.resource_id.id: r.resource_id.name for r in reservations} + days = sorted(list(set(reservations.mapped('day_start')))) partner_ids = reservations.mapped('partner_id.id') partner_colors = {} @@ -59,36 +61,47 @@ class GolemResevationReport(models.AbstractModel): partner_colors[str(partner_id)] = get_client_color(partner_number) partner_number += 1 + res = {} # List of multi-levels : group by resource, then, day_start for reservation in reservations: + resource = reservation.resource_id.id + day_start = reservation.day_start + if not resource in res: + res[resource] = {} + if not day_start in res[resource]: + res[resource][day_start] = [] line = { 'name': reservation.name, 'resource_name': reservation.resource_id.name, - 'client': reservation.partner_id.name, + 'partner': reservation.partner_id.name, 'date_start': reservation.date_start, 'date_stop': reservation.date_stop, 'day_start': reservation.day_start, - 'bgcolor': partner_colors[str(reservation.partner_id.id)] + 'day_stop': fields.Datetime.from_string(reservation.date_stop).strftime('%Y-%m-%d'), + 'bgcolor': partner_colors[str(reservation.partner_id.id)], + 'note': reservation.note } - res.append(line) - return res, total_reservations, resources + res[resource][day_start].append(line) + return res, total_reservations, resources, days @api.model def render_html(self, docids, data=None): """ Render HTML """ model = self.env.context.get('active_model') docs = self.env[model].browse(self.env.context.get('active_id')) - _data, total_reservations, resources = self.get_data(data) + _data, total_reservations, resources, days = self.get_data(data) docargs = { 'doc_ids': self.ids, 'doc_model': model, 'docs': docs, + 'company': self.env.ref('base.main_company'), 'time': time, 'data': data, - 'date_start': data['date_start'], - 'date_stop': data['date_stop'], - 'get_total_reservation': total_reservations, - 'get_data': _data, - 'get_resource': resources + 'date_start': '%s 00:00:00' % data['date_start'], + 'date_stop': '%s 23:59:59' % data['date_stop'], + 'total_reservations': total_reservations, + 'datas': _data, + 'resources': resources, + 'days': days } return self.env['report'] \ .render('golem_resource_report.golem_reservation_report', docargs) diff --git a/golem_resource_report/reports/golem_reservation_report.xml b/golem_resource_report/reports/golem_reservation_report.xml index e824b9f..1b09f3d 100644 --- a/golem_resource_report/reports/golem_reservation_report.xml +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -24,32 +24,48 @@ along with this program. If not, see .
-

- - - - +

+ : reservations
+ + From Date: + + To Date: + + +

+
-
Maison Phare toutes les reservations
- From Date: - - - To Date: -
-
+ + + + + - -
+
- + - - - - - - + + + + diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py index fd6a41e..aa89300 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard.py +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -26,17 +26,15 @@ class GolemResourceReportWizard(models.TransientModel): _name = "golem.resource.report.wizard" resource_ids = fields.Many2many('golem.resource') - date_start = fields.Datetime(required=True) - date_stop = fields.Datetime(required=True) + date_start = fields.Date(required=True) + date_stop = fields.Date(required=True) @api.multi def print_resource_report(self): """ Print Report """ self.ensure_one() record = self[0] - start_date = fields.Datetime.from_string(record.date_start) - stop_date = fields.Datetime.from_string(record.date_stop) - if start_date > stop_date: + if record.date_start > record.date_stop: raise ValidationError(_('Stop Date cannot be set before Start Date.')) else: data = self.read(
- Date :
- On behalf of :
-
+ + + +
+ + - + + + + From
+ To +
+

+
+ For +

+
+
+