[REF]GOLEM Resource Report : global refactoring

This commit is contained in:
Fabien BOURGEOIS 2018-05-25 11:42:48 +02:00
parent 704e2809c2
commit 66a46d65f6
9 changed files with 161 additions and 148 deletions

View File

@ -16,6 +16,4 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
#from . import models from . import reports, wizard
from . import wizard
from . import reports

View File

@ -20,14 +20,15 @@
'name': 'GOLEM resources reports', 'name': 'GOLEM resources reports',
'summary': 'GOLEM resources reports', 'summary': 'GOLEM resources reports',
'description': ''' GOLEM resources reports ''', 'description': ''' GOLEM resources reports ''',
'version': '10.0.0.0.0', 'version': '10.0.0.1.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois', 'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': True, 'application': False,
'installable': True, 'installable': True,
'depends': ['golem_resource'], 'depends': ['golem_resource'],
'data': ['reports/golem_reservation_report.xml', 'data': ['data/golem_resource_report_data.xml',
'reports/golem_reservation_report.xml',
'reports/golem_reservation_report_menu.xml', 'reports/golem_reservation_report_menu.xml',
'wizard/golem_resource_report_wizard_views.xml', 'wizard/golem_resource_report_wizard_views.xml',
'views/golem_resource_report_menu.xml'] 'views/golem_resource_report_menu.xml']

View File

@ -0,0 +1,40 @@
<?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>
</data>
</odoo>

View File

@ -15,66 +15,52 @@
# #
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
""" Golem Reservation Report """
import time
""" Golem Reservation Report """
import time
from random import randint from random import randint
from odoo import models, api from odoo import models, api
def get_client_color(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
class GolemResevationReport(models.AbstractModel): class GolemResevationReport(models.AbstractModel):
"Golem Reservation Report" """ Golem Reservation Report """
_name = 'report.golem_resource_report.golem_reservation_report' _name = 'report.golem_resource_report.golem_reservation_report'
_description = '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): def get_data(self, data):
"Get Resevation Data" """ Get Resevation Data """
lst = [] res = []
domain = [('date_start', '>', data['date_start']), domain = [('date_start', '>', data['date_start']),
('date_stop', '<', data['date_stop']), ('date_stop', '<', data['date_stop']),
('resource_id', 'in', data['resource_ids'])] ('resource_id', 'in', data['resource_ids'])]
reservations = self.env['golem.resource.reservation'].search(domain, order='date_start') reservations = self.env['golem.resource.reservation'].search(domain, order='date_start')
total_reservations = len(reservations)
resources = list(reservations.mapped('resource_id.name'))
partner_ids = reservations.mapped('partner_id.id') partner_ids = reservations.mapped('partner_id.id')
partner_colors = {} partner_colors = {}
partner_number = 0 partner_number = 0
for partner_id in partner_ids: for partner_id in partner_ids:
partner_colors[str(partner_id)] = self.get_client_color(partner_number) partner_colors[str(partner_id)] = get_client_color(partner_number)
partner_number += 1 partner_number += 1
res = {}
for reservation in reservations: for reservation in reservations:
res = { line = {
'name': reservation.name, 'name': reservation.name,
'resource_name': reservation.resource_id.name, 'resource_name': reservation.resource_id.name,
'client': reservation.partner_id.name, 'client': reservation.partner_id.name,
@ -83,14 +69,15 @@ class GolemResevationReport(models.AbstractModel):
'day_start': reservation.day_start, 'day_start': reservation.day_start,
'bgcolor': partner_colors[str(reservation.partner_id.id)] 'bgcolor': partner_colors[str(reservation.partner_id.id)]
} }
lst.append(res) res.append(line)
return lst return res, total_reservations, resources
@api.model @api.model
def render_html(self, docids, data=None): def render_html(self, docids, data=None):
"Render HTML" """ Render HTML """
model = self.env.context.get('active_model') model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id')) docs = self.env[model].browse(self.env.context.get('active_id'))
_data, total_reservations, resources = self.get_data(data)
docargs = { docargs = {
'doc_ids': self.ids, 'doc_ids': self.ids,
'doc_model': model, 'doc_model': model,
@ -99,9 +86,9 @@ class GolemResevationReport(models.AbstractModel):
'data': data, 'data': data,
'date_start': data['date_start'], 'date_start': data['date_start'],
'date_stop': data['date_stop'], 'date_stop': data['date_stop'],
'get_total_reservation': self.get_total_reservation(data), 'get_total_reservation': total_reservations,
'get_data': self.get_data(data), 'get_data': _data,
'get_resource': self.get_resource(data), 'get_resource': resources
} }
return self.env['report'] \ return self.env['report'] \
.render('golem_resource_report.golem_reservation_report', docargs) .render('golem_resource_report.golem_reservation_report', docargs)

View File

@ -17,46 +17,48 @@ 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/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<odoo> <odoo>
<data> <data>
<template id="golem_reservation_report">
<t t-call="report.html_container"> <template id="golem_reservation_report">
<t t-call="report.external_layout"> <t t-call="report.html_container">
<div class="font"> <t t-call="report.external_layout">
<div class="page"> <div class="font">
<br></br> <div class="page">
<table border="1" width="100%" cellpadding="0" bgcolor="#5F8CA3" > <br></br>
<tbody> <table border="1" width="100%" cellpadding="0" bgcolor="#5F8CA3" >
<tr width="100%"> <tbody>
<td class="text-center" width="100%"> <tr width="100%">
<center><b>Maison Phare toutes les reservations</b><br/> <td class="text-center" width="100%">
<b>From Date: </b> <center><b>Maison Phare toutes les reservations</b><br/>
<span t-esc="from_date" /> <b>From Date: </b>
<span t-raw="'%s' % date_start if date_start else ''" /> <span t-esc="from_date" />
<b>To Date:</b> <span t-raw="'%s' % date_start if date_start else ''" />
<span t-raw="'%s' % date_stop if date_stop else ''" /></center> <b>To Date:</b>
</td> <span t-raw="'%s' % date_stop if date_stop else ''" /></center>
</tr> </td>
</tbody> </tr>
</table> </tbody>
<table border="1" width="100%" cellpadding="0" bgcolor="#ededed" style="padding: 20px; background-color: #ededed; border-collapse:separate;"> </table>
<tbody> <table border="1" width="100%" cellpadding="0" bgcolor="#ededed" style="padding: 20px; background-color: #ededed; border-collapse:separate;">
<tr t-foreach="get_resource" t-as="resource"> <tbody>
<td><span t-esc="resource"/></td> <tr t-foreach="get_resource" t-as="resource">
<t t-foreach="get_data" t-as="data"> <td><span t-esc="resource"/></td>
<t t-if="data['resource_name']==resource"> <t t-foreach="get_data" t-as="data">
<td t-attf-style="background-color:{{data['bgcolor']}}!important;"> <t t-if="data['resource_name']==resource">
<b>Date :</b><span t-esc="data['day_start']"/><br/> <td t-attf-style="background-color:{{data['bgcolor']}}!important;">
<b>On behalf of :</b><span t-esc="data['client']"/><br/> <b>Date :</b><span t-esc="data['day_start']"/><br/>
</td> <b>On behalf of :</b><span t-esc="data['client']"/><br/>
</t> </td>
</t> </t>
</tr> </t>
</tbody> </tr>
</table> </tbody>
</div> </table>
</div> </div>
</t> </div>
</t> </t>
</template> </t>
</data> </template>
</data>
</odoo> </odoo>

View File

@ -18,32 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<odoo> <odoo>
<data> <data>
<record id="paperformat_euro_landscape"
model="report.paperformat"> <report id="action_report_report_admission_analysis"
<field name="name">European A4 Landscape</field> model="golem.resource.report.wizard"
<field name="default" eval="True" /> string="Reservations Report"
<field name="format">A4</field> report_type="qweb-pdf"
<field name="page_height">0</field> name="golem_resource_report.golem_reservation_report"
<field name="page_width">0</field> file="golem_resource_report.golem_reservation_report"
<field name="orientation">Landscape</field> menu="False" auto="False"
<field name="margin_top">10</field> paperformat="paperformat_euro_landscape" />
<field name="margin_bottom">23</field>
<field name="margin_left">7</field> </data>
<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> </odoo>

View File

@ -20,19 +20,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<data> <data>
<!-- Actions --> <!-- Actions -->
<record model="ir.actions.act_window" id="golem_resource_report_action"> <record model="ir.actions.act_window" id="golem_resource_report_action">
<field name="name">Resources Reports</field> <field name="name">Resources Reports</field>
<field name="res_model">golem.resource.report.wizard</field> <field name="res_model">golem.resource.report.wizard</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">form</field> <field name="view_mode">form</field>
<field name="view_id" ref="golem_resource_report_wizard_view_form" /> <field name="view_id" ref="golem_resource_report_wizard_view_form" />
<field name="context">{}</field> <field name="context">{}</field>
<field name="target">new</field> <field name="target">new</field>
</record> </record>
<!-- Menus --> <!-- Menus -->
<menuitem id="resource_report_menu" name="Report" parent="golem_resource.golem_resource_menu" <menuitem id="resource_report_menu" name="Report" parent="golem_resource.golem_resource_menu"
action="golem_resource_report_action" sequence="10" /> action="golem_resource_report_action" sequence="10" />
</data> </data>
</odoo> </odoo>

View File

@ -30,17 +30,17 @@ class GolemResourceReportWizard(models.TransientModel):
date_stop = fields.Datetime(required=True) date_stop = fields.Datetime(required=True)
@api.multi @api.multi
def print_report(self): def print_resource_report(self):
""" Print Report """ """ Print Report """
for record in self: self.ensure_one()
start_date = fields.Datetime.from_string(record.date_start) record = self[0]
stop_date = fields.Datetime.from_string(record.date_stop) start_date = fields.Datetime.from_string(record.date_start)
if start_date > stop_date: stop_date = fields.Datetime.from_string(record.date_stop)
raise ValidationError(_("Stop Date cannot be set before \ if start_date > stop_date:
Start Date.")) raise ValidationError(_('Stop Date cannot be set before Start Date.'))
else: else:
data = self.read( data = self.read(
['resource_ids', 'date_start', 'date_stop'])[0] ['resource_ids', 'date_start', 'date_stop'])[0]
return self.env['report'].get_action( return self.env['report'].get_action(
self, 'golem_resource_report.golem_reservation_report', self, 'golem_resource_report.golem_reservation_report',
data=data) data=data)

View File

@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
--> -->
<odoo> <odoo>
<data> <data>
<!-- Forms --> <!-- Forms -->
<record model="ir.ui.view" id="golem_resource_report_wizard_view_form"> <record model="ir.ui.view" id="golem_resource_report_wizard_view_form">
<field name="name">GOLEM resource Report Wizard Form</field> <field name="name">GOLEM resource Report Wizard Form</field>
@ -27,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group> <group>
<group> <group>
<field name="resource_ids" options="{'no_create' : True}"> <field name="resource_ids" options="{'no_create' : True}">
<tree > <tree>
<field name="name"/> <field name="name"/>
</tree> </tree>
</field> </field>
@ -38,12 +39,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</group> </group>
</group> </group>
<footer> <footer>
<button name="print_report" string="Print Report" type="object" <button name="print_resource_report" string="Print Report"
class="oe_highlight" /> type="object" class="oe_highlight" />
<button string="Close" class="oe_link" special="cancel" /> <button string="Close" class="oe_link" special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>
</record> </record>
</data> </data>
</odoo> </odoo>