From 46f017c53b9303a4e6d254c1b3d2560e5904c3e9 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Thu, 25 Jul 2013 18:26:24 +0000 Subject: [PATCH 1/8] [IMP] Field target_move is added to wizard in afr so that it will used in the future to filter posted and unposted entries --- account_financial_report/view/wizard.xml | 1 + account_financial_report/wizard/wizard.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/account_financial_report/view/wizard.xml b/account_financial_report/view/wizard.xml index 4136bfb1..76deeaff 100644 --- a/account_financial_report/view/wizard.xml +++ b/account_financial_report/view/wizard.xml @@ -47,6 +47,7 @@ + diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index be9ff1eb..8e392f09 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.py @@ -54,6 +54,9 @@ class wizard_report(osv.osv_memory): 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'lab_str': fields.char('Description', help='Description for the Summary', size=128), + 'target_move': fields.selection([('posted', 'All Posted Entries'), + ('all', 'All Entries'), + ], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), 'date_to': fields.date('End date'), @@ -70,6 +73,7 @@ class wizard_report(osv.osv_memory): 'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid), 'display_account': lambda *a: 'bal_mov', 'columns': lambda *a: 'five', + 'target_move': 'posted', } def onchange_inf_type(self, cr, uid, ids, inf_type, context=None): From 8d57b7a79b9d9bd1bf98db5a21d8de995c9a5c70 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Thu, 25 Jul 2013 18:34:18 +0000 Subject: [PATCH 2/8] [IMP] Field target_move is added to template in afr so that it will used in the future to filter posted and unposted entries --- account_financial_report/model/account_financial_report.py | 4 ++++ .../view/account_financial_report_view.xml | 1 + 2 files changed, 5 insertions(+) diff --git a/account_financial_report/model/account_financial_report.py b/account_financial_report/model/account_financial_report.py index 46acb7d0..12d23aaa 100644 --- a/account_financial_report/model/account_financial_report.py +++ b/account_financial_report/model/account_financial_report.py @@ -51,6 +51,9 @@ class account_financial_report(osv.osv): 'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'), 'lab_str': fields.char('Description', help='Description for the Summary', size=128), + 'target_move': fields.selection([('posted', 'All Posted Entries'), + ('all', 'All Entries'), + ], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), @@ -69,6 +72,7 @@ class account_financial_report(osv.osv): 'date_from': lambda *a: time.strftime('%Y-%m-%d'), 'date_to': lambda *a: time.strftime('%Y-%m-%d'), 'filter': lambda *a: 'byperiod', + 'target_move': 'posted', } def copy(self, cr, uid, id, defaults, context=None): diff --git a/account_financial_report/view/account_financial_report_view.xml b/account_financial_report/view/account_financial_report_view.xml index 40cd1d8f..6306ba76 100644 --- a/account_financial_report/view/account_financial_report_view.xml +++ b/account_financial_report/view/account_financial_report_view.xml @@ -30,6 +30,7 @@ + Date: Thu, 25 Jul 2013 20:29:21 +0000 Subject: [PATCH 3/8] [IMP] Now reports different From General Ledger can show posted or all entries depending on the selection. --- account_financial_report/report/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index ebb74b92..16329078 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -321,6 +321,7 @@ class account_balance(report_sxw.rml_parse): def z(n): return abs(n) < 0.005 and 0.0 or n + self.context['state'] = form['target_move'] self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[ 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id']) if not form['currency_id']: From b03c6b79302fc5e2f28e074a70cdccae5102df9e Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Thu, 25 Jul 2013 23:06:44 +0000 Subject: [PATCH 4/8] [FIX] Totalizing lines is being fixed and now summarize only those lines which are in the account_list. --- account_financial_report/report/parser.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 16329078..e4d4c0c1 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -332,6 +332,7 @@ class account_balance(report_sxw.rml_parse): if 'account_list' in form and form['account_list']: account_ids = form['account_list'] + account_list= form['account_list'] del form['account_list'] credit_account_ids = self.get_company_accounts(form['company_id'] and type(form[ @@ -726,11 +727,10 @@ class account_balance(report_sxw.rml_parse): # # Check whether we must sumarize this line in the report or not # - if form['tot_check'] and res['type'] == 'view' and res['level'] == 1 and (res['id'] not in tot): - + if form['tot_check'] and (res['id'] in account_list) and (res['id'] not in tot): if form['columns'] == 'qtr': tot_check = True - #~ tot[res['id']] = True + tot[res['id']] = True tot_bal1 += res.get('bal1', 0.0) tot_bal2 += res.get('bal2', 0.0) tot_bal3 += res.get('bal3', 0.0) @@ -739,7 +739,7 @@ class account_balance(report_sxw.rml_parse): elif form['columns'] == 'thirteen': tot_check = True - #~ tot[res['id']] = True + tot[res['id']] = True tot_bal1 += res.get('bal1', 0.0) tot_bal2 += res.get('bal2', 0.0) tot_bal3 += res.get('bal3', 0.0) @@ -755,7 +755,7 @@ class account_balance(report_sxw.rml_parse): tot_bal13 += res.get('bal13', 0.0) else: tot_check = True - #~ tot[res['id']] = True + tot[res['id']] = True tot_bin += res['balanceinit'] tot_deb += res['debit'] tot_crd += res['credit'] From 14af492ba113bed3f2decbb833918abdbedac454 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Thu, 25 Jul 2013 23:47:03 +0000 Subject: [PATCH 5/8] [IMP] Now Analytic lines is aware of the option 'Entries to Include' --- account_financial_report/model/account_financial_report.py | 3 ++- account_financial_report/report/parser.py | 6 ++++-- account_financial_report/wizard/wizard.py | 3 ++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/account_financial_report/model/account_financial_report.py b/account_financial_report/model/account_financial_report.py index 12d23aaa..b1e50d68 100644 --- a/account_financial_report/model/account_financial_report.py +++ b/account_financial_report/model/account_financial_report.py @@ -53,7 +53,8 @@ class account_financial_report(osv.osv): 'lab_str': fields.char('Description', help='Description for the Summary', size=128), 'target_move': fields.selection([('posted', 'All Posted Entries'), ('all', 'All Entries'), - ], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'), + ], 'Entries to Include', required=True, + help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index e4d4c0c1..cd534ea0 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -181,7 +181,8 @@ class account_balance(report_sxw.rml_parse): #~ periods = str(tuple(ctx['periods'])) where = """where aml.period_id in (%s) and aa.id = %s and aml.state <> 'draft'""" % ( periods, account['id']) - + if ctx.get('state','posted')=='posted': + where += "AND am.state = 'posted'" sql_detalle = """select aml.id as id, aj.name as diario, aa.name as descripcion, (select name from res_partner where aml.partner_id = id) as partner, aa.code as cuenta, aml.name as name, @@ -321,7 +322,8 @@ class account_balance(report_sxw.rml_parse): def z(n): return abs(n) < 0.005 and 0.0 or n - self.context['state'] = form['target_move'] + self.context['state'] = form['target_move'] or 'posted' + self.from_currency_id = self.get_company_currency(form['company_id'] and type(form[ 'company_id']) in (list, tuple) and form['company_id'][0] or form['company_id']) if not form['currency_id']: diff --git a/account_financial_report/wizard/wizard.py b/account_financial_report/wizard/wizard.py index 8e392f09..b15d54f2 100644 --- a/account_financial_report/wizard/wizard.py +++ b/account_financial_report/wizard/wizard.py @@ -56,7 +56,8 @@ class wizard_report(osv.osv_memory): 'target_move': fields.selection([('posted', 'All Posted Entries'), ('all', 'All Entries'), - ], 'Target Moves', help='Print All Accounting Entries or just Posted Accounting Entries'), + ], 'Entries to Include', required=True, + help='Print All Accounting Entries or just Posted Accounting Entries'), #~ Deprecated fields 'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'), 'date_to': fields.date('End date'), From 76b4ec45e69f1a0572856f4a75e69ede41808b9f Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Fri, 26 Jul 2013 04:36:44 +0000 Subject: [PATCH 6/8] [IMP] Consolidating Accounts now are able to be summarize with AFR --- account_financial_report/report/parser.py | 36 +++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index cd534ea0..1a55b739 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -440,8 +440,23 @@ class account_balance(report_sxw.rml_parse): ('view', 'consolidation'))])) account_not_black_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ - i[0] for i in all_account_ids]), ('type', 'in', ('view', 'consolidation'))])) + i[0] for i in all_account_ids]),('type', '=', 'view')])) + acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ + i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))])) + + account_consol_ids = account_obj._get_children_and_consol( + self.cr, self.uid, acc_cons_ids) + + account_black_ids += account_obj.search(self.cr, self.uid, ( + [('id', 'in', account_consol_ids ), + ('type', 'not in', + ('view', 'consolidation'))])) + + c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([ + ('id', 'in', account_consol_ids), + ('type', '=', 'view')])) + # This could be done quickly with a sql sentence account_not_black = account_obj.browse( self.cr, self.uid, account_not_black_ids) @@ -449,6 +464,21 @@ class account_balance(report_sxw.rml_parse): account_not_black.reverse() account_not_black_ids = [i.id for i in account_not_black] + c_account_not_black = account_obj.browse( + self.cr, self.uid, c_account_not_black_ids) + c_account_not_black.sort(key=lambda x: x.level) + c_account_not_black.reverse() + c_account_not_black_ids = [i.id for i in c_account_not_black] + + acc_cons_brw = account_obj.browse( + self.cr, self.uid, acc_cons_ids) + acc_cons_brw.sort(key=lambda x: x.level) + acc_cons_brw.reverse() + acc_cons_ids = [i.id for i in acc_cons_brw] + + account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids + account_not_black = c_account_not_black + acc_cons_brw + account_not_black + all_account_period = {} # All accounts per period # Iteration limit depending on the number of columns @@ -514,7 +544,9 @@ class account_balance(report_sxw.rml_parse): ) #It makes a copy because they modify for acc_id in account_not_black_ids: - acc_childs = dict_not_black.get(acc_id).get('obj').child_id + acc_childs = dict_not_black.get(acc_id).get('obj').type=='view' \ + and dict_not_black.get(acc_id).get('obj').child_id \ + or dict_not_black.get(acc_id).get('obj').child_consol_ids for child_id in acc_childs: dict_not_black.get(acc_id)['debit'] += all_account.get( child_id.id).get('debit') From 28b673783f4a702d6dfb161585096c2691bed1c5 Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Fri, 26 Jul 2013 04:51:07 +0000 Subject: [PATCH 7/8] [FIX] Avoid duplicating accounts when there are Consolidating Accounts --- account_financial_report/report/parser.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index 1a55b739..c1196eeb 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -453,10 +453,13 @@ class account_balance(report_sxw.rml_parse): ('type', 'not in', ('view', 'consolidation'))])) + account_black_ids = list(set(account_black_ids)) + c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([ ('id', 'in', account_consol_ids), ('type', '=', 'view')])) - + account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids)) + # This could be done quickly with a sql sentence account_not_black = account_obj.browse( self.cr, self.uid, account_not_black_ids) From 7c5cf4b0180222776c496049f05639e85297e55f Mon Sep 17 00:00:00 2001 From: Humberto Arocha Date: Fri, 26 Jul 2013 05:43:25 +0000 Subject: [PATCH 8/8] [IMP] Now Consolidating Accounts are gotten rid when their children accounts are requested from the main window. This way, when a Trail Balance is requested it can be summarized and the sum can be checked to verify that it is correct. --- account_financial_report/report/parser.py | 32 +++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/account_financial_report/report/parser.py b/account_financial_report/report/parser.py index c1196eeb..9963074a 100644 --- a/account_financial_report/report/parser.py +++ b/account_financial_report/report/parser.py @@ -445,8 +445,8 @@ class account_balance(report_sxw.rml_parse): acc_cons_ids = account_obj.search(self.cr, self.uid, ([('id', 'in', [ i[0] for i in all_account_ids]), ('type', 'in', ('consolidation',))])) - account_consol_ids = account_obj._get_children_and_consol( - self.cr, self.uid, acc_cons_ids) + account_consol_ids = acc_cons_ids and account_obj._get_children_and_consol( + self.cr, self.uid, acc_cons_ids) or [] account_black_ids += account_obj.search(self.cr, self.uid, ( [('id', 'in', account_consol_ids ), @@ -458,7 +458,10 @@ class account_balance(report_sxw.rml_parse): c_account_not_black_ids = account_obj.search(self.cr, self.uid, ([ ('id', 'in', account_consol_ids), ('type', '=', 'view')])) - account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids)) + delete_cons = False + if c_account_not_black_ids: + delete_cons = set(account_not_black_ids) & set(c_account_not_black_ids) and True or False + account_not_black_ids = list(set(account_not_black_ids) - set(c_account_not_black_ids)) # This could be done quickly with a sql sentence account_not_black = account_obj.browse( @@ -473,14 +476,18 @@ class account_balance(report_sxw.rml_parse): c_account_not_black.reverse() c_account_not_black_ids = [i.id for i in c_account_not_black] - acc_cons_brw = account_obj.browse( - self.cr, self.uid, acc_cons_ids) - acc_cons_brw.sort(key=lambda x: x.level) - acc_cons_brw.reverse() - acc_cons_ids = [i.id for i in acc_cons_brw] + if delete_cons: + account_not_black_ids = c_account_not_black_ids + account_not_black_ids + account_not_black = c_account_not_black + account_not_black + else: + acc_cons_brw = account_obj.browse( + self.cr, self.uid, acc_cons_ids) + acc_cons_brw.sort(key=lambda x: x.level) + acc_cons_brw.reverse() + acc_cons_ids = [i.id for i in acc_cons_brw] - account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids - account_not_black = c_account_not_black + acc_cons_brw + account_not_black + account_not_black_ids = c_account_not_black_ids + acc_cons_ids + account_not_black_ids + account_not_black = c_account_not_black + acc_cons_brw + account_not_black all_account_period = {} # All accounts per period @@ -551,6 +558,8 @@ class account_balance(report_sxw.rml_parse): and dict_not_black.get(acc_id).get('obj').child_id \ or dict_not_black.get(acc_id).get('obj').child_consol_ids for child_id in acc_childs: + if child_id.type == 'consolidation' and delete_cons: + continue dict_not_black.get(acc_id)['debit'] += all_account.get( child_id.id).get('debit') dict_not_black.get(acc_id)['credit'] += all_account.get( @@ -577,7 +586,8 @@ class account_balance(report_sxw.rml_parse): for aa_id in account_ids: id = aa_id[0] - + if aa_id[3].type == 'consolidation' and delete_cons: + continue # # Check if we need to include this level #