diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index e541a8f7490..9eeea323fb1 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -82,11 +82,14 @@ class account_move_line(osv.osv):
period_ids = fiscalperiod_obj.search(cr, uid, [('id', 'in', context['periods'])], order='date_start', limit=1)
if period_ids and period_ids[0]:
first_period = fiscalperiod_obj.browse(cr, uid, period_ids[0], context=context)
+ where_move_lines_by_date = " AND " +obj+".move_id IN (SELECT id FROM account_move WHERE date < '" +first_period.date_start+"')"
# Find the old periods where date start of those periods less then Start period
periods = fiscalperiod_obj.search(cr, uid, [('date_start', '<', first_period.date_start)])
periods = ','.join([str(x) for x in periods])
if periods:
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND id IN (%s)) %s %s" % (fiscalyear_clause, periods, where_move_state, where_move_lines_by_date)
+ else:
+ query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s)) %s %s" % (fiscalyear_clause, where_move_state, where_move_lines_by_date)
else:
ids = ','.join([str(x) for x in context['periods']])
query = obj+".state <> 'draft' AND "+obj+".period_id IN (SELECT id FROM account_period WHERE fiscalyear_id IN (%s) AND id IN (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date)
@@ -96,7 +99,8 @@ class account_move_line(osv.osv):
if initial_bal and not context.get('periods', False) and not where_move_lines_by_date:
#we didn't pass any filter in the context, and the initial balance can't be computed using only the fiscalyear otherwise entries will be summed twice
#so we have to invalidate this query
- query += " AND 1=2"
+ raise osv.except_osv(_('Warning !'),_("You haven't supplied enough argument to compute the initial balance"))
+
if context.get('journal_ids', False):
query += ' AND '+obj+'.journal_id IN (%s)' % ','.join(map(str, context['journal_ids']))
diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py
index 92d84e05c26..a5c5503b481 100644
--- a/addons/account/report/account_partner_ledger.py
+++ b/addons/account/report/account_partner_ledger.py
@@ -58,10 +58,11 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header):
obj_partner = self.pool.get('res.partner')
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context', {}))
ctx2 = data['form'].get('used_context',{}).copy()
- ctx2.update({'initial_bal': True})
+ self.initial_balance = data['form'].get('initial_balance', True)
+ if self.initial_balance:
+ ctx2.update({'initial_bal': True})
self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx2)
self.reconcil = data['form'].get('reconcil', True)
- self.initial_balance = data['form'].get('initial_balance', True)
self.result_selection = data['form'].get('result_selection', 'customer')
self.amount_currency = data['form'].get('amount_currency', False)
self.target_move = data['form'].get('target_move', 'all')
diff --git a/addons/account/wizard/account_report_partner_ledger.py b/addons/account/wizard/account_report_partner_ledger.py
index 1a09a6344f4..a49751a7da5 100644
--- a/addons/account/wizard/account_report_partner_ledger.py
+++ b/addons/account/wizard/account_report_partner_ledger.py
@@ -39,9 +39,22 @@ class account_partner_ledger(osv.osv_memory):
}
_defaults = {
'reconcil': True,
- 'initial_balance': True,
+ 'initial_balance': False,
'page_split': False,
}
+ def onchange_initial_balance(self, cr, uid, ids, initial_balance=False, reconcil=False, context=None):
+ res = {'value': {}}
+ if initial_balance:
+ res['value'] = {
+ 'reconcil': False
+ }
+ return res
+
+ def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
+ res = super(account_partner_ledger, self).onchange_filter(cr, uid, ids, filter=filter, fiscalyear_id=fiscalyear_id, context=context)
+ if filter == 'filter_no':
+ res['value'].update({'initial_balance': False})
+ return res
def _print_report(self, cr, uid, ids, data, context=None):
if context is None:
diff --git a/addons/account/wizard/account_report_partner_ledger_view.xml b/addons/account/wizard/account_report_partner_ledger_view.xml
index 23c3b6fa97f..fdcb6c59db4 100644
--- a/addons/account/wizard/account_report_partner_ledger_view.xml
+++ b/addons/account/wizard/account_report_partner_ledger_view.xml
@@ -15,12 +15,15 @@
-
-
+
+
+
+
+