diff --git a/addons/account_test/account_test.py b/addons/account_test/account_test.py index dc7442b1247..bf925e8236a 100644 --- a/addons/account_test/account_test.py +++ b/addons/account_test/account_test.py @@ -50,7 +50,7 @@ class accounting_assert_test(osv.osv): _columns = { 'name': fields.char('Test Name', size=256, required=True, select=True, translate=True), 'desc': fields.text('Test Description', select=True, translate=True), - 'code_exec': fields.text('Python code or SQL query', required=True), + 'code_exec': fields.text('Python code', required=True), 'active': fields.boolean('Active'), 'sequence': fields.integer('Sequence'), } diff --git a/addons/account_test/account_test_view.xml b/addons/account_test/account_test_view.xml index 1faca55c4d6..43a67edcc6c 100644 --- a/addons/account_test/account_test_view.xml +++ b/addons/account_test/account_test_view.xml @@ -13,7 +13,7 @@ - + Tests accounting.assert.test @@ -39,20 +39,26 @@
-Code should always return a result value. If result is an empty list, it means that
-the test is succesful. Otherwise it will print what is inside result.
-Code must be python with correct indentation (if needed).
-Here is a list of function that you can use in your test :
- - group(lst, col) : 
- - reconciled_inv() : return the list of all reconciled invoices
- - get_parent(acc_id) : get parent analytical account
- - now() : return current datetime
+Code should always set a variable named `result` with the result of your test, that can be a list or
+a dictionary. If `result` is an empty list, it means that the test was succesful. Otherwise it will
+try to translate and print what is inside `result`.
+
+If the result of your test is a dictionary, you can set a variable named `column_order` to choose in
+what order you want to print `result`'s content.
+
+Should you need them, you can also use the following variables into your code:
+    * cr: cursor to the database
+    * uid: ID of the current user
+
+In any ways, the code must be legal python statements with correct indentation (if needed).
 
 Example: 
-sql = 'select id, name, ref, date from account_move_line where account_id in 
-(select id from account_account where type = 'view')'
-cr.execute(sql)
-result = cr.dictfetchall()
+    sql = '''SELECT id, name, ref, date
+             FROM account_move_line 
+             WHERE account_id IN (SELECT id FROM account_account WHERE type = 'view')
+          '''
+    cr.execute(sql)
+    result = cr.dictfetchall()
                                     
@@ -61,7 +67,7 @@ result = cr.dictfetchall()
- + Accounting Tests accounting.assert.test @@ -72,7 +78,7 @@ result = cr.dictfetchall()

- + diff --git a/addons/account_test/report/account_test_report.py b/addons/account_test/report/account_test_report.py index f8ba7a47f65..ab683e18688 100644 --- a/addons/account_test/report/account_test_report.py +++ b/addons/account_test/report/account_test_report.py @@ -22,10 +22,7 @@ import datetime import time -import re from report import report_sxw -from itertools import groupby -from operator import itemgetter from tools.translate import _ # # Use period and Journal for selection or resources @@ -40,37 +37,34 @@ class report_assert_account(report_sxw.rml_parse): }) def execute_code(self, code_exec): - def group(lst, col): - return dict((k, [v for v in itr]) for k, itr in groupby(sorted(lst, key=lambda x: x[col]), itemgetter(col))) - def reconciled_inv(): - reconciled_inv_ids = self.pool.get('account.invoice').search(self.cr, self.uid, [('reconciled','=',True)]) - return reconciled_inv_ids - - def get_parent(acc_id): - acc_an_id = self.pool.get('account.analytic.account').browse(self.cr, self.uid, acc_id).parent_id - while acc_an_id.parent_id: - acc_an_id = acc_an_id.parent_id - return acc_an_id.id + """ + returns the list of invoices that are set as reconciled = True + """ + return self.pool.get('account.invoice').search(self.cr, self.uid, [('reconciled','=',True)]) def order_columns(item, cols=None): + """ + This function is used to display a dictionary as a string, with its columns in the order chosen. + + :param item: dict + :param cols: list of field names + :returns: a list of tuples (fieldname: value) in a similar way that would dict.items() do except that the + returned values are following the order given by cols + :rtype: [(key, value)] + """ if cols is None: cols = item.keys() return [(col, item.get(col)) for col in cols if col in item.keys()] localdict = { 'cr': self.cr, - '_': _, - 'reconciled_inv' : reconciled_inv, - 'group' : group, - 'get_parent' : get_parent, - 'now': datetime.datetime.now(), - 'result': None, - 'column_order': None, + 'uid': self.uid, + 'reconciled_inv': reconciled_inv, #specific function used in different tests + 'result': None, #used to store the result of the test + 'column_order': None, #used to choose the display order of columns (in case you are returning a list of dict) } - exec code_exec in localdict - result = localdict['result'] column_order = localdict.get('column_order', None) @@ -79,12 +73,12 @@ class report_assert_account(report_sxw.rml_parse): if not result: result = [_('The test was passed successfully')] else: - def _format(a): - if isinstance(a, dict): - return ', '.join(["%s: %s" % (tup[0], tup[1]) for tup in order_columns(a, column_order)]) + def _format(item): + if isinstance(item, dict): + return ', '.join(["%s: %s" % (tup[0], tup[1]) for tup in order_columns(item, column_order)]) else: - return a - result = [_format(rec) for rec in result] + return item + result = [_(_format(rec)) for rec in result] return result diff --git a/addons/account_test/security/ir.model.access.csv b/addons/account_test/security/ir.model.access.csv index 95f2336f80b..cf7e93b6baa 100644 --- a/addons/account_test/security/ir.model.access.csv +++ b/addons/account_test/security/ir.model.access.csv @@ -1,3 +1,3 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_accounting_assert_test","accounting.assert.test","model_accounting_assert_test",base.group_system,1,1,1,1 +"access_accounting_assert_test","accounting.assert.test","model_accounting_assert_test",base.group_system,1,0,0,1 "access_accounting_assert_test_manager","accounting.assert.test","model_accounting_assert_test",account.group_account_manager,1,0,0,0