Reservations report #20
21
golem_resource_report/__init__.py
Normal file
21
golem_resource_report/__init__.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#from . import models
|
||||
from . import wizard
|
||||
from . import reports
|
34
golem_resource_report/__manifest__.py
Normal file
34
golem_resource_report/__manifest__.py
Normal file
@ -0,0 +1,34 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
{
|
||||
'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']
|
||||
}
|
19
golem_resource_report/reports/__init__.py
Normal file
19
golem_resource_report/reports/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
from . import golem_reservation_report
|
107
golem_resource_report/reports/golem_reservation_report.py
Normal file
107
golem_resource_report/reports/golem_reservation_report.py
Normal file
@ -0,0 +1,107 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
""" 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)
|
62
golem_resource_report/reports/golem_reservation_report.xml
Normal file
62
golem_resource_report/reports/golem_reservation_report.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
<template id="golem_reservation_report">
|
||||
<t t-call="report.html_container">
|
||||
<t t-call="report.external_layout">
|
||||
<div class="font">
|
||||
<div class="page">
|
||||
<br></br>
|
||||
<table border="1" width="100%" cellpadding="0" bgcolor="#5F8CA3" >
|
||||
<tbody>
|
||||
<tr width="100%">
|
||||
<td class="text-center" width="100%">
|
||||
<center><b>Maison Phare toutes les reservations</b><br/>
|
||||
<b>From Date: </b>
|
||||
<span t-esc="from_date" />
|
||||
<span t-raw="'%s' % date_start if date_start else ''" />
|
||||
<b>To Date:</b>
|
||||
<span t-raw="'%s' % date_stop if date_stop else ''" /></center>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table border="1" width="100%" cellpadding="0" bgcolor="#ededed" style="padding: 20px; background-color: #ededed; border-collapse:separate;">
|
||||
<tbody>
|
||||
<tr t-foreach="get_resource" t-as="resource">
|
||||
<td><span t-esc="resource"/></td>
|
||||
<t t-foreach="get_data" t-as="data">
|
||||
<t t-if="data['resource_name']==resource">
|
||||
<td t-attf-style="background-color:{{data['bgcolor']}}!important;">
|
||||
<b>Date :</b><span t-esc="data['day_start']"/><br/>
|
||||
<b>On behalf of :</b><span t-esc="data['client']"/><br/>
|
||||
</td>
|
||||
</t>
|
||||
</t>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
</data>
|
||||
</odoo>
|
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
<record id="paperformat_euro_landscape"
|
||||
model="report.paperformat">
|
||||
<field name="name">European A4 Landscape</field>
|
||||
<field name="default" eval="True" />
|
||||
<field name="format">A4</field>
|
||||
<field name="page_height">0</field>
|
||||
<field name="page_width">0</field>
|
||||
<field name="orientation">Landscape</field>
|
||||
<field name="margin_top">10</field>
|
||||
<field name="margin_bottom">23</field>
|
||||
<field name="margin_left">7</field>
|
||||
<field name="margin_right">7</field>
|
||||
<field name="header_line" eval="False" />
|
||||
<field name="header_spacing">35</field>
|
||||
<field name="dpi">90</field>
|
||||
</record>
|
||||
<report
|
||||
id="action_report_report_admission_analysis"
|
||||
model="golem.resource.report.wizard"
|
||||
string="Reservations Report"
|
||||
report_type="qweb-pdf"
|
||||
name="golem_resource_report.golem_reservation_report"
|
||||
file="golem_resource_report.golem_reservation_report"
|
||||
menu="False"
|
||||
auto="False"
|
||||
paperformat="paperformat_euro_landscape"
|
||||
/>
|
||||
</data>
|
||||
</odoo>
|
38
golem_resource_report/views/golem_resource_report_menu.xml
Normal file
38
golem_resource_report/views/golem_resource_report_menu.xml
Normal file
@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<!-- Actions -->
|
||||
<record model="ir.actions.act_window" id="golem_resource_report_action">
|
||||
<field name="name">Resources Reports</field>
|
||||
<field name="res_model">golem.resource.report.wizard</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="golem_resource_report_wizard_view_form" />
|
||||
<field name="context">{}</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- Menus -->
|
||||
<menuitem id="resource_report_menu" name="Report" parent="golem_resource.golem_resource_menu"
|
||||
action="golem_resource_report_action" sequence="10" />
|
||||
|
||||
</data>
|
||||
</odoo>
|
19
golem_resource_report/wizard/__init__.py
Normal file
19
golem_resource_report/wizard/__init__.py
Normal file
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
from . import golem_resource_report_wizard
|
46
golem_resource_report/wizard/golem_resource_report_wizard.py
Normal file
46
golem_resource_report/wizard/golem_resource_report_wizard.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
#
|
||||
# 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
""" 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)
|
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
Copyright 2018 Fabien Bourgeois <fabien@yaltik.com>
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- Forms -->
|
||||
<record model="ir.ui.view" id="golem_resource_report_wizard_view_form">
|
||||
<field name="name">GOLEM resource Report Wizard Form</field>
|
||||
<field name="model">golem.resource.report.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Resource Report">
|
||||
<group>
|
||||
<group>
|
||||
<field name="resource_ids" options="{'no_create' : True}">
|
||||
<tree >
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<group>
|
||||
<field name="date_start" />
|
||||
<field name="date_stop" />
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="print_report" string="Print Report" type="object"
|
||||
class="oe_highlight" />
|
||||
<button string="Close" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
Loading…
Reference in New Issue
Block a user