1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21
##############################################################################
23
from osv import osv, fields
24
from osv.orm import except_orm
27
class document_directory(osv.osv):
28
_inherit='document.directory'
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)
35
'versioning':lambda *a:1,
36
'version_regex':lambda *a:'^(.*)(\..*)$',
37
'version_replace':lambda *a:"\\1.vcount\\2"
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:
46
if self._check_duplication(cr,uid,vals,[document.id]):
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)
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
63
result = super(document_file,self).write(cr,uid,ids,vals,context=context)