diff --git a/addons/account/account.py b/addons/account/account.py
index 6b265f2d52a..f3f1c6308cd 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -879,7 +879,7 @@ class account_period(osv.osv):
_defaults = {
'state': 'draft',
}
- _order = "date_start"
+ _order = "date_start, special desc"
def _check_duration(self,cr,uid,ids,context=None):
obj_period = self.browse(cr, uid, ids[0], context=context)
@@ -960,7 +960,10 @@ class account_period(osv.osv):
raise osv.except_osv(_('Error'), _('You should have chosen periods that belongs to the same company'))
if period_date_start > period_date_stop:
raise osv.except_osv(_('Error'), _('Start period should be smaller then End period'))
- return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)])
+ #for period from = january, we want to exclude the opening period (but it has same date_from, so we have to check if period_from is special or not to include that clause or not in the search).
+ if period_from.special:
+ return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)])
+ return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id), ('special', '=', False)])
account_period()
diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py
index 83a67df9178..8a487fe696d 100644
--- a/addons/account/account_move_line.py
+++ b/addons/account/account_move_line.py
@@ -68,7 +68,6 @@ class account_move_line(osv.osv):
if state:
if state.lower() not in ['all']:
where_move_state= " AND "+obj+".move_id IN (SELECT id FROM account_move WHERE account_move.state = '"+state+"')"
-
if context.get('period_from', False) and context.get('period_to', False) and not context.get('periods', False):
if initial_bal:
period_company_id = fiscalperiod_obj.browse(cr, uid, context['period_from'], context=context).company_id.id
@@ -82,17 +81,20 @@ 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)
- # 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)
+ 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 date_start <= '%s' AND id NOT IN (%s)) %s %s" % (fiscalyear_clause, first_period.date_start, ids, 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)
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)
+ 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
+ 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 52d44d40723..09cb6e689da 100644
--- a/addons/account/report/account_partner_ledger.py
+++ b/addons/account/report/account_partner_ledger.py
@@ -58,10 +58,13 @@ 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.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)
+ 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 = True
+ if data['form']['filter'] == 'unreconciled':
+ self.reconcil = False
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')
@@ -169,7 +172,6 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header):
RECONCILE_TAG = " "
else:
RECONCILE_TAG = "AND l.reconcile_id IS NULL"
-
self.cr.execute(
"SELECT COALESCE(SUM(l.debit),0.0), COALESCE(SUM(l.credit),0.0), COALESCE(sum(debit-credit), 0.0) " \
"FROM account_move_line AS l, " \
diff --git a/addons/account/wizard/account_report_common.py b/addons/account/wizard/account_report_common.py
index 42153c096e6..7aa4c465e0d 100644
--- a/addons/account/wizard/account_report_common.py
+++ b/addons/account/wizard/account_report_common.py
@@ -56,7 +56,7 @@ class account_common_report(osv.osv_memory):
return res
def onchange_filter(self, cr, uid, ids, filter='filter_no', fiscalyear_id=False, context=None):
- res = {}
+ res = {'value': {}}
if filter == 'filter_no':
res['value'] = {'period_from': False, 'period_to': False, 'date_from': False ,'date_to': False}
if filter == 'filter_date':
@@ -68,7 +68,7 @@ class account_common_report(osv.osv_memory):
FROM account_period p
LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
WHERE f.id = %s
- ORDER BY p.date_start ASC
+ ORDER BY p.date_start ASC, p.special ASC
LIMIT 1) AS period_start
UNION
SELECT * FROM (SELECT p.id
diff --git a/addons/account/wizard/account_report_general_ledger.py b/addons/account/wizard/account_report_general_ledger.py
index 1e17a66dd85..ed75b3c1dce 100644
--- a/addons/account/wizard/account_report_general_ledger.py
+++ b/addons/account/wizard/account_report_general_ledger.py
@@ -28,8 +28,8 @@ class account_report_general_ledger(osv.osv_memory):
_columns = {
'landscape': fields.boolean("Landscape Mode"),
- 'initial_balance': fields.boolean("Include Initial Balances",
- help='It adds initial balance row on report which display previous sum amount of debit/credit/balance'),
+ 'initial_balance': fields.boolean('Include Initial Balances',
+ help='If you selected to filter by date or period, this field allow you to add a row to display the amount of debit/credit/balance that precedes the filter you\'ve set.'),
'amount_currency': fields.boolean("With Currency", help="It adds the currency column if the currency is different then the company currency"),
'sortby': fields.selection([('sort_date', 'Date'), ('sort_journal_partner', 'Journal & Partner')], 'Sort by', required=True),
}
diff --git a/addons/account/wizard/account_report_general_ledger_view.xml b/addons/account/wizard/account_report_general_ledger_view.xml
index 671d66b81bb..b4203134fd6 100644
--- a/addons/account/wizard/account_report_general_ledger_view.xml
+++ b/addons/account/wizard/account_report_general_ledger_view.xml
@@ -17,10 +17,12 @@
-
+
+
+
diff --git a/addons/account/wizard/account_report_partner_ledger.py b/addons/account/wizard/account_report_partner_ledger.py
index 590ba80bd02..20a839d218f 100644
--- a/addons/account/wizard/account_report_partner_ledger.py
+++ b/addons/account/wizard/account_report_partner_ledger.py
@@ -31,23 +31,27 @@ class account_partner_ledger(osv.osv_memory):
_columns = {
'initial_balance': fields.boolean('Include Initial Balances',
- help='It adds initial balance row on report which display previous sum amount of debit/credit/balance'),
- 'reconcil': fields.boolean('Include Reconciled Entries', help='Consider reconciled entries'),
- 'page_split': fields.boolean('One Partner per Page', help='Display Ledger Report with One partner per page'),
+ help='If you selected to filter by date or period, this field allow you to add a row to display the amount of debit/credit/balance that precedes the filter you\'ve set.'),
+ 'filter': fields.selection([('filter_no', 'No Filters'), ('filter_date', 'Date'), ('filter_period', 'Periods'), ('unreconciled', 'Unreconciled Entries')], "Filter by", required=True),
+ 'page_split': fields.boolean('One Partner Per Page', help='Display Ledger Report with One partner per page'),
'amount_currency': fields.boolean("With Currency", help="It adds the currency column if the currency is different then the company currency"),
-
}
_defaults = {
- 'reconcil': True,
- 'initial_balance': True,
+ 'initial_balance': False,
'page_split': False,
}
+ 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 in ['filter_no', 'unreconciled']:
+ res['value'].update({'initial_balance': False, 'period_from': False, 'period_to': False, 'date_from': False ,'date_to': False})
+ return res
+
def _print_report(self, cr, uid, ids, data, context=None):
if context is None:
context = {}
data = self.pre_print_report(cr, uid, ids, data, context=context)
- data['form'].update(self.read(cr, uid, ids, ['initial_balance', 'reconcil', 'page_split', 'amount_currency'])[0])
+ data['form'].update(self.read(cr, uid, ids, ['initial_balance', 'filter', 'page_split', 'amount_currency'])[0])
if data['form']['page_split']:
return {
'type': 'ir.actions.report.xml',
@@ -62,4 +66,4 @@ class account_partner_ledger(osv.osv_memory):
account_partner_ledger()
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/account/wizard/account_report_partner_ledger_view.xml b/addons/account/wizard/account_report_partner_ledger_view.xml
index 23c3b6fa97f..97dcdf8d3f2 100644
--- a/addons/account/wizard/account_report_partner_ledger_view.xml
+++ b/addons/account/wizard/account_report_partner_ledger_view.xml
@@ -15,12 +15,14 @@
-
-
+
+
+
+