From 01a34e0e3befba759eb111840b504e423f2335ca Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 12 Apr 2018 18:25:57 +0200 Subject: [PATCH] fonction de reporting --- golem_resource_report/__init__.py | 1 + golem_resource_report/__manifest__.py | 1 + golem_resource_report/reports/__init__.py | 19 +++++ .../reports/golem_reservation_report.py | 79 +++++++++++++++++++ .../reports/golem_reservation_report.xml | 66 ++++++++++++++-- .../reports/golem_reservation_report_menu.xml | 49 ++++++++++++ .../views/golem_resource_report_menu.xml | 18 +++++ .../wizard/golem_resource_report_wizard.py | 11 ++- .../golem_resource_report_wizard_views.xml | 6 +- 9 files changed, 236 insertions(+), 14 deletions(-) create mode 100644 golem_resource_report/reports/__init__.py create mode 100644 golem_resource_report/reports/golem_reservation_report.py create mode 100644 golem_resource_report/reports/golem_reservation_report_menu.xml diff --git a/golem_resource_report/__init__.py b/golem_resource_report/__init__.py index 27ce4b7..f1d4cf2 100644 --- a/golem_resource_report/__init__.py +++ b/golem_resource_report/__init__.py @@ -18,3 +18,4 @@ #from . import models from . import wizard +from . import reports diff --git a/golem_resource_report/__manifest__.py b/golem_resource_report/__manifest__.py index 4b14908..d9c90a5 100644 --- a/golem_resource_report/__manifest__.py +++ b/golem_resource_report/__manifest__.py @@ -28,6 +28,7 @@ 'installable': True, 'depends': ['golem_resource'], 'data': ['reports/golem_reservation_report.xml', + 'reports/golem_reservation_report_menu.xml', 'views/golem_resource_report_menu.xml', 'wizard/golem_resource_report_wizard_views.xml'] } diff --git a/golem_resource_report/reports/__init__.py b/golem_resource_report/reports/__init__.py new file mode 100644 index 0000000..1c0b8fe --- /dev/null +++ b/golem_resource_report/reports/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from . import golem_reservation_report diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py new file mode 100644 index 0000000..a1858be --- /dev/null +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -0,0 +1,79 @@ +# -*- coding: utf-8 -*- + +# Copyright 2018 Youssef El Ouahby +# Copyright 2018 Fabien Bourgeois +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import time + +from odoo import models, api + + +class GolemResevationReport(models.AbstractModel): + _name = 'report.golem_resource_report.golem_reservation_report' + + def get_total_reservation(self, data): + domain = [('date_start', '>', data['date_start']), + ('date_stop', '<', data['date_stop']), + ('resource_id', 'in', data['resource_ids'])] + return self.env['golem.resource.reservation'].search_count(domain) + + + def get_data(self, data): + lst = [] + 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') + res = {} + for reservation in reservations: + res = { + 'name': reservation.name, + 'resource_name': reservation.resource_id.name, + 'client': reservation.partner_id.name, + 'date_start': reservation.date_start, + 'date_stop': reservation.date_stop + } + lst.append(res) + + #self.total_student = 0 + """for student in student_search: + self.total_student += 1 + res = { + 'name': student.name, + 'middle_name': student.middle_name, + 'last_name': student.last_name, + 'application_no': student.application_number, + } + lst.append(res)""" + return lst + + @api.model + def render_html(self, docids, data=None): + model = self.env.context.get('active_model') + docs = self.env[model].browse(self.env.context.get('active_id')) + docargs = { + 'doc_ids': self.ids, + 'doc_model': model, + 'docs': docs, + 'time': time, + 'data': data, + 'date_start': data['date_start'], + 'date_stop': data['date_stop'], + 'get_total_reservation': self.get_total_reservation(data), + 'get_data': self.get_data(data), + } + 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 71bdca2..60f8da5 100644 --- a/golem_resource_report/reports/golem_reservation_report.xml +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -1,8 +1,62 @@ - + + - + + + diff --git a/golem_resource_report/reports/golem_reservation_report_menu.xml b/golem_resource_report/reports/golem_reservation_report_menu.xml new file mode 100644 index 0000000..d1090cd --- /dev/null +++ b/golem_resource_report/reports/golem_reservation_report_menu.xml @@ -0,0 +1,49 @@ + + + + + + European A4 Landscape + + A4 + 0 + 0 + Landscape + 10 + 23 + 7 + 7 + + 35 + 90 + + + + diff --git a/golem_resource_report/views/golem_resource_report_menu.xml b/golem_resource_report/views/golem_resource_report_menu.xml index ec823e4..14ba437 100644 --- a/golem_resource_report/views/golem_resource_report_menu.xml +++ b/golem_resource_report/views/golem_resource_report_menu.xml @@ -1,3 +1,21 @@ + + diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py index cb0dafe..c56a2f3 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard.py +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -38,7 +38,10 @@ class GolemResourceReportWizard(models.TransientModel): raise ValidationError(_("Stop Date cannot be set before \ Start Date.")) else: - domain = [('date_start', '>', record.date_start), - ('date_stop', '<', record.date_stop), - ('resource_id', 'in', record.selected_resource_ids.ids)] - data = self.env['golem.resource.reservation'].search(domain) + data = self.read( + ['resource_ids', 'date_start', 'date_stop'])[0] + return self.env['report'].get_action( + self, 'golem_resource_report.golem_reservation_report', + data=data) + + diff --git a/golem_resource_report/wizard/golem_resource_report_wizard_views.xml b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml index 07aa754..1cfbdea 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard_views.xml +++ b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml @@ -18,7 +18,6 @@ along with this program. If not, see . --> - GOLEM resource Report Wizard Form @@ -28,7 +27,7 @@ along with this program. If not, see . - + @@ -45,7 +44,6 @@ along with this program. If not, see . - - +