[REF]GOLEM Resource Report : global refactoring
This commit is contained in:
parent
704e2809c2
commit
66a46d65f6
@ -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
|
||||
|
@ -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']
|
||||
|
40
golem_resource_report/data/golem_resource_report_data.xml
Normal file
40
golem_resource_report/data/golem_resource_report_data.xml
Normal 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>
|
@ -15,37 +15,15 @@
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
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"
|
||||
def get_client_color(partner_number):
|
||||
""" Get Client Color """
|
||||
colors = ['#FFFF5B', '#81EC54', '#47C8C8', '#FB5A66', '#E8E750',
|
||||
'#CF4ACF', '#9655D2', '#FFA15B', '#5F68D5', '#60E652']
|
||||
color = "#000000"
|
||||
@ -58,23 +36,31 @@ class GolemResevationReport(models.AbstractModel):
|
||||
color = "#" +hex(red)[2:]+hex(green)[2:]+hex(blue)[2:]
|
||||
return color
|
||||
|
||||
|
||||
class GolemResevationReport(models.AbstractModel):
|
||||
""" Golem Reservation Report """
|
||||
_name = 'report.golem_resource_report.golem_reservation_report'
|
||||
_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)
|
||||
|
@ -18,6 +18,7 @@ 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">
|
||||
@ -58,5 +59,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
</t>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
@ -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"
|
||||
|
||||
<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"
|
||||
/>
|
||||
menu="False" auto="False"
|
||||
paperformat="paperformat_euro_landscape" />
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
@ -30,14 +30,14 @@ 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:
|
||||
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."))
|
||||
raise ValidationError(_('Stop Date cannot be set before Start Date.'))
|
||||
else:
|
||||
data = self.read(
|
||||
['resource_ids', 'date_start', 'date_stop'])[0]
|
||||
|
@ -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>
|
||||
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user