[IMP] Clean and improvements on all reports & wizards

bzr revid: mra@mra-laptop-20100803042554-gctua4lghmfjk1f4
This commit is contained in:
Mustufa Rangwala 2010-08-03 09:55:54 +05:30
parent ee906a9560
commit 4017f5dc13
11 changed files with 83 additions and 102 deletions

View File

@ -27,14 +27,6 @@ from common_report_header import common_report_header
class account_balance(report_sxw.rml_parse, common_report_header):
_name = 'report.account.account.balance'
def set_context(self, objects, data, ids, report_type=None):
new_ids = ids
if (data['model'] == 'ir.ui.menu'):
new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or []
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
self.query_get_clause = data['form'].get('query_line', False) or ''
return super(account_balance, self).set_context(objects, data, new_ids, report_type=report_type)
def __init__(self, cr, uid, name, context=None):
super(account_balance, self).__init__(cr, uid, name, context=context)
self.sum_debit = 0.00
@ -57,6 +49,14 @@ class account_balance(report_sxw.rml_parse, common_report_header):
})
self.context = context
def set_context(self, objects, data, ids, report_type=None):
new_ids = ids
if (data['model'] == 'ir.ui.menu'):
new_ids = 'chart_account_id' in data['form'] and [data['form']['chart_account_id']] or []
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
self.query_get_clause = data['form'].get('query_line', False) or ''
return super(account_balance, self).set_context(objects, data, new_ids, report_type=report_type)
def _add_header(self, node, header=1):
if header == 0:
self.rml_header = ""

View File

@ -23,9 +23,7 @@ import time
from common_report_header import common_report_header
from report import report_sxw
#
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse, common_report_header):
def __init__(self, cr, uid, name, context=None):
@ -88,16 +86,15 @@ class journal_print(report_sxw.rml_parse, common_report_header):
'FROM account_move_line l '
'LEFT JOIN account_journal j ON (l.journal_id=j.id) '
'LEFT JOIN res_currency c on (l.currency_id=c.id)'
'WHERE period_id=%s AND journal_id IN %s '+self.query_get_clause +''
'GROUP BY j.id, j.code, j.name, l.amount_currency,c.code,l.currency_id ',
'WHERE period_id=%s AND journal_id IN %s ' + self.query_get_clause + ''
'GROUP BY j.id, j.code, j.name, l.amount_currency,c.code, l.currency_id ',
(period_id, tuple(self.journal_ids)))
return self.cr.dictfetchall()
def _set_get_account_currency_code(self, account_id):
self.cr.execute("SELECT c.code AS code "\
"FROM res_currency c, account_account AS ac "\
"WHERE ac.id = %s AND ac.currency_id = c.id" % (account_id))
"FROM res_currency c, account_account AS ac "\
"WHERE ac.id = %s AND ac.currency_id = c.id" % (account_id))
result = self.cr.fetchone()
if result:
self.account_currency = result[0]
@ -105,20 +102,19 @@ class journal_print(report_sxw.rml_parse, common_report_header):
self.account_currency = False
def _get_account(self, data):
if data['model']=='account.journal.period':
if data['model'] == 'account.journal.period':
return self.pool.get('account.journal.period').browse(self.cr, self.uid, data['id']).company_id.name
return super(journal_print ,self)._get_account(data)
def _get_fiscalyear(self, data):
if data['model']=='account.journal.period':
if data['model'] == 'account.journal.period':
return self.pool.get('account.journal.period').browse(self.cr, self.uid, data['id']).fiscalyear_id.name
return super(journal_print ,self)._get_fiscalyear(data)
return super(journal_print, self)._get_fiscalyear(data)
def _display_currency(self, data):
if data['model'] == 'account.journal.period':
return True
return data['form']['amount_currency']
return res
def _sum_debit_period(self, period_id, journal_id=None):
journals = journal_id or self.journal_ids

View File

@ -75,7 +75,6 @@ class general_ledger(rml_parse.rml_parse, common_report_header):
self.context = context
def _sum_currency_amount_account(self, account, form):
#FIXME: not working
self.cr.execute("SELECT sum(l.amount_currency) AS tot_currency "\
"FROM account_move_line l "\
"WHERE l.account_id = %s AND %s" %(account.id, self.query))
@ -84,7 +83,6 @@ class general_ledger(rml_parse.rml_parse, common_report_header):
self.cr.execute("SELECT sum(l.amount_currency) AS tot_currency "\
"FROM account_move_line l "\
"WHERE l.account_id = %s AND %s "%(account.id, form['initial_bal_query']))
# Add initial balance to the result
sum_currency += self.cr.fetchone()[0] or 0.0
return str(sum_currency)
@ -94,7 +92,7 @@ class general_ledger(rml_parse.rml_parse, common_report_header):
for child_account in self.pool.get('account.account').browse(self.cr, self.uid, ids_acc):
sql = """
SELECT count(id)
FROM account_move_line l
FROM account_move_line AS l
WHERE %s AND l.account_id = %%s
""" % (self.query)
self.cr.execute(sql, (child_account.id,))

View File

@ -23,9 +23,7 @@ import time
from common_report_header import common_report_header
from report import report_sxw
#
# Use period and Journal for selection or resources
#
class journal_print(report_sxw.rml_parse, common_report_header):
def __init__(self, cr, uid, name, context=None):
@ -77,9 +75,9 @@ class journal_print(report_sxw.rml_parse, common_report_header):
return obj_mline.browse(self.cr, self.uid, ids)
def _set_get_account_currency_code(self, account_id):
self.cr.execute("SELECT c.code as code "\
"FROM res_currency c,account_account as ac "\
"WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id))
self.cr.execute("SELECT c.code AS code "\
"FROM res_currency c,account_account AS ac "\
"WHERE ac.id = %s AND ac.currency_id = c.id" % (account_id))
result = self.cr.fetchone()
if result:
self.account_currency = result[0]

View File

@ -68,9 +68,9 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods'])
for r in per_ids:
if r == per_ids[len(per_ids)-1]:
result+=r.name+". "
result += r.name + ". "
else:
result+=r.name+", "
result += r.name + ", "
else:
fy_obj = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear'])
res = fy_obj.period_ids
@ -99,13 +99,18 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
def set_context(self, objects, data, ids, report_type=None):
## Compute Code
#
if (data['form']['result_selection'] == 'customer' ):
self.initial_balance = data['form'].get('initial_balance', True)
self.query = data['form'].get('query_line', '')
self.init_query = data['form'].get('initial_bal_query', '')
self.result_selection = data['form'].get('result_selection')
if (self.result_selection == 'customer' ):
self.ACCOUNT_TYPE = ('receivable',)
elif (data['form']['result_selection'] == 'supplier'):
elif (self.result_selection == 'supplier'):
self.ACCOUNT_TYPE = ('payable',)
else:
self.ACCOUNT_TYPE = ('payable', 'receivable')
#
self.cr.execute("SELECT a.id " \
"FROM account_account a " \
"LEFT JOIN account_account_type t " \
@ -113,10 +118,7 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
"WHERE a.type IN %s " \
"AND a.active", (self.ACCOUNT_TYPE,))
self.account_ids = [a for (a,) in self.cr.fetchall()]
self.initial_balance = data['form']['initial_balance'] # for include initial balance
self.query = data['form'].get('query_line', '')
self.init_query = data['form'].get('initial_bal_query', '')
return super(partner_balance, self).set_context(objects, data, ids, report_type)
return super(partner_balance, self).set_context(objects, data, ids, report_type=report_type)
def lines(self, data):
full_account = []
@ -140,7 +142,7 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
"FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
"JOIN account_account ac ON (l.account_id = ac.id)" \
"WHERE ac.type IN %s " \
" AND " + self.query + "" \
"AND " + self.query + "" \
"GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
"ORDER BY l.account_id,p.name",
(self.ACCOUNT_TYPE,))
@ -456,11 +458,11 @@ class partner_balance(report_sxw.rml_parse, common_report_header):
return credit > debit and credit - debit
def _get_partners(self, data):
if data['form']['result_selection'] == 'customer':
if self.result_selection == 'customer':
return 'Receivable Accounts'
elif data['form']['result_selection'] == 'supplier':
elif self.result_selection == 'supplier':
return 'Payable Accounts'
elif data['form']['result_selection'] == 'customer_supplier':
elif self.result_selection == 'customer_supplier':
return 'Receivable and Payable Accounts'
return ''

View File

@ -21,7 +21,6 @@
import time
import re
import datetime
import rml_parse
from report import report_sxw
@ -30,8 +29,6 @@ from common_report_header import common_report_header
class third_party_ledger(rml_parse.rml_parse, common_report_header):
def __init__(self, cr, uid, name, context=None):
self.date_lst = []
self.date_lst_string = ''
super(third_party_ledger, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
@ -58,27 +55,6 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header):
'display_currency':self._display_currency,
})
def comma_me(self, amount):
if type(amount) is float :
amount = str('%.2f'%amount)
else :
amount = str(amount)
if (amount == '0'):
return ' '
orig = amount
new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
if orig == new:
return new
else:
return self.comma_me(new)
def special_map(self):
string_map = ''
for date_string in self.date_lst:
string_map = date_string + ','
return string_map
def set_context(self, objects, data, ids, report_type=None):
self.query = data['form'].get('query_line', '')
self.init_query = data['form'].get('initial_bal_query', '')
@ -91,7 +67,6 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header):
## Si on imprime depuis les partenaires
if ids:
PARTNER_REQUEST = "AND line.partner_id IN %s",(tuple(ids),)
if self.result_selection == 'supplier':
self.ACCOUNT_TYPE = ['payable']
elif self.result_selection == 'customer':
@ -108,7 +83,6 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header):
"AND a.active", (tuple(self.ACCOUNT_TYPE), ))
self.account_ids = [a for (a,) in self.cr.fetchall()]
partner_to_use = []
self.cr.execute(
"SELECT DISTINCT l.partner_id " \
"FROM account_move_line AS l, account_account AS account " \
@ -122,11 +96,25 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header):
res = self.cr.dictfetchall()
for res_line in res:
partner_to_use.append(res_line['partner_id'])
partner_to_use.append(res_line['partner_id'])
new_ids = partner_to_use
self.partner_ids = new_ids
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(third_party_ledger, self).set_context(objects, data, new_ids, report_type)
return super(third_party_ledger, self).set_context(objects, data, new_ids, report_type)
def comma_me(self, amount):
if type(amount) is float :
amount = str('%.2f'%amount)
else :
amount = str(amount)
if (amount == '0'):
return ' '
orig = amount
new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
if orig == new:
return new
else:
return self.comma_me(new)
def lines(self, partner):
full_account = []
@ -162,8 +150,7 @@ class third_party_ledger(rml_parse.rml_parse, common_report_header):
"AND reconcile_id IS NULL " \
"AND " + self.init_query + " ",
(partner.id, tuple(self.account_ids)))
res = self.cr.fetchall()
return res
return self.cr.fetchall()
def _sum_debit_partner(self, partner):
result_tmp = 0.0

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import time
import datetime
from mx.DateTime import *

View File

@ -63,13 +63,13 @@ class account_bs_report(osv.osv_memory):
'type': 'ir.actions.report.xml',
'report_name': 'account.balancesheet.horizontal',
'datas': data,
}
}
else:
return {
'type': 'ir.actions.report.xml',
'report_name': 'account.balancesheet',
'datas': data,
}
}
account_bs_report()

View File

@ -26,7 +26,6 @@ from lxml import etree
from osv import fields, osv
from tools.translate import _
import tools
class account_common_report(osv.osv_memory):
_name = "account.common.report"
@ -82,7 +81,7 @@ class account_common_report(osv.osv_memory):
'journal_ids': _get_all_journal,
'filter': 'filter_no',
'chart_account_id': _get_account,
}
}
def _build_periods(self, cr, uid, period_from, period_to):
period_obj = self.pool.get('account.period')

View File

@ -26,7 +26,7 @@ class account_common_journal_report(osv.osv_memory):
_description = 'Account Common Journal Report'
_inherit = "account.common.report"
_columns = {
'amount_currency': fields.boolean("With Currency", help="It adds the currency column if the currency is different then the company currency"),
'amount_currency': fields.boolean("With Currency", help="Print Report with the currency column if the currency is different then the company currency"),
}
def _build_context(self, cr, uid, ids, data, context=None):

View File

@ -9,31 +9,31 @@
<field name="arch" type="xml">
<form string="Report Options">
<group height="500" width="800">
<field name="chart_account_id" widget='selection'/>
<field name="fiscalyear_id"/>
<group colspan="2" name='Journals'>
<notebook tabpos="up">
<page string="Journals" >
<field name="journal_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
</group>
<group colspan="2" name='Filters'>
<notebook tabpos="up">
<page string="Filters">
<field name="filter" on_change="onchange_filter(filter)" />
<separator string="Dates" colspan="4"/>
<field name="date_from" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<field name="date_to" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<separator string="Periods" colspan="4"/>
<field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
<field name="period_to" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
</page>
</notebook>
</group>
<newline/>
<button icon="gtk-cancel" special="cancel" string="Cancel" colspan="2"/>
<button icon="gtk-print" name="check_report" string="Print" type="object" colspan="2" default_focus="1" />
<field name="chart_account_id" widget='selection'/>
<field name="fiscalyear_id"/>
<group colspan="2" name='Journals'>
<notebook tabpos="up">
<page string="Journals" >
<field name="journal_ids" colspan="4" nolabel="1"/>
</page>
</notebook>
</group>
<group colspan="2" name='Filters'>
<notebook tabpos="up">
<page string="Filters">
<field name="filter" on_change="onchange_filter(filter)" />
<separator string="Dates" colspan="4"/>
<field name="date_from" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<field name="date_to" attrs="{'readonly':[('filter', '!=', 'filter_date')], 'required':[('filter', '=', 'filter_date')]}" colspan="4"/>
<separator string="Periods" colspan="4"/>
<field name="period_from" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
<field name="period_to" domain="[('fiscalyear_id', '=', fiscalyear_id)]" attrs="{'readonly':[('filter','!=','filter_period')], 'required':[('filter', '=', 'filter_period')]}" colspan="4"/>
</page>
</notebook>
</group>
<newline/>
<button icon="gtk-cancel" special="cancel" string="Cancel" colspan="2"/>
<button icon="gtk-print" name="check_report" string="Print" type="object" colspan="2" default_focus="1" />
</group>
</form>
</field>