removed bad code
[odoo/odoo.git] / bin / addons / base / ir / ir_sequence.py
index 9a1fb16..f48ea0f 100644 (file)
@@ -2,7 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution  
-#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 #    $Id$
 #
 #    This program is free software: you can redistribute it and/or modify
@@ -22,6 +22,7 @@
 
 import time
 from osv import fields,osv
+import pooler
 
 class ir_sequence_type(osv.osv):
     _name = 'ir.sequence.type'
@@ -55,17 +56,32 @@ 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('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True FOR UPDATE', (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):