diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index 8562d863..27e82d33 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -107,7 +107,7 @@ class AccountingExpressionProcessor(object): self._account_ids_by_code[code].add(account.id) for like_code in like_codes: for account in account_model.\ - search([('code', 'like', like_code), + search([('code', '=like', like_code), ('parent_id', 'child_of', root_account.id)]): if account.type in ('view', 'consolidation'): self._account_ids_by_code[like_code].update( diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 1ee0ee6e..c4d6eaad 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -332,15 +332,23 @@ class MisReport(models.Model): domain.extend([(query.date_field.name, '>=', datetime_from), (query.date_field.name, '<', datetime_to)]) field_names = [f.name for f in query.field_ids] + all_stored = all([model._fields[f].store for f in field_names]) if not query.aggregate: data = model.search_read(domain, field_names) res[query.name] = [AutoStruct(**d) for d in data] - elif query.aggregate == 'sum': + elif query.aggregate == 'sum' and all_stored: + # use read_group to sum stored fields data = model.read_group( domain, field_names, []) s = AutoStruct(count=data[0]['__count']) for field_name in field_names: - v = data[0][field_name] + try: + v = data[0][field_name] + except KeyError: + _logger.error('field %s not found in read_group ' + 'for %s; not summable?', + field_name, model._name) + v = AccountingNone setattr(s, field_name, v) res[query.name] = s else: @@ -352,6 +360,8 @@ class MisReport(models.Model): agg = _max elif query.aggregate == 'avg': agg = _avg + elif query.aggregate == 'sum': + agg = _sum for field_name in field_names: setattr(s, field_name, agg([d[field_name] for d in data])) diff --git a/mis_builder/static/src/js/mis_builder.js b/mis_builder/static/src/js/mis_builder.js index e0346bd9..5a5ab019 100644 --- a/mis_builder/static/src/js/mis_builder.js +++ b/mis_builder/static/src/js/mis_builder.js @@ -26,7 +26,6 @@ openerp.mis_builder = function(instance) { self.mis_report_instance_id = self.getParent().datarecord.id if (self.mis_report_instance_id) { self.getParent().dataset.context['no_destroy'] = true; - self.generate_content(); } else { self.display_settings(); }