[IMP] add prefixes. comes from PR #145

pull/189/head
jbeficent 2016-02-11 12:11:29 +01:00 committed by Stéphane Bidoul
parent 1c094b386d
commit d526bb94c6
15 changed files with 203 additions and 317 deletions

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
from . import models from . import models
from . import wizard from . import wizard

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
{ {
'name': 'MIS Builder', 'name': 'MIS Builder',

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
from . import mis_builder from . import mis_builder
from . import aep from . import aep

View File

@ -1,31 +1,12 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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 re import re
from collections import defaultdict from collections import defaultdict
from openerp.osv import expression from openerp.exceptions import Warning as UserError
from openerp.models import expression
from openerp.tools.safe_eval import safe_eval from openerp.tools.safe_eval import safe_eval
MODE_VARIATION = 'p' MODE_VARIATION = 'p'

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
def _sum(l): def _sum(l):

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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 datetime import datetime
import dateutil import dateutil
@ -76,7 +56,7 @@ class MisReportKpi(models.Model):
In addition to a name and description, it has an expression In addition to a name and description, it has an expression
to compute it based on queries defined in the MIS report. to compute it based on queries defined in the MIS report.
It also has various informations defining how to render it It also has various informations defining how to render it
(numeric or percentage or a string, a suffix, divider) and (numeric or percentage or a string, a prefix, a suffix, divider) and
how to render comparison of two values of the KPI. how to render comparison of two values of the KPI.
KPI's have a sequence and are ordered inside the MIS report. KPI's have a sequence and are ordered inside the MIS report.
""" """
@ -106,6 +86,7 @@ class MisReportKpi(models.Model):
string='Factor', string='Factor',
default='1') default='1')
dp = fields.Integer(string='Rounding', default=0) dp = fields.Integer(string='Rounding', default=0)
prefix = fields.Char(size=16, string='Prefix')
suffix = fields.Char(size=16, string='Suffix') suffix = fields.Char(size=16, string='Suffix')
compare_method = fields.Selection([('diff', _('Difference')), compare_method = fields.Selection([('diff', _('Difference')),
('pct', _('Percentage')), ('pct', _('Percentage')),
@ -165,10 +146,10 @@ class MisReportKpi(models.Model):
return '#N/A' return '#N/A'
elif self.type == 'num': elif self.type == 'num':
return self._render_num(lang_id, value, self.divider, return self._render_num(lang_id, value, self.divider,
self.dp, self.suffix) self.dp, self.prefix, self.suffix)
elif self.type == 'pct': elif self.type == 'pct':
return self._render_num(lang_id, value, 0.01, return self._render_num(lang_id, value, 0.01,
self.dp, '%') self.dp, '', '%')
else: else:
return unicode(value) return unicode(value)
@ -182,7 +163,7 @@ class MisReportKpi(models.Model):
return self._render_num( return self._render_num(
lang_id, lang_id,
value - base_value, value - base_value,
0.01, self.dp, _('pp'), sign='+') 0.01, self.dp, '', _('pp'), sign='+')
elif self.type == 'num': elif self.type == 'num':
if average_value: if average_value:
value = value / float(average_value) value = value / float(average_value)
@ -192,17 +173,17 @@ class MisReportKpi(models.Model):
return self._render_num( return self._render_num(
lang_id, lang_id,
value - base_value, value - base_value,
self.divider, self.dp, self.suffix, sign='+') self.divider, self.dp, self.prefix, self.suffix, sign='+')
elif self.compare_method == 'pct': elif self.compare_method == 'pct':
if round(base_value, self.dp) != 0: if round(base_value, self.dp) != 0:
return self._render_num( return self._render_num(
lang_id, lang_id,
(value - base_value) / abs(base_value), (value - base_value) / abs(base_value),
0.01, self.dp, '%', sign='+') 0.01, self.dp, '', '%', sign='+')
return '' return ''
def _render_num(self, lang_id, value, divider, def _render_num(self, lang_id, value, divider,
dp, suffix, sign='-'): dp, prefix, suffix, sign='-'):
divider_label = _get_selection_label( divider_label = _get_selection_label(
self._columns['divider'].selection, divider) self._columns['divider'].selection, divider)
if divider_label == '1': if divider_label == '1':
@ -213,8 +194,8 @@ class MisReportKpi(models.Model):
'%%%s.%df' % (sign, dp), '%%%s.%df' % (sign, dp),
value, value,
grouping=True) grouping=True)
value = u'%s\N{NO-BREAK SPACE}%s%s' % \ value = u'%s\N{NARROW NO-BREAK SPACE}%s\N{NO-BREAK SPACE}%s%s' % \
(value, divider_label, suffix or '') (prefix or '', value, divider_label, suffix or '')
value = value.replace('-', u'\N{NON-BREAKING HYPHEN}') value = value.replace('-', u'\N{NON-BREAKING HYPHEN}')
return value return value
@ -538,6 +519,7 @@ class MisReportInstancePeriod(models.Model):
'val_r': kpi_val_rendered, 'val_r': kpi_val_rendered,
'val_c': kpi_val_comment, 'val_c': kpi_val_comment,
'style': kpi_style, 'style': kpi_style,
'prefix': kpi.prefix,
'suffix': kpi.suffix, 'suffix': kpi.suffix,
'dp': kpi.dp, 'dp': kpi.dp,
'is_percentage': kpi.type == 'pct', 'is_percentage': kpi.type == 'pct',

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
try: try:
from . import mis_builder_xlsx from . import mis_builder_xlsx

View File

@ -0,0 +1,120 @@
# -*- coding: utf-8 -*-
# © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import xlwt
from openerp.report import report_sxw
from openerp.addons.report_xls.report_xls import report_xls
import logging
_logger = logging.getLogger(__name__)
class MisBuilderXlsParser(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(MisBuilderXlsParser, self).__init__(
cr, uid, name, context=context)
self.context = context
class MisBuilderXls(report_xls):
def __init__(self, name, table, rml=False, parser=False, header=True,
store=False):
super(MisBuilderXls, self).__init__(
name, table, rml, parser, header, store)
# Cell Styles
_xs = self.xls_styles
# header
rh_cell_format = _xs['bold'] + _xs['fill'] + \
_xs['borders_all'] + _xs['right']
self.rh_cell_style = xlwt.easyxf(rh_cell_format)
self.rh_cell_style_date = xlwt.easyxf(
rh_cell_format, num_format_str=report_xls.date_format)
# lines
self.mis_rh_cell_style = xlwt.easyxf(
_xs['borders_all'] + _xs['bold'] + _xs['fill'])
def generate_xls_report(self, _p, _xs, data, objects, wb):
report_name = objects[0].name
ws = wb.add_sheet(report_name[:31])
ws.panes_frozen = True
ws.remove_splits = True
ws.portrait = 0 # Landscape
ws.fit_width_to_pages = 1
row_pos = 0
# set print header/footer
ws.header_str = self.xls_headers['standard']
ws.footer_str = self.xls_footers['standard']
# Title
c_specs = [
('report_name', 1, 0, 'text', report_name),
]
row_data = self.xls_row_template(c_specs, ['report_name'])
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=xlwt.easyxf(_xs['xls_title']))
row_pos += 1
# get the computed result of the report
data = self.pool.get('mis.report.instance').compute(
self.cr, self.uid, objects[0].id)
# Column headers
header_name_list = ['']
col_specs_template = {'': {'header': [1, 30, 'text', ''],
'header_date': [1, 1, 'text', '']}}
for col in data['header'][0]['cols']:
col_specs_template[col['name']] = {'header': [1, 30, 'text',
col['name']],
'header_date': [1, 1, 'text',
col['date']]}
header_name_list.append(col['name'])
c_specs = map(
lambda x: self.render(x, col_specs_template, 'header'),
header_name_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rh_cell_style,
set_column_size=True)
c_specs = map(lambda x: self.render(
x, col_specs_template, 'header_date'), header_name_list)
row_data = self.xls_row_template(c_specs, [x[0] for x in c_specs])
row_pos = self.xls_write_row(
ws, row_pos, row_data, row_style=self.rh_cell_style_date)
ws.set_horz_split_pos(row_pos)
ws.set_vert_split_pos(1)
for line in data['content']:
col = 0
ws.write(row_pos, col, line['kpi_name'], self.mis_rh_cell_style)
for value in line['cols']:
col += 1
num_format_str = '#'
if value.get('dp'):
num_format_str += '.'
num_format_str += '0' * int(value['dp'])
if value.get('prefix'):
num_format_str = '"%s"' % value['prefix'] + num_format_str
if value.get('suffix'):
num_format_str += ' "%s"' % value['suffix']
kpi_cell_style = xlwt.easyxf(
_xs['borders_all'] + _xs['right'],
num_format_str=num_format_str)
if value.get('val'):
val = value['val']
if value.get('is_percentage'):
val = val / 0.01
ws.write(row_pos, col, val, kpi_cell_style)
else:
ws.write(row_pos, col, value['val_r'], kpi_cell_style)
row_pos += 1
MisBuilderXls('report.mis.report.instance.xls',
'mis.report.instance',
parser=MisBuilderXlsParser)

View File

@ -73,6 +73,8 @@ class MisBuilderXslx(ReportXlsx):
if value.get('dp'): if value.get('dp'):
num_format_str += '.' num_format_str += '.'
num_format_str += '0' * int(value['dp']) num_format_str += '0' * int(value['dp'])
if value.get('prefix'):
num_format_str = '"%s"' % value['prefix'] + num_format_str
if value.get('suffix'): if value.get('suffix'):
num_format_str = num_format_str + ' "%s"' % value['suffix'] num_format_str = num_format_str + ' "%s"' % value['suffix']
kpi_format = workbook.add_format({'num_format': num_format_str, kpi_format = workbook.add_format({'num_format': num_format_str,

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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 import logging

View File

@ -1,25 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
from . import test_mis_builder from . import test_mis_builder

View File

@ -1,26 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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 openerp.tests.common as common import openerp.tests.common as common
@ -64,11 +44,12 @@ class TestMisBuilder(common.TransactionCase):
'mis_report_instance_' 'mis_report_instance_'
'period_test'), 'period_test'),
'style': None, 'style': None,
'prefix': False,
'suffix': False, 'suffix': False,
'expr': 'len(test)', 'expr': 'len(test)',
'val_c': 'total_test = len(test)', 'val_c': 'total_test = len(test)',
'val': 0, 'val': 0,
'val_r': u'0\xa0', 'val_r': u'\u202f0\xa0',
'is_percentage': False, 'is_percentage': False,
'dp': 0, 'dp': 0,
'drilldown': False}] 'drilldown': False}]

View File

@ -49,6 +49,7 @@
<field name="type"/> <field name="type"/>
<field name="dp" attrs="{'invisible': [('type', '=', 'str')]}"/> <field name="dp" attrs="{'invisible': [('type', '=', 'str')]}"/>
<field name="divider" attrs="{'invisible': [('type', '=', 'str')]}"/> <field name="divider" attrs="{'invisible': [('type', '=', 'str')]}"/>
<field name="prefix"/>
<field name="suffix"/> <field name="suffix"/>
<field name="compare_method" attrs="{'invisible': [('type', '=', 'str')]}"/> <field name="compare_method" attrs="{'invisible': [('type', '=', 'str')]}"/>
<field name="default_css_style"/> <field name="default_css_style"/>

View File

@ -1,25 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
from . import mis_builder_dashboard from . import mis_builder_dashboard

View File

@ -1,87 +1,66 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## # © 2014-2015 ACSONE SA/NV (<http://acsone.eu>)
# # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
# 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/>.
#
##############################################################################
from openerp.osv import orm, fields from openerp import api, fields, models
from lxml import etree from lxml import etree
class AddMisReportInstanceDashboard(orm.TransientModel): class AddMisReportInstanceDashboard(models.TransientModel):
_name = "add.mis.report.instance.dashboard.wizard" _name = "add.mis.report.instance.dashboard.wizard"
_columns = {'name': fields.char('Name', size=32, required=True), name = fields.Char('Name', size=32, required=True)
'dashboard_id': fields.many2one(
'ir.actions.act_window',
string="Dashboard", required=True,
domain="[('res_model', '=', 'board.board')]"),
}
def default_get(self, cr, uid, fields, context=None): dashboard_id = fields.Many2one('ir.actions.act_window',
if context is None: string="Dashboard", required=True,
context = {} domain="[('res_model', '=', "
if context.get('active_id'): "'board.board')]")
@api.model
def default_get(self, fields):
res = {}
if self.env.context.get('active_id', False):
res = super(AddMisReportInstanceDashboard, self).default_get( res = super(AddMisReportInstanceDashboard, self).default_get(
cr, uid, fields, context=context) fields)
# get report instance name # get report instance name
res['name'] = self.pool['mis.report.instance'].read( res['name'] = self.env['mis.report.instance'].browse(
cr, uid, context['active_id'], ['name'])['name'] self.env.context['active_id']).name
return res return res
def action_add_to_dashboard(self, cr, uid, ids, context=None): @api.multi
if context is None: def action_add_to_dashboard(self):
context = {} assert self.env.context.get('active_id', False), \
assert 'active_id' in context, "active_id missing in context" "active_id missing in context"
wizard_data = self.browse(cr, uid, ids, context=context)[0]
# create the act_window corresponding to this report # create the act_window corresponding to this report
view_id = self.pool['ir.model.data'].get_object_reference( self.env.ref('mis_builder.mis_report_instance_result_view_form')
cr, uid, 'mis_builder', 'mis_report_instance_result_view_form')[1] view = self.env.ref(
report_result = self.pool['ir.actions.act_window'].create( 'mis_builder.mis_report_instance_result_view_form')
cr, uid, report_result = self.env['ir.actions.act_window'].create(
{'name': 'mis.report.instance.result.view.action.%d' {'name': 'mis.report.instance.result.view.action.%d'
% context['active_id'], % self.env.context['active_id'],
'res_model': 'mis.report.instance', 'res_model': 'mis.report.instance',
'res_id': context['active_id'], 'res_id': self.env.context['active_id'],
'target': 'current', 'target': 'current',
'view_mode': 'form', 'view_mode': 'form',
'view_id': view_id}) 'view_id': view.id})
# add this result in the selected dashboard # add this result in the selected dashboard
last_customization = self.pool['ir.ui.view.custom'].search( last_customization = self.env['ir.ui.view.custom'].search(
cr, uid, [('user_id', '=', self.env.uid),
[('user_id', '=', uid), ('ref_id', '=', self.dashboard_id.view_id.id)], limit=1)
('ref_id', '=', wizard_data.dashboard_id.view_id.id)], limit=1) arch = self.dashboard_id.view_id.arch
arch = wizard_data.dashboard_id.view_id.arch
if last_customization: if last_customization:
arch = self.pool['ir.ui.view.custom'].read( arch = self.env['ir.ui.view.custom'].browse(
cr, uid, last_customization[0], ['arch'])['arch'] last_customization[0].id).arch
new_arch = etree.fromstring(arch) new_arch = etree.fromstring(arch)
column = new_arch.xpath("//column")[0] column = new_arch.xpath("//column")[0]
column.append(etree.Element('action', {'context': str(context), column.append(etree.Element('action', {'context': str(
'name': str(report_result), self.env.context),
'string': wizard_data.name, 'name': str(report_result.id),
'string': self.name,
'view_mode': 'form'})) 'view_mode': 'form'}))
self.pool['ir.ui.view.custom'].create( self.env['ir.ui.view.custom'].create(
cr, uid, {'user_id': uid, {'user_id': self.env.uid,
'ref_id': wizard_data.dashboard_id.view_id.id, 'ref_id': self.dashboard_id.view_id.id,
'arch': etree.tostring(new_arch, pretty_print=True)}) 'arch': etree.tostring(new_arch, pretty_print=True)})
return {'type': 'ir.actions.act_window_close', } return {'type': 'ir.actions.act_window_close', }