diff --git a/golem_resource_report/__init__.py b/golem_resource_report/__init__.py new file mode 100644 index 0000000..f1d4cf2 --- /dev/null +++ b/golem_resource_report/__init__.py @@ -0,0 +1,21 @@ +# -*- 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 +from . import reports diff --git a/golem_resource_report/__manifest__.py b/golem_resource_report/__manifest__.py new file mode 100644 index 0000000..d9c90a5 --- /dev/null +++ b/golem_resource_report/__manifest__.py @@ -0,0 +1,34 @@ +# -*- 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', + '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..d482e8a --- /dev/null +++ b/golem_resource_report/reports/golem_reservation_report.py @@ -0,0 +1,107 @@ +# -*- 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 Reservation Report """ +import time + +from random import randint +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']), + ('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, partner_number): + "Get Client Color" + 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): + "Get Resevation 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') + 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, + 'date_start': reservation.date_start, + 'date_stop': reservation.date_stop, + 'day_start': reservation.day_start, + 'bgcolor': partner_colors[str(reservation.partner_id.id)] + } + lst.append(res) + return lst + + @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 = { + '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), + '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 new file mode 100644 index 0000000..0df78a7 --- /dev/null +++ b/golem_resource_report/reports/golem_reservation_report.xml @@ -0,0 +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 new file mode 100644 index 0000000..14ba437 --- /dev/null +++ b/golem_resource_report/views/golem_resource_report_menu.xml @@ -0,0 +1,38 @@ + + + + + + + + Resources Reports + golem.resource.report.wizard + form + form + + {} + new + + + + + + + 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..684c41d --- /dev/null +++ b/golem_resource_report/wizard/golem_resource_report_wizard.py @@ -0,0 +1,46 @@ +# -*- 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 Report Wizard """ + +from odoo import models, fields, api, _ +from odoo.exceptions import ValidationError + +class GolemResourceReportWizard(models.TransientModel): + """GOLEM Report Wizard : Choose report parameters """ + _name = "golem.resource.report.wizard" + + resource_ids = fields.Many2many('golem.resource') + date_start = fields.Datetime(required=True) + date_stop = fields.Datetime(required=True) + + @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) + if start_date > stop_date: + raise ValidationError(_("Stop Date cannot be set before \ + Start Date.")) + else: + 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 new file mode 100644 index 0000000..0d28277 --- /dev/null +++ b/golem_resource_report/wizard/golem_resource_report_wizard_views.xml @@ -0,0 +1,49 @@ + + + + + + + GOLEM resource Report Wizard Form + golem.resource.report.wizard + +
+ + + + + + + + + + + + + + +
+
+
+
+