From de62c0dec32b19318c566eb306a0cdf4171da9b4 Mon Sep 17 00:00:00 2001 From: apa-tiny Date: Wed, 22 Oct 2008 12:10:32 +0530 Subject: [PATCH] General Ledger Wizard Completed.... bzr revid: patelamit2003@gmail.com-20081022064032-yg1jzjhouocvzxbl --- addons/account/report/general_ledger.py | 142 ++++-- addons/account/report/general_ledger.rml | 297 +++---------- .../report/general_ledger_landscape.py | 79 +++- .../report/general_ledger_landscape.rml | 415 ++++-------------- .../wizard/wizard_general_ledger_report.py | 130 +++--- 5 files changed, 393 insertions(+), 670 deletions(-) diff --git a/addons/account/report/general_ledger.py b/addons/account/report/general_ledger.py index f4ff9f9ef45..57a355f4f93 100755 --- a/addons/account/report/general_ledger.py +++ b/addons/account/report/general_ledger.py @@ -40,7 +40,11 @@ class general_ledger(rml_parse.rml_parse): def preprocess(self, objects, data, ids): ## + + self.borne_date = self.get_min_date(data['form']) + + ## new_ids = [] if (data['model'] == 'account.account'): @@ -54,6 +58,7 @@ class general_ledger(rml_parse.rml_parse): def __init__(self, cr, uid, name, context): super(general_ledger, self).__init__(cr, uid, name, context) + self.date_borne = {} self.query = "" self.child_ids = "" self.tot_currency = 0.0 @@ -109,6 +114,7 @@ class general_ledger(rml_parse.rml_parse): return result def get_children_accounts(self, account, form): + self.child_ids = self.pool.get('account.account').search(self.cr, self.uid, [('parent_id', 'child_of', self.ids)]) res = [] @@ -116,16 +122,17 @@ class general_ledger(rml_parse.rml_parse): ## We will make the test for period or date ## We will now make the test # - if form.has_key('fiscalyear'): + if form.has_key('fiscalyear'): ctx['fiscalyear'] = form['fiscalyear'] ctx['periods'] = form['periods'][0][2] else: ctx['date_from'] = form['date_from'] ctx['date_to'] = form['date_to'] - ## +# # self.query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx) + for child_id in self.pool.get('account.account').search(self.cr, self.uid, [('parent_id', 'child_of', [account.id])]): child_account = self.pool.get('account.account').browse(self.cr, self.uid, child_id) @@ -153,69 +160,111 @@ class general_ledger(rml_parse.rml_parse): res.append(child_account) ## - if form['soldeinit']: - ## We will now compute solde initiaux - for move in res: - SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + self.borne_date['max_date'] + "'" + " AND l.date > '" + self.borne_date['min_date'] + "'" - self.cr.execute(SOLDEINIT) - resultat = self.cr.dictfetchall() - if resultat[0] : - if resultat[0]['sum_debit'] == None: - sum_debit = 0 - else: - sum_debit = resultat[0]['sum_debit'] - if resultat[0]['sum_credit'] == None: - sum_credit = 0 - else: - sum_credit = resultat[0]['sum_credit'] - - move.init_credit = sum_credit - move.init_debit = sum_debit - - else: - move.init_credit = 0 - move.init_debit = 0 + + ## We will now compute solde initiaux + + for move in res: + + SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date <= '" + self.borne_date['max_date'] + "'" + " AND l.date >= '" + self.borne_date['min_date'] + "'" + self.cr.execute(SOLDEINIT) + resultat = self.cr.dictfetchall() + + if resultat[0] : + + if resultat[0]['sum_debit'] == None: + sum_debit = 0 + else: + + sum_debit = resultat[0]['sum_debit'] + if resultat[0]['sum_credit'] == None: + sum_credit = 0 + else: + sum_credit = resultat[0]['sum_credit'] + + move.init_credit = sum_credit + move.init_debit = sum_debit + + else: + move.init_credit = 0 + move.init_debit = 0 + ## + return res def get_min_date(self,form): + ## Get max born from account_fiscal year # - sql = """ select min(fy.date_start) from account_fiscalyear + sql = """ select min(fy.date_start) as start_date,max(fy.date_stop) as stop_date from account_fiscalyear As fy where fy.state <> 'close' """ self.cr.execute(sql) res = self.cr.dictfetchall() - borne_min = res[0]['min'] - # - ## - if form.has_key('fiscalyear'): + borne_min = res[0]['start_date'] + borne_max = res[0]['stop_date'] + if form['state'] == 'byperiod': ## This function will return the most aged date periods = form['periods'][0][2] if not periods: sql = """ - Select min(p.date_start) from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ """ else: periods_id = ','.join(map(str, periods)) sql = """ - Select min(p.date_start) from account_period as p where p.id in ( """ + periods_id + """) + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) """ self.cr.execute(sql) res = self.cr.dictfetchall() - borne_max = res[0]['min'] - else: - borne_max = form['date_from'] - date_borne = { + borne_min = res[0]['start_date'] + borne_max = res[0]['stop_date'] + elif form['state'] == 'bydate': + borne_min = form['date_from'] + borne_max = form['date_to'] + elif form['state'] == 'all': + periods = form['periods'][0][2] + if not periods: + sql = """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ + """ + else: + periods_id = ','.join(map(str, periods)) + sql = """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) + """ + self.cr.execute(sql) + res = self.cr.dictfetchall() + period_min = res[0]['start_date'] + period_max = res[0]['stop_date'] + date_min = form['date_from'] + date_max = form['date_to'] + if period_min='%s' + ORDER by %s"""%(account.id,self.query,self.date_borne['max_date'],self.date_borne['min_date'],sorttag) + self.cr.execute(sql) - res = self.cr.dictfetchall() + + res = self.cr.dictfetchall() + sum = 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') for l in res: diff --git a/addons/account/report/general_ledger.rml b/addons/account/report/general_ledger.rml index 20817dff3f3..fd83bfdecd9 100755 --- a/addons/account/report/general_ledger.rml +++ b/addons/account/report/general_ledger.rml @@ -35,16 +35,15 @@ - + - - + @@ -91,244 +90,86 @@ + [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] - - Date - - - Partner - - - Ref - - - Mvt - - - Entry Label - - - Debit - - - Crebit - - - Balance - + Date + Partner + Ref + Mvt + Entry Label + Debit + Crebit + Balance + [[ repeatIn(objects, 'a') ]] + [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ repeatIn(objects, 'a') ]] - [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - - - - - - - [[ o.code ]] [[ o.name ]] - - - [[ sum_debit_account(o, data['form']) or '0.0' ]] - - - [[sum_credit_account(o, data['form']) or '0.0' ]] - - - [[sum_solde_account(o, data['form']) or '0.0' ]] - - - - - - - [[ data['form']['soldeinit'] == True or removeParentNode('tr') ]] - - - - - - Balance Initial - - - - - - - - - - - - [[ o.init_debit or '0.0' ]] - - - [[ o.init_credit or '0.0' ]] - - - [[ (o.init_debit - o.init_credit) or '0.0' ]] - - - - [[ repeatIn(lines(o, data['form']), 'line') ]] - [[ line['date'] ]] - - - - [[ line['partner'] ]] - - - [[ line['ref'] ]] - - - [[ line['move'] ]] - - - [[ line['name'] ]] - - - [[ line['debit'] and line['debit'] or '0.0' ]] - - - [[ line['credit'] and line['credit'] or '0.0' ]] - - - [[ line['progress'] and line['progress'] or '0.0' ]] - - - - - + + + [[ o.code or '']] [[ o.name or '']] + + [[ sum_debit_account(o, data['form']) or '0.0' ]] + [[sum_credit_account(o, data['form']) or '0.0' ]] + [[sum_solde_account(o, data['form']) or '0.0' ]] + + + + + [[ repeatIn(lines(o, data['form']), 'line') ]] + [[ line['date'] or '' ]] + [[ line['partner'] or '']] + [[ line['ref'] or '']] + [[ line['move'] or '']] + [[ line['name'] or '' ]] + [[ line['debit'] and line['debit'] or '0.0' ]] + [[ line['credit'] and line['credit'] or '0.0' ]] + [[ line['progress'] and line['progress'] or '0.0' ]] - [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] - - - Date - - - Partner - - - Ref - - - Mvt - - - Entry Label - - - Debit - - - Crebit - - - Balance - - - Currency - - + [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] + Date + Partner + Ref + Mvt + Entry Label + Debit + Crebit + Balance + Currency + [[ repeatIn(objects, 'a') ]] - [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - - - - - - - [[ o.code ]] [[ o.name ]] - - - [[ sum_debit_account(o, data['form']) or '0.0' ]] - - - [[sum_credit_account(o, data['form']) or '0.0' ]] - - - [[sum_solde_account(o, data['form']) or '0.0' ]] - - - - [[ sum_currency_amount_account(a, data['form']) or '0.0' ]] - - - - - - [[ data['form']['soldeinit'] == True or removeParentNode('tr') ]] - - - - - - Balance Initial - - - - - - - - - - - - [[ o.init_debit or '0.0' ]] - - - [[ o.init_credit or '0.0' ]] - - - [[ (o.init_debit - o.init_credit) or '0.0' ]] - - - - - + [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] + + + + + [[ o.code or '' ]] [[ o.name or '' ]] + + [[ sum_debit_account(o, data['form']) or '0.0' ]] + [[sum_credit_account(o, data['form']) or '0.0' ]] + [[sum_solde_account(o, data['form']) or '0.0' ]] + [[ sum_currency_amount_account(a, data['form']) or '0.0' ]] + + + - [[ repeatIn(lines(o, data['form']), 'line') ]] - - [[ line['date'] ]] - - - [[ line['partner'] ]] - - - [[ line['ref'] ]] - - - [[ line['move'] ]] - - - [[ line['name'] ]] - - - [[ line['debit'] and line['debit'] or '0.0' ]] - - - [[ line['credit'] and line['credit'] or '0.0' ]] - - - [[ line['progress'] and line['progress'] or '0.0' ]] - - - [[ line['amount_currency'] or '0.0' ]] [[ line['currency_code'] ]] - - - + [[ repeatIn(lines(o, data['form']), 'line') ]] + [[ line['date'] or '' ]] + [[ line['partner'] or '' ]] + [[ line['ref'] or '']] + [[ line['move'] or '' ]] + [[ line['name'] or '' ]] + [[ line['debit'] and line['debit'] or '0.0' ]] + [[ line['credit'] and line['credit'] or '0.0' ]] + [[ line['progress'] and line['progress'] or '0.0' ]] + [[ line['amount_currency'] or '0.0' ]] [[ line['currency_code'] or '']] - - - - + diff --git a/addons/account/report/general_ledger_landscape.py b/addons/account/report/general_ledger_landscape.py index a091ec905dd..3410d1ffc11 100755 --- a/addons/account/report/general_ledger_landscape.py +++ b/addons/account/report/general_ledger_landscape.py @@ -53,6 +53,7 @@ class general_ledger_landscape(rml_parse.rml_parse): def __init__(self, cr, uid, name, context): super(general_ledger_landscape, self).__init__(cr, uid, name, context) + self.date_borne = {} self.query = "" self.child_ids = "" self.tot_currency = 0.0 @@ -106,38 +107,73 @@ class general_ledger_landscape(rml_parse.rml_parse): return result def get_min_date(self,form): + ## Get max born from account_fiscal year # - sql = """ select min(fy.date_start) from account_fiscalyear + sql = """ select min(fy.date_start) as start_date,max(fy.date_stop) as stop_date from account_fiscalyear As fy where fy.state <> 'close' """ self.cr.execute(sql) res = self.cr.dictfetchall() - borne_min = res[0]['min'] - # - ## - if form.has_key('fiscalyear'): + borne_min = res[0]['start_date'] + borne_max = res[0]['stop_date'] + if form['state'] == 'byperiod': ## This function will return the most aged date periods = form['periods'][0][2] if not periods: sql = """ - Select min(p.date_start) from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ """ - else: + else: periods_id = ','.join(map(str, periods)) sql = """ - Select min(p.date_start) from account_period as p where p.id in ( """ + periods_id + """) + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) """ self.cr.execute(sql) res = self.cr.dictfetchall() - borne_max = res[0]['min'] - else: - borne_max = form['date_from'] - date_borne = { + borne_min = res[0]['start_date'] + borne_max = res[0]['stop_date'] + elif form['state'] == 'bydate': + borne_min = form['date_from'] + borne_max = form['date_to'] + elif form['state'] == 'all': + periods = form['periods'][0][2] + if not periods: + sql = """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.fiscalyear_id = """ + str(form['fiscalyear']) + """ + """ + else: + periods_id = ','.join(map(str, periods)) + sql = """ + Select min(p.date_start) as start_date,max(p.date_stop) as stop_date from account_period as p where p.id in ( """ + periods_id + """) + """ + self.cr.execute(sql) + res = self.cr.dictfetchall() + period_min = res[0]['start_date'] + period_max = res[0]['stop_date'] + date_min = form['date_from'] + date_max = form['date_to'] + if period_min='%s' + ORDER by %s"""%(account.id,self.query,self.date_borne['max_date'],self.date_borne['min_date'],sorttag) + self.cr.execute(sql) - res = self.cr.dictfetchall() + + res = self.cr.dictfetchall() sum = 0.0 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line') for l in res: diff --git a/addons/account/report/general_ledger_landscape.rml b/addons/account/report/general_ledger_landscape.rml index 16ddfa9a594..e49f585ae4f 100755 --- a/addons/account/report/general_ledger_landscape.rml +++ b/addons/account/report/general_ledger_landscape.rml @@ -37,9 +37,8 @@ - + - @@ -92,335 +91,93 @@ - - - [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] - + [[ data['form']['amount_currency'] == True or removeParentNode('blockTable') ]] + + Date + JNRL + Partner + Ref + Mvt + Entry Label + Counterpart + Debit + Credit + Balance + Currency + + [[ repeatIn(objects, 'a') ]] + [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] + + + + + [[ o.code ]] [[ o.name ]] + + [[ sum_debit_account(o, data['form']) or '0.0' ]] + [[ sum_credit_account(o, data['form']) or '0.0' ]] + [[ sum_solde_account(o, data['form']) or '0.0' ]] + [[ sum_currency_amount_account(o, data['form']) or '0.0' ]] + + + + + + [[ repeatIn(lines(o, data['form']), 'line') ]] + [[ line['date'] ]] + [[ line['code'] ]] + [[ line['partner'] ]] + [[ line['ref'] ]] + [[ line['move'] ]] + [[ line['name'] ]] + [[ strip_name(line['line_corresp'],55) ]] + [[ line['debit'] and line['debit'] or '0.0' ]] + [[ line['credit'] and line['credit'] or '0.0' ]] + [[ line['progress'] and line['progress'] or '0.0' ]] + [[ line['amount_currency'] or '0.0' ]] [[ line['currency_code'] ]] + + + + [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] + + Date + JNRL + Partner + Ref + Mvt + Entry Label + Counterpart + Debit + Credit + Balance + + [[ repeatIn(objects, 'a') ]] + [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - - Date - - - - JNRL - - - - Partner - - - - Ref - - - - Mvt - - - - Entry Label - - - - Counterpart - - - - Debit - - - - Credit - - - - Balance - - - - Currency - + + + [[ o.code ]] [[ o.name ]] + + [[ sum_debit_account(o, data['form']) or '0.0']] + [[sum_credit_account(o, data['form']) or '0.0']] + [[sum_solde_account(o, data['form']) or '0.0' ]] + + + - - [[ repeatIn(objects, 'a') ]] - [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - - - - - - - - - [[ o.code ]] [[ o.name ]] - - - [[ sum_debit_account(o, data['form']) or '0.0' ]] - - - [[ sum_credit_account(o, data['form']) or '0.0' ]] - - - [[ sum_solde_account(o, data['form']) or '0.0' ]] - - - - [[ sum_currency_amount_account(o, data['form']) or '0.0' ]] - - - - - - [[ data['form']['soldeinit'] == True or removeParentNode('tr') ]] - - Balance Initial - - - - - - - - - - - - - - - - - - - - - - [[ o.init_debit or '0.0' ]] - - - [[ o.init_credit or '0.0' ]] - - - [[ (o.init_debit - o.init_credit) or '0.0' ]] - - - - - + + [[ repeatIn(lines(o, data['form']), 'line') ]] + [[ line['date'] ]] + [[ line['code'] ]] + [[ line['partner'] ]] + [[ line['ref'] ]] + [[ line['move'] ]] + [[ line['name'] ]] + [[ strip_name(line['line_corresp'],55) ]] + [[ line['debit'] and line['debit'] or '0.0' ]] + [[ line['credit'] and line['credit'] or '0.0' ]] + [[ line['progress'] and line['progress'] or '0.0' ]] - - - [[ repeatIn(lines(o, data['form']), 'line') ]] - - - [[ line['date'] ]] - - - [[ line['code'] ]] - - - [[ line['partner'] ]] - - - [[ line['ref'] ]] - - - [[ line['move'] ]] - - - [[ line['name'] ]] - - - [[ strip_name(line['line_corresp'],55) ]] - - - [[ line['debit'] and line['debit'] or '0.0' ]] - - - [[ line['credit'] and line['credit'] or '0.0' ]] - - - [[ line['progress'] and line['progress'] or '0.0' ]] - - - [[ line['amount_currency'] or '0.0' ]] [[ line['currency_code'] ]] - - - - - - - - - - - - - [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] - - - - - - Date - - - - - - JNRL - - - - - - Partner - - - - - - Ref - - - - - - Mvt - - - - - - Entry Label - - - - - - Counterpart - - - - - - Debit - - - - - - Credit - - - - - - Balance - - - - - - [[ repeatIn(objects, 'a') ]] - [[ repeatIn(get_children_accounts(a,data['form']), 'o') ]] - [[ data['form']['amount_currency'] == False or removeParentNode('blockTable') ]] - - - - - [[ o.code ]] [[ o.name ]] - - - [[ sum_debit_account(o, data['form']) or '0.0']] - - - [[sum_credit_account(o, data['form']) or '0.0']] - - - [[sum_solde_account(o, data['form']) or '0.0' ]] - - - - - - [[ data['form']['soldeinit'] == True or removeParentNode('tr') ]] - - - - - - Solde Initial - - - - - - - - - - - - - - - - - - - [[ o.init_debit or '0.0' ]] - - - [[ o.init_credit or '0.0' ]] - - - [[ o.init_debit - o.init_credit or '0.0' ]] - - - - [[ repeatIn(lines(o, data['form']), 'line') ]] - - [[ line['date'] ]] - - - [[ line['code'] ]] - - - [[ line['partner'] ]] - - - [[ line['ref'] ]] - - - [[ line['move'] ]] - - - [[ line['name'] ]] - - - [[ strip_name(line['line_corresp'],55) ]] - - - [[ line['debit'] and line['debit'] or '0.0' ]] - - - [[ line['credit'] and line['credit'] or '0.0' ]] - - - [[ line['progress'] and line['progress'] or '0.0' ]] - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/addons/account/wizard/wizard_general_ledger_report.py b/addons/account/wizard/wizard_general_ledger_report.py index c4a2f2a7438..70f3925aefb 100644 --- a/addons/account/wizard/wizard_general_ledger_report.py +++ b/addons/account/wizard/wizard_general_ledger_report.py @@ -29,31 +29,31 @@ import pooler import locale import time -report_type = ''' -
-
''' - -dates_form = ''' -
- - - - - - - -''' - -dates_fields = { - 'date_from': {'string':"Start date",'type':'date','required':True ,'default': lambda *a: time.strftime('%Y-01-01')}, - 'date_to': {'string':"End date",'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')}, - 'sortbydate':{'string':"Sort by",'type':'selection','selection':[('sort_date','Date'),('sort_mvt','Mouvement')]}, - 'display_account':{'string':"Display accounts ",'type':'selection','selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]}, - 'landscape':{'string':"Print in Landscape Mode",'type':'boolean'}, - 'soldeinit':{'string':"Inclure les soldes initiaux",'type':'boolean'}, - 'amount_currency':{'string':"with amount in currency",'type':'boolean'} - -} +#report_type = ''' +#
+#
''' +# +#dates_form = ''' +#
+# +# +# +# +# +# +# +#''' +# +#dates_fields = { +# 'date_from': {'string':"Start date",'type':'date','required':True ,'default': lambda *a: time.strftime('%Y-01-01')}, +# 'date_to': {'string':"End date",'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')}, +# 'sortbydate':{'string':"Sort by",'type':'selection','selection':[('sort_date','Date'),('sort_mvt','Mouvement')]}, +# 'display_account':{'string':"Display accounts ",'type':'selection','selection':[('bal_mouvement','With movements'),('bal_all','All'),('bal_solde','With balance is not equal to 0')]}, +# 'landscape':{'string':"Print in Landscape Mode",'type':'boolean'}, +# 'soldeinit':{'string':"Inclure les soldes initiaux",'type':'boolean'}, +# 'amount_currency':{'string':"with amount in currency",'type':'boolean'} +# +#} account_form = '''
@@ -69,24 +69,58 @@ account_fields = { period_form = ''' - - - - - - - + + + + +