From 4ef3f9218bb97b66b301f84ed49661d3be79a909 Mon Sep 17 00:00:00 2001 From: "Purnendu Singh (OpenERP)" Date: Wed, 3 Oct 2012 15:12:42 +0530 Subject: [IMP] document: add on_change on fname so it will update the download link with the name of attached document bzr revid: psi@tinyerp.com-20121003094242-5wu6pki5cx442jte --- addons/document/document.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 3ae783f49e7..cbc20edc044 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -36,7 +36,6 @@ 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' def _attach_parent_id(self, cr, uid, ids=None, context=None): @@ -149,7 +148,14 @@ 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'): + + 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_duplication(self, cr, uid, vals, ids=[], op='create'): name = vals.get('name', False) parent_id = vals.get('parent_id', False) res_model = vals.get('res_model', False) -- cgit v1.2.3 From 7a41798d7014adca2c2e91d6eac14e8f6562bc4f Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 9 Oct 2012 10:08:58 +0200 Subject: [IMP] mail, document: don't check duplication of file for attachment mail bzr revid: chm@openerp.com-20121009080858-gnpf1893m12jd3mp --- addons/document/document.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 3ae783f49e7..27dde3250e2 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -154,6 +154,7 @@ class document_file(osv.osv): 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: @@ -164,11 +165,11 @@ class document_file(osv.osv): 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)]) + res = self.search(cr, uid, [('id', '<>', file.id), ('name', '=', name), ('parent_id', '=', parent_id), ('res_model', '=', 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)]) + res = self.search(cr, uid, [('name', '=', name), ('parent_id', '=', parent_id), ('res_id', '=', res_id), ('res_model', '=', res_model), ('res_model', '!=', '')]) if len(res): return False return True @@ -219,7 +220,11 @@ 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'): + + # when a user write a mail, there are no model + # don't check the duplication for the mails + res_mail = self.search(cr, uid, [('id', 'in', ids), ('res_model', '=', '')]) + if res!=res_mail and 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 -- cgit v1.2.3 From df873d22a89048ccb67d9f27eea9cbce6970005d Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 10 Oct 2012 12:15:32 +0200 Subject: [FIX] mail: context default value error bzr revid: chm@openerp.com-20121010101532-v2vx6h01x4zeq0ac --- addons/document/document.py | 49 ++------------------------------------------- 1 file changed, 2 insertions(+), 47 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 27dde3250e2..b94222fa11c 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -149,31 +149,6 @@ 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_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), ('res_model', '!=', '')]) - if len(res): - return False - return True - def check(self, cr, uid, ids, mode, context=None, values=None): """Check access wrt. res_model, relax the rule of ir.attachment parent @@ -221,12 +196,6 @@ class document_file(osv.osv): if not len(res): return False - # when a user write a mail, there are no model - # don't check the duplication for the mails - res_mail = self.search(cr, uid, [('id', 'in', ids), ('res_model', '=', '')]) - if res!=res_mail and 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) if (('parent_id' in vals) or ('name' in vals)) and not from_node: @@ -291,22 +260,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 -- cgit v1.2.3 From b2d8a448b47835b744e1defeef257353c6081d12 Mon Sep 17 00:00:00 2001 From: Fabien Pinckaers Date: Wed, 10 Oct 2012 22:18:23 +0200 Subject: [IMP] document names bzr revid: fp@openerp.com-20121010201823-rgv2zv73urxz3ysh --- addons/document/document.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 3ae783f49e7..e2fa2cecd1e 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -36,7 +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): -- cgit v1.2.3