Browse Source

[WIP] mis_builder refactoring: refactor and improve PDF report

pull/189/head
Stéphane Bidoul 8 years ago
parent
commit
c50af0b5a4
  1. 20
      mis_builder/report/report_mis_report_instance.py
  2. 99
      mis_builder/report/report_mis_report_instance.xml
  3. 62
      mis_builder/static/src/css/report.css

20
mis_builder/report/report_mis_report_instance.py

@ -9,26 +9,6 @@ from openerp import api, models
_logger = logging.getLogger(__name__)
class ReportMisReportInstance(models.AbstractModel):
_name = 'report.mis_builder.report_mis_report_instance'
@api.multi
def render_html(self, data=None):
docs = self.env['mis.report.instance'].browse(self._ids)
docs_computed = {}
for doc in docs:
docs_computed[doc.id] = doc.compute()
docargs = {
'doc_ids': self._ids,
'doc_model': 'mis.report.instance',
'docs': docs,
'docs_computed': docs_computed,
}
return self.env['report'].\
render('mis_builder.report_mis_report_instance', docargs)
class Report(models.Model):
_inherit = "report"

99
mis_builder/report/report_mis_report_instance.xml

@ -4,72 +4,69 @@
<template id="report_mis_report_instance">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<t t-set="matrix" t-value="o._compute_matrix()"/>
<div class="page">
<h2><span t-field="o.name" /> - <span t-field="o.company_id.name" /></h2>
<div class="mis_table">
<div class="mis_thead">
<t t-foreach="docs_computed[o.id]['header']" t-as="h">
<div class="mis_row labels">
<div class="mis_cell">
<div>
<t t-esc="h_value['kpi_name']"/>
</div>
<div class="mis_row">
<div class="mis_cell mis_collabel"></div>
<t t-foreach="matrix.iter_cols()" t-as="col">
<div class="mis_cell mis_collabel">
<t t-esc="col.description"/>
<t t-if="col.comment">
<br/>
<t t-esc="col.comment"/>
</t>
</div>
<t t-foreach="h_value['cols']" t-as="col">
<div class="mis_cell amount" t-att-colspan="col.get('colspan', 1)">
<div>
<t t-esc="col['name']"/>
</div>
<t t-if="col.get('date')">
<div>
<t t-esc="col['date']"/>
</div>
</t>
</div>
</t>
</div>
</t>
<!-- add empty cells because we have no colspan with css tables -->
<t t-foreach="list(col.iter_subcols())[1:]" t-as="subcol">
<div class="mis_cell mis_collabel"></div>
</t>
</t>
</div>
<div class="mis_row">
<div class="mis_cell mis_collabel"></div>
<t t-foreach="matrix.iter_subcols()" t-as="subcol">
<div class="mis_cell mis_collabel">
<t t-esc="subcol.description"/>
<t t-if="subcol.comment">
<br/>
<t t-esc="subcol.comment"/>
</t>
</div>
</t>
</div>
</div>
<div class="mis_tbody">
<div t-foreach="docs_computed[o.id]['content']" t-as="c" class="mis_row lines">
<div t-att-style="c_value['default_style']" class="mis_cell">
<div class="text-left">
<t t-esc="c_value['kpi_name']"/>
</div>
<div t-foreach="matrix.iter_rows()" t-as="row" class="mis_row">
<div t-att-style="row.style and row.style.to_css_style() or ''" class="mis_cell mis_rowlabel">
<t t-esc="row.description"/>
<t t-if="row.comment">
<br/>
<t t-esc="row.comment"/>
</t>
</div>
<t t-foreach="c_value['cols']" t-as="value">
<div t-att-style="c_value['default_style']" class="mis_cell">
<div t-att-style="value_value.get('style')" class="text-right">
<t t-esc="value_value['val_r']"/>
</div>
</div>
<t t-foreach="row.iter_cells()" t-as="cell">
<t t-if="cell">
<div t-att-style="cell.row.style and cell.row.style.to_css_style() or ''" class="mis_cell mis_amount">
<div t-att-style="cell.style and cell.style.to_css_style() or ''">
<t t-esc="cell.val_rendered"/>
</div>
</div>
</t>
<t t-if="not cell">
<div class="mis_cell mis_amount"></div>
</t>
</t>
</div>
</div>
</div>
</div>
</t>
<div class="footer">
<div style="border-top: 1px solid black;">
<div class="col-xs-3">
<span t-esc="context_timestamp(datetime.datetime.now()).strftime('%Y-%m-%d %H:%M')"/>
</div>
<div class="col-xs-2 col-xs-offset-2 text-center">
</div>
<div class="col-xs-2 col-xs-offset-3 text-right">
<ul class="list-inline">
Page
<li><span class="page"/></li>
<li>of</li>
<li><span class="topage"/></li>
</ul>
</div>
</div>
</div>
</t>
</t>
</template>

62
mis_builder/static/src/css/report.css

@ -1,47 +1,45 @@
.mis_table {
display: table ;
display: table;
width: 100%;
table-layout: fixed ;
table-layout: fixed;
}
.mis_row {
display: table-row ;
display: table-row;
page-break-inside: avoid;
}
.mis_cell {
display: table-cell ;
display: table-cell;
page-break-inside: avoid;
}
.mis_thead {
display: table-header-group ;
display: table-header-group;
}
.mis_tbody {
display: table-row-group ;
}
.mis_row.labels {
background-color:#F0F0F0 ;
display: table-row-group;
}
.mis_table, .mis_table .mis_row {
border-left:0px;
border-right:0px;
text-align:left;
padding-right:3px;
padding-left:3px;
padding-top:2px;
padding-bottom:2px;
border-collapse:collapse;
}
.mis_table .mis_row.labels, .mis_table .mis_row.lines {
border-color:grey ;
border-bottom:1px solid lightGrey ;
}
.mis_table .mis_cell {
word-wrap: break-word;
}
.mis_cell.amount {
word-wrap:normal;
text-align:right;
}
.mis_table .mis_cell{
padding-left: 5px;
/* border-right:1px solid lightGrey; uncomment to active column lines */
border-left: 0px;
border-right: 0px;
text-align: left;
padding-right: 3px;
padding-left: 3px;
padding-top: 2px;
padding-bottom: 2px;
border-collapse: collapse;
}
.mis_table .mis_row {
border-color: grey;
border-bottom: 1px solid lightGrey;
}
.mis_table .mis_cell.mis_collabel {
font-weight: bold;
background-color: #F0F0F0;
text-align: center;
}
.mis_table .mis_cell.mis_rowlabel {
text-align: left;
/*white-space: nowrap;*/
}
.mis_table .mis_cell.mis_amount {
text-align: right;
}
Loading…
Cancel
Save