~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to document_extension/document.py

  • Committer: Sbh (Open ERP)
  • Date: 2009-01-16 11:52:23 UTC
  • mto: (3477.2.8 trunk-extra-addons)
  • mto: This revision was merged to the branch mainline in revision 3483.
  • Revision ID: sbh@tinyerp.com-20090116115223-jdbkdcxt1qr0i31k
Add  new module named document_extension still under development

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
import re
 
23
from osv import osv, fields
 
24
from osv.orm import except_orm
 
25
import pooler
 
26
 
 
27
class document_directory(osv.osv):
 
28
    _inherit='document.directory'
 
29
    _columns = {
 
30
        'versioning': fields.boolean('Automatic Versioning'),
 
31
        'version_regex' : fields.char('Reg. Ex.',size=64,require=True),
 
32
        'version_replace': fields.char('Replace',size=64,require=True)
 
33
    }
 
34
    _defaults={
 
35
        'versioning':lambda *a:1,
 
36
        'version_regex':lambda *a:'^(.*)(\..*)$',
 
37
        'version_replace':lambda *a:"\\1.vcount\\2"
 
38
    }
 
39
document_directory()
 
40
class document_file(osv.osv):
 
41
    _inherit = 'ir.attachment'
 
42
    def write(self, cr, uid, ids, vals, context=None):
 
43
        for document in self.browse(cr,uid,ids,context=context):
 
44
            if document.parent_id and document.parent_id.versioning:
 
45
                count=1
 
46
                if  self._check_duplication(cr,uid,vals,[document.id]):
 
47
                         #version code
 
48
                         newname=''
 
49
                         filename=vals.get('datas_fname',False)
 
50
                         temp=vals.get('datas',False)
 
51
                         pattern=document.parent_id.version_regex
 
52
                         replace=document.parent_id.version_replace.replace('count',str(count))
 
53
                         newname=re.sub(pattern,replace, filename)
 
54
 
 
55
                         pool = pooler.get_pool(cr.dbname)
 
56
                         data = self.browse(cr, uid, ids[0], context=context)
 
57
                         if not 'name' in vals :
 
58
                             vals.update({'name':data.name,'datas':temp,'parent_id':data.parent_id.id,'datas_fname':filename})
 
59
                         self.create(cr, uid, vals, context=context)
 
60
                         vals['datas_fname'] = newname
 
61
                         vals['datas']=data.datas
 
62
 
 
63
        result = super(document_file,self).write(cr,uid,ids,vals,context=context)
 
64
        cr.commit()
 
65
        return result
 
66
 
 
67
document_file()