[IMP] mis_builder: refactor to compute period only for modes actually used
parent
0ede82e6da
commit
55b31f9cbd
|
@ -157,17 +157,15 @@ class AccountingExpressionProcessor(object):
|
||||||
def get_aml_domain_for_expr(self, expr):
|
def get_aml_domain_for_expr(self, expr):
|
||||||
""" Get a domain on account.move.line for an expression.
|
""" Get a domain on account.move.line for an expression.
|
||||||
|
|
||||||
Only accounting expression in mode 'p' and 'e' are considered.
|
|
||||||
|
|
||||||
Prerequisite: done_parsing() must have been invoked.
|
Prerequisite: done_parsing() must have been invoked.
|
||||||
|
|
||||||
Returns a domain that can be used to search on account.move.line.
|
Returns a domain that can be used to search on account.move.line.
|
||||||
|
To be meaningful, this domain must be extended with a domain
|
||||||
|
obtained from get_aml_domain_for_dates()
|
||||||
"""
|
"""
|
||||||
aml_domains = []
|
aml_domains = []
|
||||||
for mo in self.ACC_RE.finditer(expr):
|
for mo in self.ACC_RE.finditer(expr):
|
||||||
field, mode, account_codes, domain = self._parse_match_object(mo)
|
field, _, account_codes, domain = self._parse_match_object(mo)
|
||||||
if mode == MODE_INITIAL:
|
|
||||||
continue
|
|
||||||
aml_domain = list(domain)
|
aml_domain = list(domain)
|
||||||
if account_codes:
|
if account_codes:
|
||||||
account_ids = set()
|
account_ids = set()
|
||||||
|
@ -181,11 +179,6 @@ class AccountingExpressionProcessor(object):
|
||||||
aml_domains.append(expression.normalize_domain(aml_domain))
|
aml_domains.append(expression.normalize_domain(aml_domain))
|
||||||
return expression.OR(aml_domains)
|
return expression.OR(aml_domains)
|
||||||
|
|
||||||
def get_aml_domain_for_dates(self, date_start, date_end, mode):
|
|
||||||
if mode != MODE_VARIATION:
|
|
||||||
raise RuntimeError("") # TODO
|
|
||||||
return [('date', '>=', date_start), ('date', '<=', date_end)]
|
|
||||||
|
|
||||||
def _period_has_moves(self, period):
|
def _period_has_moves(self, period):
|
||||||
move_model = self.env['account.move']
|
move_model = self.env['account.move']
|
||||||
return bool(move_model.search([('period_id', '=', period.id)],
|
return bool(move_model.search([('period_id', '=', period.id)],
|
||||||
|
@ -277,27 +270,36 @@ class AccountingExpressionProcessor(object):
|
||||||
period_from, period_to, company_id))
|
period_from, period_to, company_id))
|
||||||
return period_ids
|
return period_ids
|
||||||
|
|
||||||
def get_aml_domain_for_periods(self, period_from, period_to, mode):
|
def get_aml_domain_for_dates(self, date_from, date_to,
|
||||||
|
period_from, period_to,
|
||||||
|
mode,
|
||||||
|
target_move):
|
||||||
|
if period_from and period_to:
|
||||||
period_ids = self._get_period_ids_for_mode(
|
period_ids = self._get_period_ids_for_mode(
|
||||||
period_from, period_to, mode)
|
period_from, period_to, mode)
|
||||||
return [('period_id', 'in', period_ids)]
|
domain = [('period_id', 'in', period_ids)]
|
||||||
|
else:
|
||||||
|
domain = [('date', '>=', date_from), ('date', '<=', date_to)]
|
||||||
|
if target_move == 'posted':
|
||||||
|
domain.append(('move_id.state', '=', 'posted'))
|
||||||
|
return domain
|
||||||
|
|
||||||
def do_queries(self, period_domain, period_domain_i, period_domain_e):
|
def do_queries(self, date_from, date_to, period_from, period_to,
|
||||||
|
target_move):
|
||||||
aml_model = self.env['account.move.line']
|
aml_model = self.env['account.move.line']
|
||||||
# {(domain, mode): {account_id: (debit, credit)}}
|
# {(domain, mode): {account_id: (debit, credit)}}
|
||||||
self._data = defaultdict(dict)
|
self._data = defaultdict(dict)
|
||||||
# fetch sum of debit/credit, grouped by account_id
|
domain_by_mode = {}
|
||||||
for key in self._map_account_ids:
|
for key in self._map_account_ids:
|
||||||
domain, mode = key
|
domain, mode = key
|
||||||
if mode == MODE_VARIATION:
|
if mode not in domain_by_mode:
|
||||||
domain = list(domain) + period_domain
|
domain_by_mode[mode] = \
|
||||||
elif mode == MODE_INITIAL:
|
self.get_aml_domain_for_dates(date_from, date_to,
|
||||||
domain = list(domain) + period_domain_i
|
period_from, period_to,
|
||||||
elif mode == MODE_END:
|
mode, target_move)
|
||||||
domain = list(domain) + period_domain_e
|
domain = list(domain) + domain_by_mode[mode]
|
||||||
else:
|
|
||||||
raise RuntimeError("unexpected mode %s" % (mode,))
|
|
||||||
domain.append(('account_id', 'in', self._map_account_ids[key]))
|
domain.append(('account_id', 'in', self._map_account_ids[key]))
|
||||||
|
# fetch sum of debit/credit, grouped by account_id
|
||||||
accs = aml_model.read_group(domain,
|
accs = aml_model.read_group(domain,
|
||||||
['debit', 'credit', 'account_id'],
|
['debit', 'credit', 'account_id'],
|
||||||
['account_id'])
|
['account_id'])
|
||||||
|
|
|
@ -37,9 +37,6 @@ from openerp.tools.safe_eval import safe_eval
|
||||||
from openerp.tools.translate import _
|
from openerp.tools.translate import _
|
||||||
|
|
||||||
from .aep import AccountingExpressionProcessor
|
from .aep import AccountingExpressionProcessor
|
||||||
from .aep import MODE_VARIATION
|
|
||||||
from .aep import MODE_END
|
|
||||||
from .aep import MODE_INITIAL
|
|
||||||
|
|
||||||
|
|
||||||
class AutoStruct(object):
|
class AutoStruct(object):
|
||||||
|
@ -379,7 +376,6 @@ class mis_report_instance_period(orm.Model):
|
||||||
all_period_ids = period_obj.search(
|
all_period_ids = period_obj.search(
|
||||||
cr, uid,
|
cr, uid,
|
||||||
[('special', '=', False),
|
[('special', '=', False),
|
||||||
'|', ('company_id', '=', False),
|
|
||||||
('company_id', '=', c.company_id.id)],
|
('company_id', '=', c.company_id.id)],
|
||||||
order='date_start',
|
order='date_start',
|
||||||
context=context)
|
context=context)
|
||||||
|
@ -388,7 +384,6 @@ class mis_report_instance_period(orm.Model):
|
||||||
[('special', '=', False),
|
[('special', '=', False),
|
||||||
('date_start', '<=', d),
|
('date_start', '<=', d),
|
||||||
('date_stop', '>=', d),
|
('date_stop', '>=', d),
|
||||||
'|', ('company_id', '=', False),
|
|
||||||
('company_id', '=', c.company_id.id)],
|
('company_id', '=', c.company_id.id)],
|
||||||
context=context)
|
context=context)
|
||||||
if not current_period_ids:
|
if not current_period_ids:
|
||||||
|
@ -527,26 +522,6 @@ class mis_report_instance_period(orm.Model):
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def compute_period_domain(self, cr, uid, period_report, aep, mode,
|
|
||||||
context=None):
|
|
||||||
domain = []
|
|
||||||
target_move = period_report.report_instance_id.target_move
|
|
||||||
if target_move == 'posted':
|
|
||||||
domain.append(('move_id.state', '=', target_move))
|
|
||||||
if not period_report.period_from.id or not period_report.period_to.id:
|
|
||||||
aml_domain = aep\
|
|
||||||
.get_aml_domain_for_periods(period_report.date_from,
|
|
||||||
period_report.date_to,
|
|
||||||
mode)
|
|
||||||
domain.extend(aml_domain)
|
|
||||||
elif period_report.period_from.id and period_report.period_to.id:
|
|
||||||
aml_domain = aep\
|
|
||||||
.get_aml_domain_for_periods(period_report.period_from,
|
|
||||||
period_report.period_to,
|
|
||||||
mode)
|
|
||||||
domain.extend(aml_domain)
|
|
||||||
return domain
|
|
||||||
|
|
||||||
def _fetch_queries(self, cr, uid, c, context):
|
def _fetch_queries(self, cr, uid, c, context):
|
||||||
res = {}
|
res = {}
|
||||||
report = c.report_instance_id.report_id
|
report = c.report_instance_id.report_id
|
||||||
|
@ -589,16 +564,13 @@ class mis_report_instance_period(orm.Model):
|
||||||
'len': len,
|
'len': len,
|
||||||
'avg': lambda l: sum(l) / float(len(l)),
|
'avg': lambda l: sum(l) / float(len(l)),
|
||||||
}
|
}
|
||||||
domain_p = self.compute_period_domain(cr, uid, c, aep, MODE_VARIATION,
|
|
||||||
context=context)
|
|
||||||
domain_e = self.compute_period_domain(cr, uid, c, aep, MODE_END,
|
|
||||||
context=context)
|
|
||||||
domain_i = self.compute_period_domain(cr, uid, c, aep, MODE_INITIAL,
|
|
||||||
context=context)
|
|
||||||
aep.do_queries(domain_p, domain_i, domain_e)
|
|
||||||
localdict.update(self._fetch_queries(cr, uid, c,
|
localdict.update(self._fetch_queries(cr, uid, c,
|
||||||
context=context))
|
context=context))
|
||||||
|
|
||||||
|
aep.do_queries(c.date_from, c.date_to,
|
||||||
|
c.period_from, c.period_to,
|
||||||
|
c.report_instance_id.target_move)
|
||||||
|
|
||||||
compute_queue = c.report_instance_id.report_id.kpi_ids
|
compute_queue = c.report_instance_id.report_id.kpi_ids
|
||||||
recompute_queue = []
|
recompute_queue = []
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in New Issue