[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
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#from . import models
from . import wizard
from . import reports
from . import reports, wizard

View File

@ -20,14 +20,15 @@
'name': 'GOLEM resources reports',
'summary': 'GOLEM resources reports',
'description': ''' GOLEM resources reports ''',
'version': '10.0.0.0.0',
'version': '10.0.0.1.0',
'category': 'GOLEM',
'author': 'Youssef El Ouahby, Fabien Bourgeois',
'license': 'AGPL-3',
'application': True,
'application': False,
'installable': True,
'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',
'wizard/golem_resource_report_wizard_views.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
# 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 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):
"Golem Reservation Report"
""" 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
_description = 'Golem Reservation Report'
def get_data(self, data):
"Get Resevation Data"
lst = []
""" Get Resevation Data """
res = []
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')
total_reservations = len(reservations)
resources = list(reservations.mapped('resource_id.name'))
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_colors[str(partner_id)] = get_client_color(partner_number)
partner_number += 1
res = {}
for reservation in reservations:
res = {
line = {
'name': reservation.name,
'resource_name': reservation.resource_id.name,
'client': reservation.partner_id.name,
@ -83,14 +69,15 @@ class GolemResevationReport(models.AbstractModel):
'day_start': reservation.day_start,
'bgcolor': partner_colors[str(reservation.partner_id.id)]
}
lst.append(res)
return lst
res.append(line)
return res, total_reservations, resources
@api.model
def render_html(self, docids, data=None):
"Render HTML"
""" Render HTML """
model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id'))
_data, total_reservations, resources = self.get_data(data)
docargs = {
'doc_ids': self.ids,
'doc_model': model,
@ -99,9 +86,9 @@ class GolemResevationReport(models.AbstractModel):
'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),
'get_total_reservation': total_reservations,
'get_data': _data,
'get_resource': resources
}
return self.env['report'] \
.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/>.
-->
<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>
<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>

View File

@ -18,32 +18,15 @@ 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>
<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>

View File

@ -20,19 +20,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<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>
<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>
</data>
</odoo>

View File

@ -30,17 +30,17 @@ class GolemResourceReportWizard(models.TransientModel):
date_stop = fields.Datetime(required=True)
@api.multi
def print_report(self):
def print_resource_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)
self.ensure_one()
record = self[0]
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)

View File

@ -18,6 +18,7 @@ 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>
@ -27,7 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group>
<group>
<field name="resource_ids" options="{'no_create' : True}">
<tree >
<tree>
<field name="name"/>
</tree>
</field>
@ -38,12 +39,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</group>
</group>
<footer>
<button name="print_report" string="Print Report" type="object"
class="oe_highlight" />
<button name="print_resource_report" string="Print Report"
type="object" class="oe_highlight" />
<button string="Close" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</odoo>