1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (C) 2004-2011 Pexego Sistemas Informáticos. All Rights Reserved
5
# $Omar Castiñeira Saavedra$
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import osv,fields
24
class sequence(osv.osv):
25
_inherit = "ir.sequence"
27
def _get_code(self,cr,uid,num):
28
keyword=self.pool.get('res.users').browse(cr,uid,uid).company_id.keyword
29
val1 =keyword and keyword[int(num[0])] or num[0]
30
val2 = keyword and keyword[int(num[1])] or num[1]
33
def _process_extend(self,cr,uid,s):
36
'year':time.strftime('%Y'),
37
'month': time.strftime('%m'),
38
'day':time.strftime('%d'),
39
'y': time.strftime('%y'),
40
'doy': time.strftime('%j'),
41
'woy': time.strftime('%W'),
42
'weekday': time.strftime('%w'),
43
'h24': time.strftime('%H'),
44
'h12': time.strftime('%I'),
45
'min': time.strftime('%M'),
46
'sec': time.strftime('%S'),
47
'kw_month': self._get_code(cr,uid,time.strftime('%m')),
48
'kw_year':self._get_code(cr,uid,time.strftime('%y'))
50
def get_id(self, cr, uid, sequence_id, test='id', context=None):
51
assert test in ('code','id')
52
company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)
53
cr.execute('''SELECT id, number_next, prefix, suffix, padding
57
AND (company_id in %%s or company_id is NULL)
58
ORDER BY company_id, id
59
FOR UPDATE NOWAIT''' % test,
60
(sequence_id, tuple(company_ids)))
61
res = cr.dictfetchone()
63
cr.execute('UPDATE ir_sequence SET number_next=number_next+number_increment WHERE id=%s AND active=true', (res['id'],))
64
if res['number_next']:
65
return self._process_extend(cr,uid,res['prefix']) + '%%0%sd' % res['padding'] % res['number_next'] + self._process_extend(cr,uid,res['suffix'])
67
return self._process_extend(cr,uid,res['prefix']) + self._process_extend(cr,uid,res['suffix'])
b'\\ No newline at end of file'