summaryrefslogtreecommitdiff
path: root/addons/document
diff options
context:
space:
mode:
authorVidhin Mehta (OpenERP) <vme@tinyerp.com>2012-10-15 17:03:32 +0530
committerVidhin Mehta (OpenERP) <vme@tinyerp.com>2012-10-15 17:03:32 +0530
commit287b9d09eb740f6adfafdbbc65265f2aecf515ba (patch)
treed0d686830d71c964f03bc69f85c3ef26dec6f006 /addons/document
parent3eb5cfb61b6bbb84043f4fa6b3fdefb0fbb320c7 (diff)
parent7f23ad5de563eacfcae958d0011637800b097d4a (diff)
[MERGE]trunk.
bzr revid: vme@tinyerp.com-20121015113332-i8g3d8na27j08h3l
Diffstat (limited to 'addons/document')
-rw-r--r--addons/document/document.py52
-rw-r--r--addons/document/document_view.xml12
2 files changed, 12 insertions, 52 deletions
diff --git a/addons/document/document.py b/addons/document/document.py
index 3ae783f49e7..37a0219d143 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -36,8 +36,7 @@ DMS_ROOT_PATH = tools.config.get('document_path', os.path.join(tools.config['roo
class document_file(osv.osv):
_inherit = 'ir.attachment'
- _rec_name = 'datas_fname'
-
+ _rec_name = 'name'
def _attach_parent_id(self, cr, uid, ids=None, context=None):
"""Migrate ir.attachments to the document module.
@@ -149,29 +148,12 @@ class document_file(osv.osv):
_sql_constraints = [
# filename_uniq is not possible in pure SQL
]
- def _check_duplication(self, cr, uid, vals, ids=None, op='create'):
- name = vals.get('name', False)
- parent_id = vals.get('parent_id', False)
- res_model = vals.get('res_model', False)
- res_id = vals.get('res_id', 0)
- if op == 'write':
- for file in self.browse(cr, uid, ids): # FIXME fields_only
- if not name:
- name = file.name
- if not parent_id:
- parent_id = file.parent_id and file.parent_id.id or False
- if not res_model:
- res_model = file.res_model and file.res_model or False
- if not res_id:
- res_id = file.res_id and file.res_id or 0
- res = self.search(cr, uid, [('id', '<>', file.id), ('name', '=', name), ('parent_id', '=', parent_id), ('res_model', '=', res_model), ('res_id', '=', res_id)])
- if len(res):
- return False
- if op == 'create':
- res = self.search(cr, uid, [('name', '=', name), ('parent_id', '=', parent_id), ('res_id', '=', res_id), ('res_model', '=', res_model)])
- if len(res):
- return False
- return True
+
+ def onchange_file(self, cr, uid, ids, datas_fname=False, context=None):
+ res = {'value':{}}
+ if datas_fname:
+ res['value'].update({'name': datas_fname})
+ return res
def check(self, cr, uid, ids, mode, context=None, values=None):
"""Check access wrt. res_model, relax the rule of ir.attachment parent
@@ -219,8 +201,6 @@ class document_file(osv.osv):
res = self.search(cr, uid, [('id', 'in', ids)])
if not len(res):
return False
- if not self._check_duplication(cr, uid, vals, ids, 'write'):
- raise osv.except_osv(_('ValidateError'), _('File name must be unique!'))
# if nodes call this write(), they must skip the code below
from_node = context and context.get('__from_node', False)
@@ -286,22 +266,8 @@ class document_file(osv.osv):
else:
if vals.get('file_size'):
del vals['file_size']
- result = self._check_duplication(cr, uid, vals)
- if not result:
- domain = [
- ('res_id', '=', vals['res_id']),
- ('res_model', '=', vals['res_model']),
- ('datas_fname', '=', vals['datas_fname']),
- ]
- attach_ids = self.search(cr, uid, domain, context=context)
- super(document_file, self).write(cr, uid, attach_ids,
- {'datas' : vals['datas']},
- context=context)
- result = attach_ids[0]
- else:
- #raise osv.except_osv(_('ValidateError'), _('File name must be unique!'))
- result = super(document_file, self).create(cr, uid, vals, context)
- return result
+
+ return super(document_file, self).create(cr, uid, vals, context)
def __get_partner_id(self, cr, uid, res_model, res_id, context=None):
""" A helper to retrieve the associated partner from any res_model+id
diff --git a/addons/document/document_view.xml b/addons/document/document_view.xml
index b631583fb27..54776c4d36e 100644
--- a/addons/document/document_view.xml
+++ b/addons/document/document_view.xml
@@ -228,6 +228,9 @@
<field name="priority" eval="1"/>
<field name="inherit_id" ref="base.view_attachment_form"/>
<field name="arch" type="xml">
+ <xpath expr="//field[@name='datas_fname']" position="replace">
+ <field name="datas_fname" invisible="1" on_change="onchange_file(datas_fname)"/>
+ </xpath>
<field name="url" position="after">
<field name="user_id"/>
</field>
@@ -338,15 +341,6 @@
<field name="value" eval="'ir.actions.act_window,%d'%action_document_file_directory_form"/>
</record>
- <record model="ir.ui.view" id="view_attachment_form_inherit">
- <field name="name">ir.attachment.view.inherit</field>
- <field name="model">ir.attachment</field>
- <field name="inherit_id" ref="base.view_attachment_form"/>
- <field name="arch" type="xml">
- <field name="datas_fname" position = "replace" >
- </field>
- </field>
- </record>
<record model="ir.ui.view" id="view_process_node_form_inherit1">
<field name="name">process.node.form</field>