From 2abaabc002d0e03cd1bb918894effe02c80c6d81 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Wed, 11 Apr 2018 21:27:07 +0200 Subject: [PATCH 1/7] wizard pour choisir les resources --- golem_resource_report/__init__.py | 20 +++++++ golem_resource_report/__manifest__.py | 33 ++++++++++++ .../reports/golem_reservation_report.xml | 8 +++ .../views/golem_resource_report_menu.xml | 14 +++++ golem_resource_report/wizard/__init__.py | 19 +++++++ .../wizard/golem_resource_report_wizard.py | 38 ++++++++++++++ .../golem_resource_report_wizard_views.xml | 52 +++++++++++++++++++ 7 files changed, 184 insertions(+) create mode 100644 golem_resource_report/__init__.py create mode 100644 golem_resource_report/__manifest__.py create mode 100644 golem_resource_report/reports/golem_reservation_report.xml create mode 100644 golem_resource_report/views/golem_resource_report_menu.xml create mode 100644 golem_resource_report/wizard/__init__.py create mode 100644 golem_resource_report/wizard/golem_resource_report_wizard.py create mode 100644 golem_resource_report/wizard/golem_resource_report_wizard_views.xml diff --git a/golem_resource_report/__init__.py b/golem_resource_report/__init__.py new file mode 100644 index 0000000..27ce4b7 --- /dev/null +++ b/golem_resource_report/__init__.py @@ -0,0 +1,20 @@ +# -*- 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 models +from . import wizard diff --git a/golem_resource_report/__manifest__.py b/golem_resource_report/__manifest__.py new file mode 100644 index 0000000..4b14908 --- /dev/null +++ b/golem_resource_report/__manifest__.py @@ -0,0 +1,33 @@ +# -*- 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 . + +{ + 'name': 'GOLEM resources reports', + 'summary': 'GOLEM resources reports', + 'description': ''' GOLEM resources reports ''', + 'version': '10.0.0.0.0', + 'category': 'GOLEM', + 'author': 'Youssef El Ouahby, Fabien Bourgeois', + 'license': 'AGPL-3', + 'application': True, + 'installable': True, + 'depends': ['golem_resource'], + 'data': ['reports/golem_reservation_report.xml', + 'views/golem_resource_report_menu.xml', + 'wizard/golem_resource_report_wizard_views.xml'] +} diff --git a/golem_resource_report/reports/golem_reservation_report.xml b/golem_resource_report/reports/golem_reservation_report.xml new file mode 100644 index 0000000..71bdca2 --- /dev/null +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -0,0 +1,8 @@ + + + + diff --git a/golem_resource_report/views/golem_resource_report_menu.xml b/golem_resource_report/views/golem_resource_report_menu.xml new file mode 100644 index 0000000..3facc13 --- /dev/null +++ b/golem_resource_report/views/golem_resource_report_menu.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + diff --git a/golem_resource_report/wizard/__init__.py b/golem_resource_report/wizard/__init__.py new file mode 100644 index 0000000..5ae7a4c --- /dev/null +++ b/golem_resource_report/wizard/__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_resource_report_wizard diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py new file mode 100644 index 0000000..5941c40 --- /dev/null +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -0,0 +1,38 @@ +# -*- 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 . + +""" GOLEM Resources management """ + +from odoo import models, fields, api + +class GolemResourceReportWizard(models.TransientModel): + """GOLEM Resource wizard : refusal reason for a reservation """ + _name = "golem.resource.report.wizard" + def _get_resources(self): + return self.env['golem.resource'].search([]).ids + + resource_ids = fields.Many2many('golem.resource',default=_get_resources) + selected_resource_ids = fields.Many2many('golem.resource', + domaine="[('id', in, resources_ids.ids)]") + date_start = fields.Datetime(required=True) + date_stop = fields.Datetime(required=True) + + @api.multi + def print_report(self): + for record in self: + pass diff --git a/golem_resource_report/wizard/golem_resource_report_wizard_views.xml b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml new file mode 100644 index 0000000..3d226bd --- /dev/null +++ b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml @@ -0,0 +1,52 @@ + + + + + + + + GOLEM resource Report Wizard Form + golem.resource.report.wizard + +
+ + + + + + + + + + + + + + +
+
+
+
+
+ +
+
-- 2.45.2 From c669ddae2f9bb5801ca9681af6405f6ac8522344 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 12 Apr 2018 00:52:05 +0200 Subject: [PATCH 2/7] code refactoring --- .../views/golem_resource_report_menu.xml | 12 +++++++--- .../wizard/golem_resource_report_wizard.py | 20 ++++++++++------ .../golem_resource_report_wizard_views.xml | 23 +++++++++---------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/golem_resource_report/views/golem_resource_report_menu.xml b/golem_resource_report/views/golem_resource_report_menu.xml index 3facc13..ec823e4 100644 --- a/golem_resource_report/views/golem_resource_report_menu.xml +++ b/golem_resource_report/views/golem_resource_report_menu.xml @@ -2,11 +2,17 @@ - + + Resources Reports + golem.resource.report.wizard + form + form + + {} + new + - diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py index 5941c40..cb0dafe 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard.py +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -18,21 +18,27 @@ """ GOLEM Resources management """ -from odoo import models, fields, api +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError class GolemResourceReportWizard(models.TransientModel): """GOLEM Resource wizard : refusal reason for a reservation """ _name = "golem.resource.report.wizard" - def _get_resources(self): - return self.env['golem.resource'].search([]).ids - resource_ids = fields.Many2many('golem.resource',default=_get_resources) - selected_resource_ids = fields.Many2many('golem.resource', - domaine="[('id', in, resources_ids.ids)]") + resource_ids = fields.Many2many('golem.resource') date_start = fields.Datetime(required=True) date_stop = fields.Datetime(required=True) @api.multi def print_report(self): for record in self: - pass + start_date = fields.Datetime.from_string(record.date_start) + stop_date = fields.Datetime.from_string(record.date_stop) + if start_date > stop_date: + 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) 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 3d226bd..07aa754 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard_views.xml +++ b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml @@ -27,22 +27,21 @@ along with this program. If not, see .
- - - - - - - - - - - + + + + + + + + + +
-- 2.45.2 From 01a34e0e3befba759eb111840b504e423f2335ca Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 12 Apr 2018 18:25:57 +0200 Subject: [PATCH 3/7] 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 . - - + -- 2.45.2 From 94bdd6240a280c9f57aae67b998c18e3245ebc70 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Thu, 12 Apr 2018 18:58:19 +0200 Subject: [PATCH 4/7] =?UTF-8?q?quelques=20am=C3=A9liorations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/golem_reservation_report.py | 11 ----------- .../wizard/golem_resource_report_wizard_views.xml | 4 ++-- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py index a1858be..6867d45 100644 --- a/golem_resource_report/reports/golem_reservation_report.py +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -47,17 +47,6 @@ class GolemResevationReport(models.AbstractModel): '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 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 1cfbdea..0d28277 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard_views.xml +++ b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml @@ -26,8 +26,8 @@ along with this program. If not, see .
- - + + -- 2.45.2 From ce325aa0547599a2397924087bde38917a6533ca Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Fri, 13 Apr 2018 19:18:59 +0200 Subject: [PATCH 5/7] =?UTF-8?q?Am=C3=A9lioration=20de=20l'affichage=20du?= =?UTF-8?q?=20rappoort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reports/golem_reservation_report.py | 24 ++++++++++++++++++- .../reports/golem_reservation_report.xml | 22 +++++++++-------- .../wizard/golem_resource_report_wizard.py | 12 ++++++++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py index 6867d45..1e84b7e 100644 --- a/golem_resource_report/reports/golem_reservation_report.py +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -18,9 +18,11 @@ import time +from random import randint from odoo import models, api + class GolemResevationReport(models.AbstractModel): _name = 'report.golem_resource_report.golem_reservation_report' @@ -31,6 +33,23 @@ class GolemResevationReport(models.AbstractModel): return self.env['golem.resource.reservation'].search_count(domain) + + + def get_resource(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') + lst = reservations.mapped('resource_id.name') + return lst + + def get_client_color(self, client_id): + client_id *= 777777 + color = "#0" + str(client_id) + color = color[:7] + return color + def get_data(self, data): lst = [] domain = [('date_start', '>', data['date_start']), @@ -43,8 +62,10 @@ class GolemResevationReport(models.AbstractModel): 'name': reservation.name, 'resource_name': reservation.resource_id.name, 'client': reservation.partner_id.name, + 'client_id': self.get_client_color(reservation.partner_id.id), 'date_start': reservation.date_start, - 'date_stop': reservation.date_stop + 'date_stop': reservation.date_stop, + 'day_start': reservation.day_start } lst.append(res) return lst @@ -63,6 +84,7 @@ class GolemResevationReport(models.AbstractModel): 'date_stop': data['date_stop'], 'get_total_reservation': self.get_total_reservation(data), 'get_data': self.get_data(data), + 'get_resource': self.get_resource(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 60f8da5..9162793 100644 --- a/golem_resource_report/reports/golem_reservation_report.xml +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -40,16 +40,18 @@ along with this program. If not, see . - - - - + + + + + + + +
- - - - - -
+ Date :
+ On behalf of :
+ client_id :
+
diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py index c56a2f3..fc38925 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard.py +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -40,8 +40,16 @@ class GolemResourceReportWizard(models.TransientModel): else: data = self.read( ['resource_ids', 'date_start', 'date_stop'])[0] + + 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') + lst = reservations.mapped('resource_id.name') + print '____________________________________' + print lst + return self.env['report'].get_action( self, 'golem_resource_report.golem_reservation_report', data=data) - - -- 2.45.2 From 1398cb945d323df47286adbd5f0a085c55a3f7b3 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Mon, 16 Apr 2018 17:10:22 +0200 Subject: [PATCH 6/7] modification couleurs --- .../reports/golem_reservation_report.py | 26 ++++++++++++++----- .../reports/golem_reservation_report.xml | 4 +-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py index 1e84b7e..042a10d 100644 --- a/golem_resource_report/reports/golem_reservation_report.py +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -44,10 +44,17 @@ class GolemResevationReport(models.AbstractModel): lst = reservations.mapped('resource_id.name') return lst - def get_client_color(self, client_id): - client_id *= 777777 - color = "#0" + str(client_id) - color = color[:7] + def get_client_color(self, partner_number): + colors = ['#FFFF5B', '#81EC54', '#47C8C8', '#FB5A66', '#E8E750', + '#CF4ACF', '#9655D2', '#FFA15B', '#5F68D5', '#60E652'] + color = "#000000" + if partner_number < 10: + color = colors[partner_number] + else: + red = randint(128, 255) + green = randint(128, 255) + blue = randint(128, 255) + color = "#" +hex(red)[2:]+hex(green)[2:]+hex(blue)[2:] return color def get_data(self, data): @@ -56,16 +63,23 @@ class GolemResevationReport(models.AbstractModel): ('date_stop', '<', data['date_stop']), ('resource_id', 'in', data['resource_ids'])] reservations = self.env['golem.resource.reservation'].search(domain, order='date_start') + partner_ids = reservations.mapped('partner_id.id') + partner_colors = {} + partner_number = 0 + for partner_id in partner_ids: + partner_colors[str(partner_id)] = self.get_client_color(partner_number) + partner_number +=1 + res = {} for reservation in reservations: res = { 'name': reservation.name, 'resource_name': reservation.resource_id.name, 'client': reservation.partner_id.name, - 'client_id': self.get_client_color(reservation.partner_id.id), 'date_start': reservation.date_start, 'date_stop': reservation.date_stop, - 'day_start': reservation.day_start + 'day_start': reservation.day_start, + 'bgcolor': partner_colors[str(reservation.partner_id.id)] } lst.append(res) return lst diff --git a/golem_resource_report/reports/golem_reservation_report.xml b/golem_resource_report/reports/golem_reservation_report.xml index 9162793..b545aff 100644 --- a/golem_resource_report/reports/golem_reservation_report.xml +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -45,10 +45,10 @@ along with this program. If not, see . - + Date :
On behalf of :
- client_id :
+ client_id :
-- 2.45.2 From e7464a62b305464d352169abf118336bfaaf00d9 Mon Sep 17 00:00:00 2001 From: eloyoussef Date: Mon, 16 Apr 2018 17:48:14 +0200 Subject: [PATCH 7/7] code refactoring --- .../reports/golem_reservation_report.py | 13 ++++++++----- .../reports/golem_reservation_report.xml | 2 -- .../wizard/golem_resource_report_wizard.py | 15 +++------------ 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/golem_resource_report/reports/golem_reservation_report.py b/golem_resource_report/reports/golem_reservation_report.py index 042a10d..d482e8a 100644 --- a/golem_resource_report/reports/golem_reservation_report.py +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -15,7 +15,7 @@ # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . - +""" Golem Reservation Report """ import time from random import randint @@ -24,18 +24,18 @@ from odoo import models, api class GolemResevationReport(models.AbstractModel): + "Golem Reservation Report" _name = 'report.golem_resource_report.golem_reservation_report' def get_total_reservation(self, data): + "Get Reservation Count" 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_resource(self, data): + "Get Resource List" lst = [] domain = [('date_start', '>', data['date_start']), ('date_stop', '<', data['date_stop']), @@ -45,6 +45,7 @@ class GolemResevationReport(models.AbstractModel): return lst def get_client_color(self, partner_number): + "Get Client Color" colors = ['#FFFF5B', '#81EC54', '#47C8C8', '#FB5A66', '#E8E750', '#CF4ACF', '#9655D2', '#FFA15B', '#5F68D5', '#60E652'] color = "#000000" @@ -58,6 +59,7 @@ class GolemResevationReport(models.AbstractModel): return color def get_data(self, data): + "Get Resevation Data" lst = [] domain = [('date_start', '>', data['date_start']), ('date_stop', '<', data['date_stop']), @@ -68,7 +70,7 @@ class GolemResevationReport(models.AbstractModel): partner_number = 0 for partner_id in partner_ids: partner_colors[str(partner_id)] = self.get_client_color(partner_number) - partner_number +=1 + partner_number += 1 res = {} for reservation in reservations: @@ -86,6 +88,7 @@ class GolemResevationReport(models.AbstractModel): @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')) docargs = { diff --git a/golem_resource_report/reports/golem_reservation_report.xml b/golem_resource_report/reports/golem_reservation_report.xml index b545aff..0df78a7 100644 --- a/golem_resource_report/reports/golem_reservation_report.xml +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -40,7 +40,6 @@ along with this program. If not, see . - @@ -48,7 +47,6 @@ along with this program. If not, see . diff --git a/golem_resource_report/wizard/golem_resource_report_wizard.py b/golem_resource_report/wizard/golem_resource_report_wizard.py index fc38925..684c41d 100644 --- a/golem_resource_report/wizard/golem_resource_report_wizard.py +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -16,13 +16,13 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -""" GOLEM Resources management """ +""" GOLEM Resources Report Wizard """ from odoo import models, fields, api, _ from odoo.exceptions import ValidationError class GolemResourceReportWizard(models.TransientModel): - """GOLEM Resource wizard : refusal reason for a reservation """ + """GOLEM Report Wizard : Choose report parameters """ _name = "golem.resource.report.wizard" resource_ids = fields.Many2many('golem.resource') @@ -31,6 +31,7 @@ class GolemResourceReportWizard(models.TransientModel): @api.multi def print_report(self): + """ Print Report """ for record in self: start_date = fields.Datetime.from_string(record.date_start) stop_date = fields.Datetime.from_string(record.date_stop) @@ -40,16 +41,6 @@ class GolemResourceReportWizard(models.TransientModel): else: data = self.read( ['resource_ids', 'date_start', 'date_stop'])[0] - - 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') - lst = reservations.mapped('resource_id.name') - print '____________________________________' - print lst - return self.env['report'].get_action( self, 'golem_resource_report.golem_reservation_report', data=data) -- 2.45.2
Date :
On behalf of :
- client_id :