[MRG] [ADD] the possibility to use instance of account.statement.completion.rule

This commit is contained in:
unknown
2014-01-23 09:44:24 +01:00
committed by Yannick Vaucher
9 changed files with 385 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ import traceback
import sys
import logging
import simplejson
import inspect
import psycopg2
@@ -73,14 +74,13 @@ class AccountStatementProfil(orm.Model):
rel='as_rul_st_prof_rel'),
}
def _get_callable(self, cr, uid, profile, context=None):
def _get_rules(self, cr, uid, profile, context=None):
if isinstance(profile, (int, long)):
prof = self.browse(cr, uid, profile, context=context)
else:
prof = profile
# We need to respect the sequence order
sorted_array = sorted(prof.rule_ids, key=attrgetter('sequence'))
return tuple((x.function_to_call for x in sorted_array))
return sorted(prof.rule_ids, key=attrgetter('sequence'))
def _find_values_from_rules(self, cr, uid, calls, line, context=None):
"""
@@ -99,12 +99,15 @@ class AccountStatementProfil(orm.Model):
if context is None:
context = {}
if not calls:
calls = self._get_callable(cr, uid, line['profile_id'], context=context)
calls = self._get_rules(cr, uid, line['profile_id'], context=context)
rule_obj = self.pool.get('account.statement.completion.rule')
for call in calls:
method_to_call = getattr(rule_obj, call)
result = method_to_call(cr, uid, line, context)
method_to_call = getattr(rule_obj, call.function_to_call)
if len(inspect.getargspec(method_to_call).args) == 6:
result = method_to_call(cr, uid, call.id, line, context)
else:
result = method_to_call(cr, uid, line, context)
if result:
result['already_completed'] = True
return result
@@ -526,7 +529,7 @@ class AccountBankSatement(orm.Model):
ctx = context.copy()
ctx['line_ids'] = tuple((x.id for x in stat.line_ids))
b_profile = stat.profile_id
rules = profile_obj._get_callable(cr, uid, b_profile, context=context)
rules = profile_obj._get_rules(cr, uid, b_profile, context=context)
profile_id = b_profile.id # Only for perfo even it gains almost nothing
master_account_id = b_profile.receivable_account_id
master_account_id = master_account_id.id if master_account_id else False