~pexego/openobject-addons/6.1-pexego-sale_commission

« back to all changes in this revision

Viewing changes to keyword_sequence/sequence.py

  • Committer: Omar (pexego)
  • Date: 2012-07-27 08:40:22 UTC
  • Revision ID: omar@pexego.es-20120727084022-qp3ludpr3vsuyuf6
[ADD] Traceability modules ported to 6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2004-2011 Pexego Sistemas Informáticos. All Rights Reserved
 
5
#    $Omar Castiñeira Saavedra$
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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/>.
 
19
#
 
20
##############################################################################
 
21
import time
 
22
from osv import osv,fields
 
23
 
 
24
class sequence(osv.osv):
 
25
    _inherit = "ir.sequence"
 
26
      
 
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]
 
31
        return val1 + val2
 
32
 
 
33
    def _process_extend(self,cr,uid,s):
 
34
        
 
35
        return (s or '') % {
 
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'))
 
49
        }
 
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
 
54
                      FROM ir_sequence
 
55
                      WHERE %s=%%s
 
56
                       AND active=true
 
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()
 
62
        if res:
 
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'])
 
66
            else:
 
67
                return self._process_extend(cr,uid,res['prefix']) + self._process_extend(cr,uid,res['suffix'])
 
68
        return False
 
69
  
 
70
 
 
71
sequence()
 
 
b'\\ No newline at end of file'