forked from Yaltik/golem
[REF][IMP]GOLEM Resource Report : huge refactoring of report model and data with representation per date, then, resource, then dates, then periods
This commit is contained in:
parent
66a46d65f6
commit
654d2de6b4
@ -20,7 +20,9 @@
|
||||
|
||||
import time
|
||||
from random import randint
|
||||
from odoo import models, api
|
||||
from odoo import models, fields, api
|
||||
|
||||
# FIXME: usage of Odoo fields will be needed for i18n awareness
|
||||
|
||||
def get_client_color(partner_number):
|
||||
""" Get Client Color """
|
||||
@ -44,13 +46,13 @@ class GolemResevationReport(models.AbstractModel):
|
||||
|
||||
def get_data(self, data):
|
||||
""" 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'))
|
||||
resources = {r.resource_id.id: r.resource_id.name for r in reservations}
|
||||
days = sorted(list(set(reservations.mapped('day_start'))))
|
||||
|
||||
partner_ids = reservations.mapped('partner_id.id')
|
||||
partner_colors = {}
|
||||
@ -59,36 +61,47 @@ class GolemResevationReport(models.AbstractModel):
|
||||
partner_colors[str(partner_id)] = get_client_color(partner_number)
|
||||
partner_number += 1
|
||||
|
||||
res = {} # List of multi-levels : group by resource, then, day_start
|
||||
for reservation in reservations:
|
||||
resource = reservation.resource_id.id
|
||||
day_start = reservation.day_start
|
||||
if not resource in res:
|
||||
res[resource] = {}
|
||||
if not day_start in res[resource]:
|
||||
res[resource][day_start] = []
|
||||
line = {
|
||||
'name': reservation.name,
|
||||
'resource_name': reservation.resource_id.name,
|
||||
'client': reservation.partner_id.name,
|
||||
'partner': 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)]
|
||||
'day_stop': fields.Datetime.from_string(reservation.date_stop).strftime('%Y-%m-%d'),
|
||||
'bgcolor': partner_colors[str(reservation.partner_id.id)],
|
||||
'note': reservation.note
|
||||
}
|
||||
res.append(line)
|
||||
return res, total_reservations, resources
|
||||
res[resource][day_start].append(line)
|
||||
return res, total_reservations, resources, days
|
||||
|
||||
@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'))
|
||||
_data, total_reservations, resources = self.get_data(data)
|
||||
_data, total_reservations, resources, days = self.get_data(data)
|
||||
docargs = {
|
||||
'doc_ids': self.ids,
|
||||
'doc_model': model,
|
||||
'docs': docs,
|
||||
'company': self.env.ref('base.main_company'),
|
||||
'time': time,
|
||||
'data': data,
|
||||
'date_start': data['date_start'],
|
||||
'date_stop': data['date_stop'],
|
||||
'get_total_reservation': total_reservations,
|
||||
'get_data': _data,
|
||||
'get_resource': resources
|
||||
'date_start': '%s 00:00:00' % data['date_start'],
|
||||
'date_stop': '%s 23:59:59' % data['date_stop'],
|
||||
'total_reservations': total_reservations,
|
||||
'datas': _data,
|
||||
'resources': resources,
|
||||
'days': days
|
||||
}
|
||||
return self.env['report'] \
|
||||
.render('golem_resource_report.golem_reservation_report', docargs)
|
||||
|
@ -24,32 +24,48 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<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>
|
||||
<h3 class="text-center">
|
||||
<span t-esc="company.name" /> : <span t-esc="total_reservations" /> reservations<br />
|
||||
<small>
|
||||
<strong>From Date: </strong>
|
||||
<span t-esc="time.strftime('%d/%m/%Y',time.strptime(date_start,'%Y-%m-%d %H:%M:%S'))"/>
|
||||
<strong>To Date:</strong>
|
||||
<span t-esc="time.strftime('%d/%m/%Y',time.strptime(date_stop,'%Y-%m-%d %H:%M:%S'))"/>
|
||||
</small>
|
||||
</h3>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<t t-foreach="days" t-as="day">
|
||||
<th class="text-center" t-esc="time.strftime('%A %d/%m',time.strptime(day,'%Y-%m-%d'))"/>
|
||||
</t>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table border="1" width="100%" cellpadding="0" bgcolor="#ededed" style="padding: 20px; background-color: #ededed; border-collapse:separate;">
|
||||
</thead>
|
||||
<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>
|
||||
<tr t-foreach="resources" t-as="resource_id">
|
||||
<td><span t-esc="resources[resource_id]" /></td>
|
||||
<t t-foreach="days" t-as="day">
|
||||
<td>
|
||||
<t t-if="datas.get(resource_id, {}).get(day)">
|
||||
<t t-set="reservations" t-value="datas[resource_id][day]" />
|
||||
<t t-foreach="reservations" t-as="resa">
|
||||
<div t-attf-style="background-color:{{resa['bgcolor']}}!important;border-top: 1px solid #333333;">
|
||||
<t t-if="resa['day_start']==resa['day_stop']">
|
||||
<span t-esc="time.strftime('%Hh%M',time.strptime(resa['date_start'],'%Y-%m-%d %H:%M:%S'))"/> -
|
||||
<span t-esc="time.strftime('%Hh%M',time.strptime(resa['date_stop'],'%Y-%m-%d %H:%M:%S'))"/>
|
||||
</t>
|
||||
<t t-else="">
|
||||
From <span t-esc="time.strftime('%d/%m %Hh%M',time.strptime(resa['date_start'],'%Y-%m-%d %H:%M:%S'))"/><br />
|
||||
To <span t-esc="time.strftime('%d/%m %Hh%M',time.strptime(resa['date_stop'],'%Y-%m-%d %H:%M:%S'))"/>
|
||||
</t>
|
||||
<p t-if="resa.get('note')" t-esc="resa['note']" />
|
||||
<br />
|
||||
<em>For <span t-esc="resa['partner']"/></em>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
</td>
|
||||
</t>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -26,17 +26,15 @@ class GolemResourceReportWizard(models.TransientModel):
|
||||
_name = "golem.resource.report.wizard"
|
||||
|
||||
resource_ids = fields.Many2many('golem.resource')
|
||||
date_start = fields.Datetime(required=True)
|
||||
date_stop = fields.Datetime(required=True)
|
||||
date_start = fields.Date(required=True)
|
||||
date_stop = fields.Date(required=True)
|
||||
|
||||
@api.multi
|
||||
def print_resource_report(self):
|
||||
""" Print Report """
|
||||
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:
|
||||
if record.date_start > record.date_stop:
|
||||
raise ValidationError(_('Stop Date cannot be set before Start Date.'))
|
||||
else:
|
||||
data = self.read(
|
||||
|
Loading…
Reference in New Issue
Block a user