[IMP] Improvements in all common classes and also with some reports related with it
bzr revid: mra@mra-laptop-20100714043702-ath5tjx2k8g6hh9n
This commit is contained in:
parent
a090f6ebe9
commit
b0fe8544ce
|
@ -27,10 +27,12 @@ from report import report_sxw
|
|||
from account_journal_common_default import account_journal_common_default
|
||||
|
||||
class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
def __init__(self, cr, uid, name, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
super(partner_balance, self).__init__(cr, uid, name, context=context)
|
||||
self.date_lst = []
|
||||
self.account_ids = False
|
||||
self.account_ids = []
|
||||
self.localcontext.update( {
|
||||
'time': time,
|
||||
'lines': self.lines,
|
||||
|
@ -52,7 +54,7 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
#
|
||||
|
||||
def get_periods(self, form):
|
||||
result=''
|
||||
result = ''
|
||||
if form.has_key('periods') and form['periods']:
|
||||
period_ids = form['periods']
|
||||
per_ids = self.pool.get('account.period').browse(self.cr, self.uid, form['periods'])
|
||||
|
@ -67,9 +69,9 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
len_res = len(res)
|
||||
for r in res:
|
||||
if r == res[len_res-1]:
|
||||
result+=r.name+". "
|
||||
result += r.name + ". "
|
||||
else:
|
||||
result+=r.name+", "
|
||||
result += r.name + ", "
|
||||
return str(result and result[:-1]) or 'ALL'
|
||||
|
||||
def date_range(self, start, end):
|
||||
|
@ -101,14 +103,12 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
self.date_lst = date_array
|
||||
self.date_lst.sort()
|
||||
|
||||
|
||||
def transform_date_into_date_array(self, data):
|
||||
return_array = self.date_range(data['form']['date_from'], data['form']['date_to'])
|
||||
self.date_lst = return_array
|
||||
self.date_lst.sort()
|
||||
|
||||
def transform_none_into_date_array(self, data):
|
||||
|
||||
sql = "SELECT min(date) as start_date from account_move_line"
|
||||
self.cr.execute(sql)
|
||||
start_date = self.cr.fetchone()[0]
|
||||
|
@ -136,7 +136,7 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
else:
|
||||
return self.comma_me(new)
|
||||
|
||||
def set_context(self, objects, data, ids, report_type = None):
|
||||
def set_context(self, objects, data, ids, report_type=None):
|
||||
# Transformation des date
|
||||
#
|
||||
#
|
||||
|
@ -147,9 +147,7 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
elif data['form']['filter'] == 'filter_period':
|
||||
self.transform_period_into_date_array(data)
|
||||
|
||||
|
||||
## Compute Code
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
#
|
||||
if (data['form']['result_selection'] == 'customer' ):
|
||||
self.ACCOUNT_TYPE = ('receivable',)
|
||||
|
@ -166,12 +164,9 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
"WHERE a.type IN %s " \
|
||||
"AND a.active", (self.ACCOUNT_TYPE,))
|
||||
self.account_ids = [a for (a,) in self.cr.fetchall()]
|
||||
|
||||
return super(partner_balance, self).set_context(objects, data, ids, report_type)
|
||||
|
||||
def lines(self,data):
|
||||
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
full_account = []
|
||||
result_tmp = 0.0
|
||||
if self.date_lst:
|
||||
|
@ -340,14 +335,11 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
(tuple(self.account_ids), tuple(self.date_lst)))
|
||||
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
||||
result_tmp = result_tmp + temp_res
|
||||
|
||||
return result_tmp
|
||||
|
||||
def _sum_credit(self, data):
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
|
||||
result_tmp = 0.0
|
||||
temp_res = 0.0
|
||||
if self.date_lst:
|
||||
|
@ -358,14 +350,11 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
"AND l.date IN %s",
|
||||
(tuple(self.account_ids), tuple(self.date_lst),))
|
||||
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
||||
result_tmp = result_tmp + temp_res
|
||||
|
||||
return result_tmp
|
||||
return result_tmp + temp_res
|
||||
|
||||
def _sum_litige(self, data):
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
temp_res = 0.0
|
||||
if self.date_lst:
|
||||
|
@ -377,14 +366,11 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
"AND l.blocked=TRUE ",
|
||||
(tuple(self.account_ids), tuple(self.date_lst),))
|
||||
temp_res = float(self.cr.fetchone()[0] or 0.0)
|
||||
result_tmp = result_tmp + temp_res
|
||||
|
||||
return result_tmp
|
||||
return result_tmp + temp_res
|
||||
|
||||
def _sum_sdebit(self, data):
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
a = 0.0
|
||||
if self.date_lst:
|
||||
|
@ -404,15 +390,11 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
result_tmp = result_tmp + (a or 0.0)
|
||||
else:
|
||||
result_tmp = 0.0
|
||||
|
||||
return result_tmp
|
||||
|
||||
def _sum_scredit(self, data):
|
||||
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
|
||||
result_tmp = 0.0
|
||||
a = 0.0
|
||||
if self.date_lst:
|
||||
|
@ -427,13 +409,11 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
"GROUP BY l.partner_id",
|
||||
(tuple(self.account_ids), tuple(self.date_lst),))
|
||||
a = self.cr.fetchone()[0] or 0.0
|
||||
|
||||
if self.cr.fetchone() != None:
|
||||
result_tmp = result_tmp + (a or 0.0)
|
||||
|
||||
else:
|
||||
result_tmp = 0.0
|
||||
|
||||
return result_tmp
|
||||
|
||||
def _solde_balance_debit(self, data):
|
||||
|
@ -447,8 +427,6 @@ class partner_balance(report_sxw.rml_parse, account_journal_common_default):
|
|||
def _get_currency(self, form):
|
||||
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
|
||||
|
||||
report_sxw.report_sxw('report.account.partner.balance', 'res.partner',
|
||||
'account/report/partner_balance.rml',parser=partner_balance,
|
||||
header=0)
|
||||
report_sxw.report_sxw('report.account.partner.balance', 'res.partner', 'account/report/partner_balance.rml',parser=partner_balance, header=False)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -26,10 +26,11 @@ import datetime
|
|||
import pooler
|
||||
import rml_parse
|
||||
from report import report_sxw
|
||||
from account_journal_common_default import account_journal_common_default
|
||||
|
||||
class third_party_ledger(rml_parse.rml_parse):
|
||||
class third_party_ledger(rml_parse.rml_parse, account_journal_common_default):
|
||||
|
||||
def __init__(self, cr, uid, name, context):
|
||||
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)
|
||||
|
@ -40,7 +41,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
'sum_credit_partner': self._sum_credit_partner,
|
||||
'sum_debit': self._sum_debit,
|
||||
'sum_credit': self._sum_credit,
|
||||
# 'get_company': self._get_company,
|
||||
'get_currency': self._get_currency,
|
||||
'comma_me' : self.comma_me,
|
||||
})
|
||||
|
@ -103,6 +103,7 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
return new
|
||||
else:
|
||||
return self.comma_me(new)
|
||||
|
||||
def special_map(self):
|
||||
string_map = ''
|
||||
for date_string in self.date_lst:
|
||||
|
@ -135,7 +136,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
if self.date_lst:
|
||||
self.date_lst_string = '\'' + '\',\''.join(map(str, self.date_lst)) + '\''
|
||||
#
|
||||
#new_ids = [id for (id,) in self.cr.fetchall()]
|
||||
if data['form']['result_selection'] == 'supplier':
|
||||
self.ACCOUNT_TYPE = ['payable']
|
||||
elif data['form']['result_selection'] == 'customer':
|
||||
|
@ -152,8 +152,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
'WHERE a.type IN %s' \
|
||||
"AND a.active", (tuple(self.ACCOUNT_TYPE), ))
|
||||
self.account_ids = [a for (a,) in self.cr.fetchall()]
|
||||
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
partner_to_use = []
|
||||
|
||||
if self.date_lst and data['form']['soldeinit'] :
|
||||
|
@ -196,7 +194,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
super(third_party_ledger, self).set_context(objects, data, new_ids, report_type)
|
||||
|
||||
def lines(self, partner,data):
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
full_account = []
|
||||
if data['form']['reconcil'] :
|
||||
RECONCILE_TAG = " "
|
||||
|
@ -241,12 +238,9 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
sum = r['debit'] - r['credit']
|
||||
r['progress'] = sum
|
||||
full_account.append(r)
|
||||
|
||||
return full_account
|
||||
|
||||
def _sum_debit_partner(self, partner, data):
|
||||
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
if data['form']['reconcil'] :
|
||||
RECONCILE_TAG = " "
|
||||
|
@ -285,7 +279,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
return result_tmp
|
||||
|
||||
def _sum_credit_partner(self, partner, data):
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
if data['form']['reconcil'] :
|
||||
RECONCILE_TAG = " "
|
||||
|
@ -326,7 +319,6 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
def _sum_debit(self, data):
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
if data['form']['reconcil'] :
|
||||
RECONCILE_TAG = " "
|
||||
|
@ -360,14 +352,11 @@ class third_party_ledger(rml_parse.rml_parse):
|
|||
result_tmp = contemp[0] or 0.0
|
||||
else:
|
||||
result_tmp = result_tmp + 0.0
|
||||
|
||||
return result_tmp
|
||||
|
||||
|
||||
def _sum_credit(self, data):
|
||||
if not self.ids:
|
||||
return 0.0
|
||||
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
|
||||
result_tmp = 0.0
|
||||
if data['form']['reconcil'] :
|
||||
RECONCILE_TAG = " "
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#
|
||||
##############################################################################
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_common_journal_report(osv.osv_memory):
|
||||
_name = 'account.common.journal.report'
|
||||
|
@ -34,7 +33,6 @@ class account_common_journal_report(osv.osv_memory):
|
|||
return result
|
||||
|
||||
def pre_print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
# data['form'].update(self.read(cr, uid, ids, ['sort_selection'])[0])
|
||||
fy_ids = data['form']['fiscalyear_id'] and [data['form']['fiscalyear_id']] or self.pool.get('account.fiscalyear').search(cr, uid, [('state', '=', 'draft')], context=context)
|
||||
period_list = data['form']['periods'] or self.pool.get('account.period').search(cr, uid, [('fiscalyear_id', 'in', fy_ids)], context=context)
|
||||
data['form']['active_ids'] = self.pool.get('account.journal.period').search(cr, uid, [('journal_id', 'in', data['form']['journal_ids']), ('period_id', 'in', period_list)], context=context)
|
||||
|
@ -43,4 +41,4 @@ class account_common_journal_report(osv.osv_memory):
|
|||
|
||||
account_common_journal_report()
|
||||
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -18,25 +18,26 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class account_common_partner_report(osv.osv_memory):
|
||||
_name = 'account.common.partner.report'
|
||||
_description = 'Account Common Partner Report'
|
||||
_inherit = "account.common.report"
|
||||
|
||||
_columns = {
|
||||
'result_selection': fields.selection([('customer','Receivable Accounts'),
|
||||
('supplier','Payable Accounts'),
|
||||
('Suppliers and Customers' ,'Receivable and Payable Accounts')],
|
||||
'Partner', required=True),
|
||||
"Partner's", required=True),
|
||||
}
|
||||
_defaults = {
|
||||
'result_selection' : 'Suppliers and Customers',
|
||||
}
|
||||
}
|
||||
|
||||
def pre_print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
data['form'].update(self.read(cr, uid, ids, ['result_selection'])[0])
|
||||
data['form']['active_ids'] = data['form']['chart_account_id'] # Check me
|
||||
data['form']['query_line'] = query_line
|
||||
|
@ -44,4 +45,4 @@ class account_common_partner_report(osv.osv_memory):
|
|||
|
||||
account_common_partner_report()
|
||||
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -81,17 +81,17 @@ class account_common_report(osv.osv_memory):
|
|||
return res
|
||||
|
||||
def _get_account(self, cr, uid, context=None):
|
||||
tmp = self.pool.get('account.account').search(cr, uid, [], limit=1 )
|
||||
if not tmp:
|
||||
accounts = self.pool.get('account.account').search(cr, uid, [], limit=1 )
|
||||
if not accounts:
|
||||
return False
|
||||
return tmp[0]
|
||||
return accounts[0]
|
||||
|
||||
def _get_fiscalyear(self, cr, uid, context=None):
|
||||
now = time.strftime('%Y-%m-%d')
|
||||
tmp = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 )
|
||||
if not tmp:
|
||||
fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 )
|
||||
if not fiscalyears:
|
||||
return False
|
||||
return tmp[0]
|
||||
return fiscalyears[0]
|
||||
|
||||
def _get_all_journal(self, cr, uid, context=None):
|
||||
return self.pool.get('account.journal').search(cr, uid ,[])
|
||||
|
@ -126,8 +126,6 @@ class account_common_report(osv.osv_memory):
|
|||
raise osv.except_osv(_('Error'),_('Start period should be smaller then End period'))
|
||||
period_date_start = period_obj.read(cr, uid, data['form']['period_from'], ['date_start'])['date_start']
|
||||
period_date_stop = period_obj.read(cr, uid, data['form']['period_to'], ['date_stop'])['date_stop']
|
||||
# result['date_from'] = period_date_start
|
||||
# result['date_to'] = period_date_stop
|
||||
cr.execute('SELECT id FROM account_period WHERE date_start >= %s AND date_stop <= %s', (period_date_start, period_date_stop))
|
||||
result['periods'] = map(lambda x: x[0], cr.fetchall())
|
||||
return result
|
||||
|
@ -142,7 +140,7 @@ class account_common_report(osv.osv_memory):
|
|||
data['ids'] = context.get('active_ids', [])
|
||||
data['model'] = context.get('active_model', 'ir.ui.menu')
|
||||
data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id'])[0]
|
||||
if data['form']['filter'] == 'filter_period': # FIX Me => onchange on period from and to is not working so did this ..but correct it!
|
||||
if data['form']['filter'] == 'filter_period': # FIX Me => on_change on period from and to is not working so did this ..but correct it!
|
||||
start_date = self.onchange_period_from(cr, uid, ids, data['form']['filter'], data['form']['period_from'])
|
||||
end_date = self.onchange_period_to(cr, uid, ids, data['form']['filter'], data['form']['period_to'])
|
||||
data['form']['date_from'] = start_date['value']['date_from']
|
||||
|
@ -157,4 +155,4 @@ class account_common_report(osv.osv_memory):
|
|||
|
||||
account_common_report()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -18,38 +18,33 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import time
|
||||
|
||||
from tools.translate import _
|
||||
from osv import fields, osv
|
||||
|
||||
class account_partner_balance(osv.osv_memory):
|
||||
"""
|
||||
This wizard will provide the partner balance report by periods, between any two dates.
|
||||
This wizard will provide the partner balance report by periods, between any two dates.
|
||||
"""
|
||||
_inherit = 'account.common.partner.report'
|
||||
_name = 'account.partner.balance'
|
||||
_description = 'Print Account Partner Balance'
|
||||
|
||||
_columns = {
|
||||
'soldeinit': fields.boolean('Include initial balances'),
|
||||
'soldeinit': fields.boolean('Include Initial Balances'),
|
||||
}
|
||||
_defaults={
|
||||
'soldeinit' : True,
|
||||
_defaults = {
|
||||
'soldeinit' : True,
|
||||
}
|
||||
|
||||
def _check_date(self, cr, uid, data, context=None):
|
||||
sql = """
|
||||
SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
|
||||
sql = """ SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f Where %s between f.date_start and f.date_stop """
|
||||
cr.execute(sql, (data['form']['date_from'],))
|
||||
res = cr.dictfetchall()
|
||||
if res:
|
||||
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_to'] < res[0]['date_start']):
|
||||
raise osv.except_osv(_('UserError'),_('Date to must be set between %s and %s') % (str(res[0]['date_start']), str(res[0]['date_stop'])))
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
raise osv.except_osv(_('UserError'),_('Date not in a defined fiscal year'))
|
||||
return True
|
||||
|
||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
||||
if context is None:
|
||||
|
@ -57,8 +52,7 @@ class account_partner_balance(osv.osv_memory):
|
|||
data = self.pre_print_report(cr, uid, ids, data, query_line, context=context)
|
||||
data['form'].update(self.read(cr, uid, ids, ['soldeinit'])[0])
|
||||
if data['form']['filter'] == 'filter_date':
|
||||
self._check_date(cr, uid, data, context)
|
||||
data['form']['query_line'] = query_line
|
||||
self._check_date(cr, uid, data, context=context)
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.partner.balance',
|
||||
|
|
|
@ -18,9 +18,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import time
|
||||
|
||||
from tools.translate import _
|
||||
from osv import fields, osv
|
||||
|
||||
class account_partner_ledger(osv.osv_memory):
|
||||
|
@ -36,9 +34,9 @@ class account_partner_ledger(osv.osv_memory):
|
|||
'page_split': fields.boolean('One Partner Per Page'),
|
||||
}
|
||||
_defaults = {
|
||||
'reconcile' : True,
|
||||
'soldeinit' : True,
|
||||
'page_split' : False,
|
||||
'reconcile' : True,
|
||||
'soldeinit' : True,
|
||||
'page_split' : False,
|
||||
}
|
||||
|
||||
def _check_date(self, cr, uid, data, context=None):
|
||||
|
@ -62,7 +60,6 @@ class account_partner_ledger(osv.osv_memory):
|
|||
data['form'].update(self.read(cr, uid, ids, ['soldeinit', 'reconcil', 'page_split'])[0])
|
||||
if data['form']['filter'] == 'filter_date':
|
||||
self._check_date(cr, uid, data, context)
|
||||
data['form']['query_line'] = query_line
|
||||
if data['form']['page_split']:
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
|
@ -76,6 +73,7 @@ class account_partner_ledger(osv.osv_memory):
|
|||
'datas': data,
|
||||
'nodestroy':True,
|
||||
}
|
||||
|
||||
account_partner_ledger()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue