Browse Source

[IMP] Some improvements

* Refactoring _get_account_vars_in_report
* Use account_partial_balance instead of call __compute directly
pull/86/head
Adrien Peiffer (ACSONE) 10 years ago
committed by Stéphane Bidoul
parent
commit
1be717cd68
  1. 3
      mis_builder/__openerp__.py
  2. 1
      mis_builder/models/__init__.py
  3. 33
      mis_builder/models/account_account.py
  4. 74
      mis_builder/models/mis_builder.py

3
mis_builder/__openerp__.py

@ -31,7 +31,8 @@
""",
'author': 'ACSONE SA/NV',
'website': 'http://acsone.eu',
'depends': ['account'],
'depends': ['account',
'account_partial_balance'], # OCA/AFT
'data': [
'wizard/mis_builder_dashboard.xml',
'views/mis_builder.xml',

1
mis_builder/models/__init__.py

@ -23,4 +23,3 @@
##############################################################################
from . import mis_builder
from . import account_account

33
mis_builder/models/account_account.py

@ -1,33 +0,0 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# 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/>.
#
##############################################################################
from openerp.osv import orm
class account_account(orm.Model):
_inherit = 'account.account'
def _compute(self, cr, uid, ids, field_names, arg=None, context=None,
query='', query_params=()):
return self.__compute(cr, uid, ids, field_names, arg=arg,
context=context, query=query,
query_params=query_params)

74
mis_builder/models/mis_builder.py

@ -107,11 +107,6 @@ def _get_account_code(account_var):
return res[0]
# TODO : To review
def _get_account_vars_in_expr(expr, res_vars, is_solde=False, is_initial=False):
pass
# TODO : Not use here, Check in upstream
# def _get_vars_in_expr(expr, varnames=None):
# if not varnames:
@ -123,36 +118,43 @@ def _get_account_vars_in_expr(expr, res_vars, is_solde=False, is_initial=False):
def _get_eval_expression(expr, domain_mapping):
domain_list = []
for function in FUNCTION_LIST:
domain_list.extend(re.findall(r'\b%s[%s]?_\w+(\[.+?\])' % (function, PARAMETERS_STR), expr))
domain_list.extend(re.findall(r'\b%s[%s]?_\w+(\[.+?\])' %
(function, PARAMETERS_STR), expr))
for domain in domain_list:
expr = expr.replace(domain, domain_mapping[domain])
return expr
# TODO : To review
def _get_account_vars_in_expr(expr, res_vars, domain_mapping, is_solde=False,
is_initial=False):
for function in FUNCTION_LIST:
prefix = _get_prefix(function, is_solde=is_solde,
is_initial=is_initial)
find_res = re.findall(r'\b%s\w+(?:\[.+?\])?' % prefix, expr)
for item in find_res:
match = re.match(r'\b(%s)(\w+)(\[.+?\])?' % prefix, item)
var_tuple = match.groups()
domain = "" if var_tuple[2] is None else var_tuple[2]
key = ""
if domain != "":
if domain not in domain_mapping:
key = 'd' + str(len(res_vars.keys()))
domain_mapping[domain] = key
else:
key = domain_mapping[domain]
key_domain = (key, domain)
if not res_vars.get(key_domain, False):
res_vars[key_domain] = set()
res_vars[key_domain].add(var_tuple[1])
def _get_account_vars_in_report(report, domain_mapping, is_solde=False,
is_initial=False):
res_vars = {}
domain_count = 0
for kpi in report.kpi_ids:
for function in FUNCTION_LIST:
prefix = _get_prefix(function, is_solde=is_solde, is_initial=is_initial)
find_res = re.findall(r'\b%s\w+(?:\[.+?\])?' % prefix, kpi.expression)
for item in find_res:
match = re.match(r'\b(%s)(\w+)(\[.+?\])?' % prefix, item)
var_tuple = match.groups()
domain = "" if var_tuple[2] is None else var_tuple[2]
key = ""
if domain != "":
if domain not in domain_mapping:
key = 'd' + str(domain_count)
domain_count += 1
domain_mapping[domain] = key
else:
key = domain_mapping[domain]
key_domain = (key, domain)
if not res_vars.get(key_domain, False):
res_vars[key_domain] = set()
res_vars[key_domain].add(var_tuple[1])
_get_account_vars_in_expr(kpi.expression, res_vars, domain_mapping,
is_solde, is_initial)
return res_vars
@ -570,7 +572,7 @@ class mis_report_instance_period(orm.Model):
'Period name should be unique by report'),
]
# TODO : To review
# TODO : To adapt to work with expression domain
def compute_domain(self, cr, uid, ids, account_, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
@ -637,22 +639,26 @@ class mis_report_instance_period(orm.Model):
where_clause_params = ()
if domain != '':
domain_eval = safe_eval(domain)
query = account_move_line_obj._where_calc(cr, uid, domain_eval, context=context)
from_clause, where_clause, where_clause_params = query.get_sql()
query = account_move_line_obj._where_calc(cr, uid, domain_eval,
context=context)
from_clause, where_clause, where_clause_params = \
query.get_sql()
assert from_clause == '"account_move_line"'
where_clause = where_clause.replace("account_move_line", "l")
where_clause_params = tuple(where_clause_params)
account_datas = self.pool['account.account']._compute(cr, uid, account_ids,['balance', 'credit', 'debit'], arg=None, context=context, query=where_clause, query_params=where_clause_params)
for id, fields in account_datas.iteritems():
account_data = account_obj.read(cr, uid, [id], ['code'],
context=context)[0]
context.update({'query': where_clause,
'query_params': where_clause_params})
account_datas = account_obj\
.read(cr, uid, account_ids,
['code', 'balance', 'credit', 'debit'], context=context)
for account_data in account_datas:
for item in FUNCTION:
var = _python_account_var(item[1], account_data['code'],
is_solde=is_solde,
is_initial=is_initial)
var = var + key
assert key not in balances
balances[var] = fields[item[0]]
balances[var] = account_data[item[0]]
return balances

Loading…
Cancel
Save