[IMP] Refactor improvements using AEP
parent
76ea800265
commit
7b89e6d573
|
@ -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':
|
||||||
|
|
|
@ -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 = []
|
domain = []
|
||||||
# extract all bal code
|
this = self.browse(cr, uid, ids, context=context)[0]
|
||||||
res_vars = {}
|
env = Environment(cr, uid, {})
|
||||||
domain_mapping = {}
|
aep = AccountingExpressionProcessor(env)
|
||||||
_get_account_vars_in_expr(account_, res_vars, domain_mapping,
|
aep.parse_expr(account_)
|
||||||
is_solde=False, is_initial=False)
|
aep.done_parsing([('company_id', '=',
|
||||||
for key_domain, account_code in res_vars.iteritems():
|
this.report_instance_id.company_id.id)])
|
||||||
key, domain = key_domain
|
domain.extend(aep.get_aml_domain_for_expr(account_))
|
||||||
partial_domain = [('account_id.code', 'in', list(account_code))]
|
if domain != []:
|
||||||
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
|
|
||||||
|
|
||||||
# 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']
|
||||||
|
target_move = this.report_instance_id.target_move
|
||||||
for c in self.browse(cr, uid, ids, context=context):
|
|
||||||
target_move = c.report_instance_id.target_move
|
|
||||||
if target_move == 'posted':
|
if target_move == 'posted':
|
||||||
domain_list.append(('move_id.state', '=', target_move))
|
domain.append(('move_id.state', '=', target_move))
|
||||||
if c.period_from:
|
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 = this.date_from
|
||||||
date_from = c.date_from
|
date_to = this.date_to
|
||||||
if not date_to or date_to < c.date_to:
|
|
||||||
date_to = c.date_to
|
|
||||||
if period_ids:
|
if period_ids:
|
||||||
if date_from:
|
if date_from:
|
||||||
domain_list.append('|')
|
domain.append('|')
|
||||||
domain_list.append(('period_id', 'in', period_ids))
|
domain.append(('period_id', 'in', period_ids))
|
||||||
if date_from:
|
if date_from:
|
||||||
domain_list.extend([('date', '>=', c.date_from),
|
domain.extend([('date', '>=', date_from),
|
||||||
('date', '<=', c.date_to)])
|
('date', '<=', date_to)])
|
||||||
return domain_list
|
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):
|
||||||
|
|
|
@ -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…
Reference in New Issue