22
22
23
23
import datetime
24
24
import time
25
- import re
26
25
from report import report_sxw
27
- from itertools import groupby
28
- from operator import itemgetter
29
26
from tools .translate import _
30
27
#
31
28
# Use period and Journal for selection or resources
@@ -40,37 +37,34 @@ def __init__(self, cr, uid, name, context):
40
37
})
41
38
42
39
def execute_code (self , code_exec ):
43
- def group (lst , col ):
44
- return dict ((k , [v for v in itr ]) for k , itr in groupby (sorted (lst , key = lambda x : x [col ]), itemgetter (col )))
45
-
46
40
def reconciled_inv ():
47
- reconciled_inv_ids = self .pool .get ('account.invoice' ).search (self .cr , self .uid , [('reconciled' ,'=' ,True )])
48
- return reconciled_inv_ids
49
-
50
- def get_parent (acc_id ):
51
- acc_an_id = self .pool .get ('account.analytic.account' ).browse (self .cr , self .uid , acc_id ).parent_id
52
- while acc_an_id .parent_id :
53
- acc_an_id = acc_an_id .parent_id
54
- return acc_an_id .id
41
+ """
42
+ returns the list of invoices that are set as reconciled = True
43
+ """
44
+ return self .pool .get ('account.invoice' ).search (self .cr , self .uid , [('reconciled' ,'=' ,True )])
55
45
56
46
def order_columns (item , cols = None ):
47
+ """
48
+ This function is used to display a dictionary as a string, with its columns in the order chosen.
49
+
50
+ :param item: dict
51
+ :param cols: list of field names
52
+ :returns: a list of tuples (fieldname: value) in a similar way that would dict.items() do except that the
53
+ returned values are following the order given by cols
54
+ :rtype: [(key, value)]
55
+ """
57
56
if cols is None :
58
57
cols = item .keys ()
59
58
return [(col , item .get (col )) for col in cols if col in item .keys ()]
60
59
61
60
localdict = {
62
61
'cr' : self .cr ,
63
- '_' : _ ,
64
- 'reconciled_inv' : reconciled_inv ,
65
- 'group' : group ,
66
- 'get_parent' : get_parent ,
67
- 'now' : datetime .datetime .now (),
68
- 'result' : None ,
69
- 'column_order' : None ,
62
+ 'uid' : self .uid ,
63
+ 'reconciled_inv' : reconciled_inv , #specific function used in different tests
64
+ 'result' : None , #used to store the result of the test
65
+ 'column_order' : None , #used to choose the display order of columns (in case you are returning a list of dict)
70
66
}
71
-
72
67
exec code_exec in localdict
73
-
74
68
result = localdict ['result' ]
75
69
column_order = localdict .get ('column_order' , None )
76
70
@@ -79,12 +73,12 @@ def order_columns(item, cols=None):
79
73
if not result :
80
74
result = [_ ('The test was passed successfully' )]
81
75
else :
82
- def _format (a ):
83
- if isinstance (a , dict ):
84
- return ', ' .join (["%s: %s" % (tup [0 ], tup [1 ]) for tup in order_columns (a , column_order )])
76
+ def _format (item ):
77
+ if isinstance (item , dict ):
78
+ return ', ' .join (["%s: %s" % (tup [0 ], tup [1 ]) for tup in order_columns (item , column_order )])
85
79
else :
86
- return a
87
- result = [_format (rec ) for rec in result ]
80
+ return item
81
+ result = [_ ( _format (rec ) ) for rec in result ]
88
82
89
83
return result
90
84
0 commit comments