~ubuntu-branches/debian/sid/openerp-server/sid

« back to all changes in this revision

Viewing changes to bin/addons/base/ir/ir_sequence.py

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-02-07 13:33:00 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090207133300-1svab0irxt6lmbvs
Tags: 5.0.0-1
MergingĀ upstreamĀ versionĀ 5.0.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
##############################################################################
3
3
#
4
4
#    OpenERP, Open Source Management Solution   
5
 
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
6
#    $Id$
7
7
#
8
8
#    This program is free software: you can redistribute it and/or modify
69
69
            'sec': time.strftime('%S'),
70
70
        }
71
71
 
72
 
    def get_id(self, cr, uid, sequence_id, test='id=%s'):
73
 
        cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True FOR UPDATE', (sequence_id,))
74
 
        res = cr.dictfetchone()
75
 
        if res:
76
 
            cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%s and active=True', (res['id'],))
77
 
            if res['number_next']:
78
 
                return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
79
 
            else:
80
 
                return self._process(res['prefix']) + self._process(res['suffix'])
 
72
    def get_id(self, cr, uid, sequence_id, test='id=%s', context={}):
 
73
        try:
 
74
            cr.execute('lock table ir_sequence')
 
75
            cr.execute('select id,number_next,number_increment,prefix,suffix,padding from ir_sequence where '+test+' and active=True', (sequence_id,))
 
76
            res = cr.dictfetchone()
 
77
            if res:
 
78
                cr.execute('update ir_sequence set number_next=number_next+number_increment where id=%s and active=True', (res['id'],))
 
79
                if res['number_next']:
 
80
                    return self._process(res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process(res['suffix'])
 
81
                else:
 
82
                    return self._process(res['prefix']) + self._process(res['suffix'])
 
83
        finally:
 
84
            cr.commit()
81
85
        return False
82
86
 
83
87
    def get(self, cr, uid, code):