removed bad code
[odoo/odoo.git] / bin / addons / base / ir / ir_sequence.py
index 7eff555..f48ea0f 100644 (file)
@@ -1,34 +1,28 @@
+# -*- encoding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
+#    OpenERP, Open Source Management Solution  
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    $Id$
 #
-# $Id$
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
 #
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
 #
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
 import time
 from osv import fields,osv
+import pooler
 
 class ir_sequence_type(osv.osv):
     _name = 'ir.sequence.type'
@@ -62,21 +56,38 @@ class ir_sequence(osv.osv):
     }
 
     def _process(self, s):
-        return (s or '') % {'year':time.strftime('%Y'), 'month': time.strftime('%m'), 'day':time.strftime('%d')}
+        return (s or '') % {
+            'year':time.strftime('%Y'), 
+            'month': time.strftime('%m'), 
+            'day':time.strftime('%d'),
+            'y': time.strftime('%y'),
+            'doy': time.strftime('%j'),
+            'woy': time.strftime('%W'),
+            'weekday': time.strftime('%w'),
+            'h24': time.strftime('%H'),
+            'h12': time.strftime('%I'),
+            'min': time.strftime('%M'),
+            'sec': time.strftime('%S'),
+        }
 
-    def get_id(self, cr, uid, sequence_id, test='id=%d'):
-        cr.execute('lock table ir_sequence')
-        cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True', (sequence_id,))
-        res = cr.dictfetchone()
-        if res:
-            cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%d and active=True', (res['id'],))
-            if res['number_next']:
-                return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
-            else:
-                return self._process(res['prefix']) + self._process(res['suffix'])
+    def get_id(self, cr, uid, sequence_id, test='id=%s', context=None):
+        try:
+            cr.execute('SELECT id, number_next, prefix, suffix, padding FROM ir_sequence WHERE '+test+' AND active=%s FOR UPDATE', (sequence_id, True))
+            res = cr.dictfetchone()
+            if res:
+                cr.execute('UPDATE ir_sequence SET number_next=number_next+number_increment WHERE id=%s AND active=%s', (res['id'], True))
+                if res['number_next']:
+                    return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
+                else:
+                    return self._process(res['prefix']) + self._process(res['suffix'])
+        finally:
+            cr.commit()
         return False
 
     def get(self, cr, uid, code):
         return self.get_id(cr, uid, code, test='code=%s')
 ir_sequence()
 
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+