Browse Source

[IMP] Refactor improvements using AEP

pull/86/head
Adrien Peiffer (ACSONE) 10 years ago
committed by Stéphane Bidoul
parent
commit
7b89e6d573
  1. 3
      mis_builder/models/aep.py
  2. 103
      mis_builder/models/mis_builder.py
  3. 2
      mis_builder/static/src/js/mis_builder.js

3
mis_builder/models/aep.py

@ -141,13 +141,14 @@ class AccountingExpressionProcessor(object):
""" """
domains = [] domains = []
for mo in self.ACC_RE.finditer(expr): for mo in self.ACC_RE.finditer(expr):
field, mode, account_codes, domain = self._parse_mo(mo)
field, mode, account_codes, domain_partial = self._parse_mo(mo)
if mode == 'i': if mode == 'i':
continue continue
account_ids = set() account_ids = set()
for account_code in account_codes: for account_code in account_codes:
account_ids.update(self._account_ids_by_code[account_code]) account_ids.update(self._account_ids_by_code[account_code])
domain = [('account_id', 'in', tuple(account_ids))] domain = [('account_id', 'in', tuple(account_ids))]
domain.extend(list(domain_partial))
if field == 'crd': if field == 'crd':
domain.append(('credit', '>', 0)) domain.append(('credit', '>', 0))
elif field == 'deb': elif field == 'deb':

103
mis_builder/models/mis_builder.py

@ -76,51 +76,6 @@ def _python_var(var_str):
return re.sub(r'\W|^(?=\d)', '_', var_str).lower() return re.sub(r'\W|^(?=\d)', '_', var_str).lower()
def _get_sufix(is_solde=False, is_initial=False):
if is_solde:
return 's'
elif is_initial:
return 'i'
else:
return ''
def _get_prefix(function, is_solde=False, is_initial=False):
return function + _get_sufix(is_solde=is_solde, is_initial=is_initial)
# 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(?:_[0-9]+|\[.*?\])(?:\[.+?\])?' % prefix,
expr)
for item in find_res:
match = re.match(r'\b(%s)(_[0-9]+|\[.*?\])(\[.+?\])?' % 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()
if var_tuple[1].startswith('_'):
account_codes = var_tuple[1][1:]
else:
account_codes = var_tuple[1][1:-1]
account_codes = [a.strip() for a in account_codes.split(',')]
account_codes_set = set(account_codes)
res_vars[key_domain] |= account_codes_set
def _is_valid_python_var(name): def _is_valid_python_var(name):
for item in FUNCTION_LIST: for item in FUNCTION_LIST:
for param in PARAMETERS: for param in PARAMETERS:
@ -535,57 +490,43 @@ class mis_report_instance_period(orm.Model):
'Period name should be unique by report'), 'Period name should be unique by report'),
] ]
# TODO : To review
def compute_domain(self, cr, uid, ids, account_, context=None): def compute_domain(self, cr, uid, ids, account_, context=None):
if isinstance(ids, (int, long)): if isinstance(ids, (int, long)):
ids = [ids] ids = [ids]
domain_list = []
# extract all bal code
res_vars = {}
domain_mapping = {}
_get_account_vars_in_expr(account_, res_vars, domain_mapping,
is_solde=False, is_initial=False)
for key_domain, account_code in res_vars.iteritems():
key, domain = key_domain
partial_domain = [('account_id.code', 'in', list(account_code))]
if domain != '':
partial_domain.insert(0, '&')
domain_eval = safe_eval(domain)
partial_domain.extend(domain_eval)
domain_list.extend(partial_domain)
nb_or = len(res_vars) - 1
while nb_or > 0:
domain_list.insert(0, '|')
nb_or -= 1
domain = []
this = self.browse(cr, uid, ids, context=context)[0]
env = Environment(cr, uid, {})
aep = AccountingExpressionProcessor(env)
aep.parse_expr(account_)
aep.done_parsing([('company_id', '=',
this.report_instance_id.company_id.id)])
domain.extend(aep.get_aml_domain_for_expr(account_))
if domain != []:
# compute date/period # compute date/period
period_ids = [] period_ids = []
date_from = None date_from = None
date_to = None date_to = None
period_obj = self.pool['account.period'] period_obj = self.pool['account.period']
for c in self.browse(cr, uid, ids, context=context):
target_move = c.report_instance_id.target_move
target_move = this.report_instance_id.target_move
if target_move == 'posted': if target_move == 'posted':
domain_list.append(('move_id.state', '=', target_move))
if c.period_from:
domain.append(('move_id.state', '=', target_move))
if this.period_from:
compute_period_ids = period_obj.build_ctx_periods( compute_period_ids = period_obj.build_ctx_periods(
cr, uid, c.period_from.id, c.period_to.id)
cr, uid, this.period_from.id, this.period_to.id)
period_ids.extend(compute_period_ids) period_ids.extend(compute_period_ids)
else: else:
if not date_from or date_from > c.date_from:
date_from = c.date_from
if not date_to or date_to < c.date_to:
date_to = c.date_to
date_from = this.date_from
date_to = this.date_to
if period_ids: if period_ids:
if date_from: if date_from:
domain_list.append('|')
domain_list.append(('period_id', 'in', period_ids))
domain.append('|')
domain.append(('period_id', 'in', period_ids))
if date_from: if date_from:
domain_list.extend([('date', '>=', c.date_from),
('date', '<=', c.date_to)])
return domain_list
domain.extend([('date', '>=', date_from),
('date', '<=', date_to)])
else:
domain = False
return domain
def compute_period_domain(self, cr, uid, period_report, is_solde, def compute_period_domain(self, cr, uid, period_report, is_solde,
is_initial, context=None): is_initial, context=None):

2
mis_builder/static/src/js/mis_builder.js

@ -35,6 +35,7 @@ openerp.mis_builder = function(instance) {
[period_id, val_c], [period_id, val_c],
{'context': new instance.web.CompoundContext()} {'context': new instance.web.CompoundContext()}
).then(function(result){ ).then(function(result){
if (result != false){
self.do_action({ self.do_action({
name: val_c + ' - ' + period_name, name: val_c + ' - ' + period_name,
domain: JSON.stringify(result), domain: JSON.stringify(result),
@ -45,6 +46,7 @@ openerp.mis_builder = function(instance) {
view_mode : "list", view_mode : "list",
target: 'current', target: 'current',
}); });
}
}); });
} }
}, },

Loading…
Cancel
Save