From 26e21b097e151c1d93aea77049ca5eab2758728a Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Tue, 19 Apr 2011 17:34:59 +0200 Subject: [PATCH 1/4] [FIX] account: fix error on initial balance if we don't give any criteria lp bug: https://launchpad.net/bugs/744789 fixed bzr revid: qdp-launchpad@openerp.com-20110419153459-fpd1zitw5ud3lzct --- addons/account/account_move_line.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 83a67df9178..e541a8f7490 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -93,6 +93,10 @@ class account_move_line(osv.osv): 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 + query += " AND 1=2" if context.get('journal_ids', False): query += ' AND '+obj+'.journal_id IN (%s)' % ','.join(map(str, context['journal_ids'])) From 62e9299b2bd705eec64e13231e1aa2bf75fe5c3d Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Thu, 28 Apr 2011 12:50:58 +0530 Subject: [PATCH 2/4] [FIX] account: Third Party ledger problem with Initial Balance lp bug: https://launchpad.net/bugs/744789 fixed bzr revid: psi@tinyerp.co.in-20110428072058-q0n8y4k01t74pe7z --- addons/account/account_move_line.py | 6 +++++- addons/account/report/account_partner_ledger.py | 5 +++-- .../wizard/account_report_partner_ledger.py | 15 ++++++++++++++- .../wizard/account_report_partner_ledger_view.xml | 7 +++++-- 4 files changed, 27 insertions(+), 6 deletions(-) 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 @@ - - + + + + + From ee0f98590e521a1cfa90e3b846aab8d11dc11508 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Wed, 4 May 2011 16:52:33 +0200 Subject: [PATCH 3/4] [FIX] account: improved order of account_period in order to have the period for opening entries first and fixed in common report wizard the bug that was selecting entries from opening period too when we were printing entries from january to march (because of same date_start for january and opening period). Also fixed the query_get when giving the periods directly in the context (previously it was doing a very weird thing with the clause where_move_lines_by_date defined again and it was not compliant with the opening period new change) bzr revid: qdp-launchpad@openerp.com-20110504145233-icq3a40l9pahy7hm --- addons/account/account.py | 7 +++++-- addons/account/account_move_line.py | 10 +--------- addons/account/wizard/account_report_common.py | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index c11d7394100..a6e83308385 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) @@ -961,7 +961,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 9eeea323fb1..8d920f12db3 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,14 +81,7 @@ 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) + 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, tuple(context['periods']), 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) diff --git a/addons/account/wizard/account_report_common.py b/addons/account/wizard/account_report_common.py index 7a8a0365208..6784e44f779 100644 --- a/addons/account/wizard/account_report_common.py +++ b/addons/account/wizard/account_report_common.py @@ -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 From 887afe33840e1bbd23a694369108fc149ad7101d Mon Sep 17 00:00:00 2001 From: "psi (Open ERP)" Date: Fri, 6 May 2011 11:57:58 +0530 Subject: [PATCH 4/4] [IMP] Add Unreconciled Entries as fourth selection ooption in Filter bzr revid: psi@tinyerp.co.in-20110506062758-6nd4styq6xqojrok --- addons/account/account_move_line.py | 4 +++- addons/account/report/account_partner_ledger.py | 5 +++-- addons/account/wizard/account_report_common.py | 2 +- .../wizard/account_report_partner_ledger.py | 16 ++++------------ .../account_report_partner_ledger_view.xml | 3 +-- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 8d920f12db3..8a487fe696d 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -81,7 +81,8 @@ 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) - 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, tuple(context['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) @@ -93,6 +94,7 @@ class account_move_line(osv.osv): #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 a5c5503b481..d6f1416f920 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -62,7 +62,9 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): 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.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') @@ -170,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 6784e44f779..040e10b6916 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': diff --git a/addons/account/wizard/account_report_partner_ledger.py b/addons/account/wizard/account_report_partner_ledger.py index a49751a7da5..f5b757c8f23 100644 --- a/addons/account/wizard/account_report_partner_ledger.py +++ b/addons/account/wizard/account_report_partner_ledger.py @@ -32,35 +32,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'), + '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': 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}) + 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', diff --git a/addons/account/wizard/account_report_partner_ledger_view.xml b/addons/account/wizard/account_report_partner_ledger_view.xml index fdcb6c59db4..8862bd36013 100644 --- a/addons/account/wizard/account_report_partner_ledger_view.xml +++ b/addons/account/wizard/account_report_partner_ledger_view.xml @@ -15,8 +15,7 @@ - - +