5 <record model="accounting.assert.test" id="account_test_01">
6 <field name="sequence">1</field>
7 <field name="name">Test 1: General balance</field>
8 <field name="desc">Check the balance: Debit sum = Credit sum</field>
9 <field name="code_exec"><![CDATA[sql="""SELECT
10 sum(debit)-sum(credit) as balance
11 FROM account_move_line
15 res= cr.dictfetchall()
16 if res[0]['balance']!=0.0 and res[0]['balance'] is not None:
17 result.append(_('* The difference of the balance is: '))
22 <record model="accounting.assert.test" id="account_test_02">
23 <field name="sequence">2</field>
24 <field name="name">Test 2: Opening a fiscal year</field>
25 <field name="desc">Check if the balance of the new opened fiscal year matches with last year's balance</field>
26 <field name="code_exec"><![CDATA[result = []
27 cr.execute("select coalesce(sum(debit),0) as debit_new_fyear,coalesce(sum(credit),0) as credit_new_fyear from account_move_line where period_id in (select id from account_period where state='draft' and special order by id desc limit 1);")
28 rec = cr.dictfetchall()
29 cr.execute("select coalesce(sum(debit),0) as debit_last_fyear,coalesce(sum(credit),0) as credit_last_fyear from account_move_line where period_id in (select period_id from account_fiscalyear where state='done' order by id desc limit 1);")
30 rec2= cr.dictfetchall()
31 if (rec2[0]['credit_last_fyear']-rec[0]['credit_new_fyear']!=0) or (rec2[0]['debit_last_fyear']-rec[0]['debit_new_fyear']!=0) :
32 result.append(_('* New fiscalyear debit and credit are:'))
34 result.append(_('* Last year debit and credit are:'))
35 result.append(rec2[0])
40 <record model="accounting.assert.test" id="account_test_03">
41 <field name="sequence">3</field>
42 <field name="name">Test 3: Movement lines</field>
43 <field name="desc">Check if movement lines are balanced and have the same date and period</field>
44 <field name="code_exec"><![CDATA[order_columns=['am_date','ml_date','am.period_id','ml.period_id','am.id']
47 sum(debit)-sum(credit) as balance,
52 FROM account_move am, account_move_line ml
55 GROUP BY am.name, am.id, am.state, am.period_id, ml.period_id,am.period_id, ml.period_id,am.date, ml.date
56 HAVING abs(sum(ml.debit-ml.credit)) <> 0 or am.period_id!=ml.period_id or (am.date!=ml.date)
59 res = cr.dictfetchall()
61 res.insert(0,_('* The test failed for these movement lines:'))
67 <record model="accounting.assert.test" id="account_test_04">
68 <field name="sequence">4</field>
69 <field name="name">Test 4: Totally reconciled mouvements</field>
70 <field name="desc">Check if the totally reconciled movements are balanced</field>
71 <field name="code_exec"><![CDATA[res = []
72 cr.execute("SELECT distinct reconcile_id from account_move_line where reconcile_id is not null")
73 rec_ids = cr.dictfetchall()
74 for record in rec_ids :
75 cr.execute("SELECT distinct r.name,r.id from account_journal j,account_period p, account_move_reconcile r,account_move m, account_move_line ml where m.journal_id=j.id and m.period_id=p.id and ml.reconcile_id=%s and ml.move_id=m.id and ml.reconcile_id=r.id group by r.id,r.name having sum(ml.debit)-sum(ml.credit)<>0", (record['reconcile_id'],))
76 reconcile_ids=cr.dictfetchall()
78 res.append(', '.join(["Reconcile name: %(name)s, id=%(id)s " % r for r in reconcile_ids]))
81 result.insert(0,_('* The test failed for these reconciled items(id/name):'))
85 <record model="accounting.assert.test" id="account_test_05">
86 <field name="sequence">5</field>
87 <field name="name">Test 5.1 : Payable and Receivable accountant lines of reconciled invoices</field>
88 <field name="desc">Check that reconciled invoice for Sales/Purchases has reconciled entries for Payable and Receivable Accounts</field>
89 <field name="code_exec"><![CDATA[res = []
90 cr.execute("SELECT distinct inv.number,inv.id from account_invoice inv, account_move m, account_move_line ml, account_account a where m.id=ml.move_id and ml.account_id=a.id and a.type in ('receivable','payable') and inv.move_id=m.id and ml.reconcile_id is not null;")
91 records= cr.dictfetchall()
92 rec = [r['id'] for r in records]
93 res = reconciled_inv()
94 invoices = set(rec).difference(set(res))
95 result = [rec for rec in records if rec['id'] in invoices]
97 result.insert(0,_('* Invoices that need to be checked: '))
101 <record model="accounting.assert.test" id="account_test_05_2">
102 <field name="sequence">6</field>
103 <field name="name">Test 5.2 : Reconcilied invoices and Payable/Receivable accounts</field>
104 <field name="desc">Check that reconciled account moves, that define Payable and Receivable accounts, are belonging to reconciled invoices</field>
105 <field name="code_exec"><![CDATA[res = reconciled_inv()
108 cr.execute("SELECT distinct inv.number,inv.id from account_invoice inv, account_move_line ml, account_account a, account_move m where m.id=ml.move_id and inv.move_id=m.id and inv.id=inv.move_id and ml.reconcile_id is null and a.type in ('receivable','payable') and ml.account_id=a.id and inv.id in %s",(tuple(res),))
109 records = cr.dictfetchall()
110 result = [rec for rec in records]
112 result.insert(0,_('* Invoices that need to be checked: '))
116 <record model="accounting.assert.test" id="account_test_06">
117 <field name="sequence">7</field>
118 <field name="name">Test 6 : Invoices status</field>
119 <field name="desc">Check that paid/reconciled invoices are not in 'Open' state</field>
120 <field name="code_exec"><![CDATA[
122 column_order = ['number','id','name','state']
124 cr.execute("select inv.name,inv.state,inv.id,inv.number from account_invoice inv where inv.state!='paid' and id in %s", (tuple(reconciled_inv()),))
125 res = cr.dictfetchall()
128 result.insert(0,_('* Invoices that need to be checked: '))
133 <record model="accounting.assert.test" id="account_test_06_1">
134 <field name="sequence">8</field>
135 <field name="name">Test 7: « View » account type</field>
136 <field name="desc">Check that there's no move for any account with « View » account type</field>
137 <field name="code_exec"><![CDATA[column_order=['name','ref','id','date']
138 sql = "select id, name, ref, date from account_move_line where account_id in (select id from account_account where type = 'view')"
140 result = cr.dictfetchall()
142 result.insert(0,_('* Movement lines that need to be checked: '))
146 <record model="accounting.assert.test" id="account_test_07">
147 <field name="sequence">9</field>
148 <field name="name">Test 8 : Closing balance on bank statements</field>
149 <field name="desc">Check on bank statement that the Closing Balance = Starting Balance + sum of statement lines</field>
150 <field name="code_exec"><![CDATA[column_order = ['name','difference']
151 cr.execute("SELECT s.balance_start+sum(m.amount)-s.balance_end_real as difference, s.name from account_bank_statement s inner join account_bank_statement_line m on m.statement_id=s.id group by s.id, s.balance_start, s.balance_end_real,s.name having abs(s.balance_start+sum(m.amount)-s.balance_end_real) > 0.000000001;")
152 result = cr.dictfetchall()
154 result.insert(0,_('* Unbalanced bank statement that need to be checked: '))
158 <record model="accounting.assert.test" id="account_test_08">
159 <field name="sequence">10</field>
160 <field name="name">Test 9 : Accounts and partners on account moves</field>
161 <field name="desc">Check that general accounts and partners on account moves are active</field>
162 <field name="code_exec"><![CDATA[column_order=['partner_name','partner_active','account_name','move_line_id','period']
164 cr.execute("SELECT l.id as move_line_id,a.name as account_name,a.code as account_code,r.name as partner_name,r.active as partner_active,p.name as period from account_period p,res_partner r, account_account a,account_move_line l where l.account_id=a.id and l.partner_id=r.id and (not r.active or not a.active) and l.period_id=p.id")
165 res = cr.dictfetchall()
168 result.insert(0,_('* Here is the list of inactive partners and movement lines that are not correct: '))