Browse Source

[IMP] cherry pick commits in V8 from a809796 to 09d69b9 and adapt the code to v7

pull/90/head
jbeficent 9 years ago
committed by Stéphane Bidoul
parent
commit
2a0df08df9
  1. 4
      mis_builder/__openerp__.py
  2. 0
      mis_builder/migrations/7.0.0.2/pre-migration.py
  3. 165
      mis_builder/models/mis_builder.py
  4. 67
      mis_builder/report/report_mis_report_instance.py
  5. 55
      mis_builder/report/report_mis_report_instance.xml
  6. BIN
      mis_builder/static/src/img/icon.png

4
mis_builder/__openerp__.py

@ -29,14 +29,10 @@
'summary': """
Build 'Management Information System' Reports and Dashboards
""",
<<<<<<< HEAD
'description': """
""",
'author': 'ACSONE SA/NV',
=======
'author': 'ACSONE SA/NV,'
'Odoo Community Association (OCA)',
>>>>>>> 98a321c... [FIX] Add OCA as author
'website': 'http://acsone.eu',
'depends': [
'account',

0
mis_builder/migrations/8.0.0.2/pre-migration.py → mis_builder/migrations/7.0.0.2/pre-migration.py

165
mis_builder/models/mis_builder.py

@ -22,13 +22,9 @@
#
##############################################################################
<<<<<<< HEAD
from datetime import datetime, timedelta
from dateutil import parser
=======
import datetime
import dateutil
>>>>>>> 09d69b9... [IMP] mis_builder: improve eval context of query domain
from dateutil import parser
import logging
import re
import time
@ -61,18 +57,13 @@ def _get_selection_label(selection, value):
def _utc_midnight(d, tz_name, add_day=0):
<<<<<<< HEAD
d = datetime.strptime(d, tools.DEFAULT_SERVER_DATE_FORMAT)
=======
d = fields.Datetime.from_string(d) + datetime.timedelta(days=add_day)
>>>>>>> 09d69b9... [IMP] mis_builder: improve eval context of query domain
d = datetime.datetime.strptime(d, tools.DEFAULT_SERVER_DATE_FORMAT)
utc_tz = pytz.timezone('UTC')
if add_day:
d = d + timedelta(days=add_day)
d = d + datetime.timedelta(days=add_day)
context_tz = pytz.timezone(tz_name)
local_timestamp = context_tz.localize(d, is_dst=False)
return datetime.strftime(local_timestamp.astimezone(utc_tz),
tools.DEFAULT_SERVER_DATETIME_FORMAT)
return datetime.datetime.strftime(local_timestamp.astimezone(utc_tz))
def _python_var(var_str):
@ -83,9 +74,6 @@ def _is_valid_python_var(name):
return re.match("[_A-Za-z][_a-zA-Z0-9]*$", name)
<<<<<<< HEAD
class MisReportKpi(orm.Model):
=======
def _sum(l):
if not l:
return None
@ -110,8 +98,7 @@ def _max(l):
return max(l)
class MisReportKpi(models.Model):
>>>>>>> 4cd4a14... [FIX] mis_builder: do not crash on aggregate queries with no results
class MisReportKpi(orm.Model):
""" A KPI is an element (ie a line) of a MIS report.
In addition to a name and description, it has an expression
@ -402,7 +389,6 @@ class MisReportInstancePeriod(orm.Model):
are defined as an offset relative to a pivot date.
"""
<<<<<<< HEAD
def _get_dates(self, cr, uid, ids, field_names, arg, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
@ -410,17 +396,20 @@ class MisReportInstancePeriod(orm.Model):
for c in self.browse(cr, uid, ids, context=context):
period_ids = None
valid = True
date_from = False
date_to = False
d = parser.parse(c.report_instance_id.pivot_date)
if c.type == 'd':
date_from = d + timedelta(days=c.offset)
date_to = date_from + timedelta(days=c.duration - 1)
date_from = d + datetime.timedelta(days=c.offset)
date_to = date_from + datetime.timedelta(days=c.duration - 1)
date_from = date_from.strftime(
tools.DEFAULT_SERVER_DATE_FORMAT)
date_to = date_to.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
elif c.type == 'w':
date_from = d - timedelta(d.weekday())
date_from = date_from + timedelta(days=c.offset * 7)
date_to = date_from + timedelta(days=(7 * c.duration) - 1)
date_from = d - datetime.timedelta(d.weekday())
date_from = date_from + datetime.timedelta(days=c.offset * 7)
date_to = date_from + datetime.timedelta(
days=(7 * c.duration) - 1)
date_from = date_from.strftime(
tools.DEFAULT_SERVER_DATE_FORMAT)
date_to = date_to.strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
@ -428,41 +417,6 @@ class MisReportInstancePeriod(orm.Model):
period_obj = self.pool['account.period']
current_period_ids = period_obj.search(
cr, uid,
=======
@api.one
@api.depends('report_instance_id.pivot_date', 'type', 'offset', 'duration')
def _compute_dates(self):
self.date_from = False
self.date_to = False
self.period_from = False
self.period_to = False
self.valid = False
d = fields.Date.from_string(self.report_instance_id.pivot_date)
if self.type == 'd':
date_from = d + datetime.timedelta(days=self.offset)
date_to = date_from + \
datetime.timedelta(days=self.duration - 1)
self.date_from = fields.Date.to_string(date_from)
self.date_to = fields.Date.to_string(date_to)
self.valid = True
elif self.type == 'w':
date_from = d - datetime.timedelta(d.weekday())
date_from = date_from + datetime.timedelta(days=self.offset * 7)
date_to = date_from + \
datetime.timedelta(days=(7 * self.duration) - 1)
self.date_from = fields.Date.to_string(date_from)
self.date_to = fields.Date.to_string(date_to)
self.valid = True
elif self.type == 'fp':
current_periods = self.env['account.period'].search(
[('special', '=', False),
('date_start', '<=', d),
('date_stop', '>=', d),
('company_id', '=',
self.report_instance_id.company_id.id)])
if current_periods:
all_periods = self.env['account.period'].search(
>>>>>>> 09d69b9... [IMP] mis_builder: improve eval context of query domain
[('special', '=', False),
('date_start', '<=', d),
('date_stop', '>=', d),
@ -589,48 +543,42 @@ class MisReportInstancePeriod(orm.Model):
def _fetch_queries(self, cr, uid, c, context):
res = {}
<<<<<<< HEAD
report = c.report_instance_id.report_id
query_obj = self.pool['mis.report.query']
for query in report.query_ids:
obj = self.pool[query.model_id.model]
domain = query.domain and safe_eval(query.domain) or []
=======
for query in self.report_instance_id.report_id.query_ids:
model = self.env[query.model_id.model]
<<<<<<< HEAD
domain = query.domain and safe_eval(
query.domain,
{'uid': self._uid, 'context': self._context}) or []
>>>>>>> 4bc6080... Add ability to use ('user_id', '=', uid) in a domain
=======
eval_context = {
'env': self.env,
'time': time,
'datetime': datetime,
'dateutil': dateutil,
# deprecated
'uid': self.env.uid,
'context': self.env.context,
'uid': uid,
'context': context,
}
if not c.date_from or not c.date_to:
raise orm.except_orm(_('Error!'),
_('Please define From and To dates for '
'period %s.') % c.name)
domain = query.domain and \
safe_eval(query.domain, eval_context) or []
>>>>>>> 09d69b9... [IMP] mis_builder: improve eval context of query domain
domain.extend(query_obj._get_additional_filter(cr, uid,
query.id,
context=context))
if query.date_field.ttype == 'date':
domain.extend([(query.date_field.name, '>=', c.date_from),
(query.date_field.name, '<=', c.date_to)])
else:
tz = context.get('tz', False) or 'UTC'
datetime_from = _utc_midnight(
c.date_from, context.get('tz', 'UTC'))
c.date_from, tz)
datetime_to = _utc_midnight(
c.date_to, context.get('tz', 'UTC'), add_day=1)
c.date_to, tz, add_day=1)
domain.extend([(query.date_field.name, '>=', datetime_from),
(query.date_field.name, '<', datetime_to)])
<<<<<<< HEAD
if obj._columns.get('company_id', False):
domain.extend(['|', ('company_id', '=', False),
('company_id', '=', c.company_id.id)])
=======
>>>>>>> 57a9bbb... [FIX] mis_builder: do not arbitrarily filter on company in queries
field_names = [f.name for f in query.field_ids]
if not query.aggregate:
obj_ids = obj.search(cr, uid, domain, context=context)
@ -651,11 +599,11 @@ class MisReportInstancePeriod(orm.Model):
cr, uid, obj_ids, field_names, context=context)
s = AutoStruct(count=len(data))
if query.aggregate == 'min':
agg = _min
agg = min
elif query.aggregate == 'max':
agg = _max
agg = max
elif query.aggregate == 'avg':
agg = _avg
agg = lambda l: sum(l) / float(len(l))
for field_name in field_names:
setattr(s, field_name,
agg([d[field_name] for d in data]))
@ -834,57 +782,11 @@ class MisReportInstance(orm.Model):
context=context)
return res
<<<<<<< HEAD
def preview(self, cr, uid, ids, context=None):
assert len(ids) == 1
view_id = self.pool['ir.model.data'].get_object_reference(
cr, uid, 'mis_builder',
'mis_report_instance_result_view_form')[1]
=======
name = fields.Char(required=True,
string='Name', translate=True)
description = fields.Char(required=False,
string='Description', translate=True)
date = fields.Date(string='Base date',
help='Report base date '
'(leave empty to use current date)')
pivot_date = fields.Date(compute='_compute_pivot_date',
string="Pivot date")
report_id = fields.Many2one('mis.report',
required=True,
string='Report')
period_ids = fields.One2many('mis.report.instance.period',
'report_instance_id',
required=True,
string='Periods')
target_move = fields.Selection([('posted', 'All Posted Entries'),
('all', 'All Entries')],
string='Target Moves',
required=True,
default='posted')
company_id = fields.Many2one(comodel_name='res.company',
string='Company',
readonly=True,
related='root_account.company_id',
store=True)
root_account = fields.Many2one(comodel_name='account.account',
domain='[("parent_id", "=", False)]',
string="Account chart",
required=True)
landscape_pdf = fields.Boolean(string='Landscape PDF')
def _format_date(self, lang_id, date):
# format date following user language
date_format = self.env['res.lang'].browse(lang_id).date_format
return datetime.datetime.strftime(
fields.Date.from_string(date), date_format)
@api.multi
def preview(self):
assert len(self) == 1
view_id = self.env.ref('mis_builder.'
'mis_report_instance_result_view_form')
>>>>>>> 09d69b9... [IMP] mis_builder: improve eval context of query domain
return {
'type': 'ir.actions.act_window',
'res_model': 'mis.report.instance',
@ -899,10 +801,9 @@ class MisReportInstance(orm.Model):
# format date following user language
tformat = self.pool['res.lang'].read(
cr, uid, lang_id, ['date_format'])[0]['date_format']
return datetime.strftime(datetime.strptime(
date,
tools.DEFAULT_SERVER_DATE_FORMAT),
tformat)
date = datetime.datetime.strptime(date,
tools.DEFAULT_SERVER_DATE_FORMAT)
return date.strftime(tformat)
def compute(self, cr, uid, _id, context=None):
assert isinstance(_id, (int, long))

67
mis_builder/report/report_mis_report_instance.py

@ -1,67 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# mis_builder module for Odoo, Management Information System Builder
# Copyright (C) 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
#
# This file is a part of mis_builder
#
# mis_builder is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License v3 or later
# as published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# mis_builder 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 v3 or later for more details.
#
# You should have received a copy of the GNU Affero General Public License
# v3 or later along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logging
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"
@api.v7
def get_pdf(self, cr, uid, ids, report_name, html=None, data=None,
context=None):
if ids:
report = self._get_report_from_name(cr, uid, report_name)
obj = self.pool[report.model].browse(cr, uid, ids,
context=context)[0]
context = context.copy()
if hasattr(obj, 'landscape_pdf') and obj.landscape_pdf:
context.update({'landscape': True})
return super(Report, self).get_pdf(cr, uid, ids, report_name,
html=html, data=data,
context=context)

55
mis_builder/report/report_mis_report_instance.xml

@ -1,55 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="report_mis_report_instance">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<div class="page">
<h2 t-field="o.name"></h2>
<table class="table table-condensed">
<thead>
<tr>
<t t-foreach="docs_computed[o.id]['header']" t-as="h">
<th>
<div>
<t t-esc="h_value['kpi_name']"/>
</div>
</th>
<th t-foreach="h_value['cols']" t-as="col" class="text-center">
<div>
<t t-esc="col['name']"/>
</div>
<div>
<t t-esc="col['date']"/>
</div>
</th>
</t>
</tr>
</thead>
<tbody>
<tr t-foreach="docs_computed[o.id]['content']" t-as="c">
<td t-att-style="c_value['default_style']">
<div class="text-left">
<t t-esc="c_value['kpi_name']"/>
</div>
</td>
<t t-foreach="c_value['cols']" t-as="value">
<td t-att-style="c_value['default_style']">
<div t-att-style="value_value.get('style')" class="text-right">
<t t-esc="value_value['val_r']"/>
</div>
</td>
</t>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
</template>
</data>
</openerp>

BIN
mis_builder/static/src/img/icon.png

Before

Width: 64  |  Height: 64  |  Size: 3.4 KiB

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

Loading…
Cancel
Save