← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-744789-qdp into lp:openobject-addons

 

qdp (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-744789-qdp into lp:openobject-addons.

Requested reviews:
  Purnendu Singh (OpenERP) (psi-tinyerp)
  Olivier Dony (OpenERP) (odo)
Related bugs:
  Bug #744789 in OpenERP Addons: "[V6] Third party ledger : Initial Balance"
  https://bugs.launchpad.net/openobject-addons/+bug/744789

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-744789-qdp/+merge/58334

in the query_get() of account.move.line, if we don't give any other criteria in the context than the fiscalyear when computing an initial balance then it simply means that the entries returned will be exactly the same as without initial balance, which lead to count the entries twice...

this hack is a little nasty (not so say "a lot nasty"), but i can't think to something else.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-744789-qdp/+merge/58334
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-744789-qdp.
=== modified file 'account/account_move_line.py'
--- account/account_move_line.py	2011-04-25 06:11:14 +0000
+++ account/account_move_line.py	2011-04-28 07:25:56 +0000
@@ -82,17 +82,25 @@
                 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)
         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']))
 

=== modified file 'account/report/account_partner_ledger.py'
--- account/report/account_partner_ledger.py	2011-01-14 00:11:01 +0000
+++ account/report/account_partner_ledger.py	2011-04-28 07:25:56 +0000
@@ -58,10 +58,11 @@
         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')

=== modified file 'account/wizard/account_report_partner_ledger.py'
--- account/wizard/account_report_partner_ledger.py	2011-04-15 10:09:01 +0000
+++ account/wizard/account_report_partner_ledger.py	2011-04-28 07:25:56 +0000
@@ -39,9 +39,22 @@
     }
     _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:

=== modified file 'account/wizard/account_report_partner_ledger_view.xml'
--- account/wizard/account_report_partner_ledger_view.xml	2011-01-14 00:11:01 +0000
+++ account/wizard/account_report_partner_ledger_view.xml	2011-04-28 07:25:56 +0000
@@ -15,12 +15,15 @@
             </xpath>
             <xpath expr="//field[@name='target_move']" position="after">
                 <field name="result_selection"/>
-                <field name="initial_balance"/>
-                <field name="reconcil"/>
+                <field name="initial_balance" attrs="{'readonly':[('filter', '=', 'filter_no')]}" on_change="onchange_initial_balance(initial_balance, reconcil)"/>
+                <field name="reconcil" attrs="{'readonly':[('initial_balance', '=', True)]}" on_change="onchange_initial_balance(initial_balance, reconcil)"/>
                 <field name="amount_currency"/>
                 <field name="page_split"/>
                 <newline/>
             </xpath>
+            <xpath expr="//field[@name='filter']" position="replace">
+                <field name="filter" strint="replaced" on_change="onchange_filter(filter, fiscalyear_id)" colspan="4"/>
+            </xpath>
             </data>
             </field>
         </record>


Follow ups