← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-783123-mtr into lp:openobject-addons

 

Meera Trambadia (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-783123-mtr into lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #783123 in OpenERP Addons: "account chart Fiscal Year Onchange - start and end period is not working for future fiscal year."
  https://bugs.launchpad.net/openobject-addons/+bug/783123

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-783123-mtr/+merge/61962

account: 'Account charts' wizard, now assign start and end period for future fiscal year --fixes lp:783123  
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-783123-mtr/+merge/61962
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-783123-mtr.
=== modified file 'account/wizard/account_chart.py'
--- account/wizard/account_chart.py	2011-03-16 13:28:33 +0000
+++ account/wizard/account_chart.py	2011-05-23 11:48:12 +0000
@@ -19,6 +19,7 @@
 #
 ##############################################################################
 
+import time
 from osv import fields, osv
 
 class account_chart(osv.osv_memory):
@@ -41,27 +42,34 @@
     def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
         res = {}
         res['value'] = {}
+        period_obj = self.pool.get('account.period')
+        fiscalyear_obj = self.pool.get('account.fiscalyear')
         if fiscalyear_id:
             start_period = end_period = False
-            cr.execute('''
-                SELECT * FROM (SELECT p.id
-                               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
-                               LIMIT 1) AS period_start
-                UNION
-                SELECT * FROM (SELECT p.id
-                               FROM account_period p
-                               LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
-                               WHERE f.id = %s
-                               AND p.date_start < NOW()
-                               ORDER BY p.date_stop DESC
-                               LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
-            periods =  [i[0] for i in cr.fetchall()]
-            if periods and len(periods) > 1:
+            fiscalyear = fiscalyear_obj.browse(cr, uid, [fiscalyear_id], context=context)[0]
+            current_start_period = period_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear_id),('date_start', '=', time.strftime('%Y-01-01'))], context=context)
+            if current_start_period:
+                cr.execute('''
+                    SELECT * FROM (SELECT p.id
+                                   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
+                                   LIMIT 1) AS period_start
+                    UNION
+                    SELECT * FROM (SELECT p.id
+                                   FROM account_period p
+                                   LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
+                                   WHERE f.id = %s
+                                   AND p.date_start < NOW()
+                                   ORDER BY p.date_stop DESC
+                                   LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
+                periods =  [i[0] for i in cr.fetchall()]
                 start_period = periods[0]
                 end_period = periods[1]
+            else:
+                start_period = period_obj.search(cr, uid, [('date_start', '=', fiscalyear.date_start)], context=context)[1]
+                end_period = period_obj.search(cr, uid, [('date_stop', '=', fiscalyear.date_stop )], context=context)[0]
             res['value'] = {'period_from': start_period, 'period_to': end_period}
         return res