From 6eef5d7e360353c60a56d0b1ab4c3484f80059d8 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Sun, 27 Jun 2010 23:18:09 +0300 Subject: Document: rearrange columns definition of document.file Note: *must* use the server as patched, for the 'url' and 'type' columns. bzr revid: p_christ@hol.gr-20100627201809-p5wy2w368gqoyy3h --- addons/document/document.py | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index aa893b617c3..c5315bf0574 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -72,33 +72,32 @@ class document_file(osv.osv): return res _columns = { + # Columns from ir.attachment: + 'create_date': fields.datetime('Date Created', readonly=True), + 'create_uid': fields.many2one('res.users', 'Creator', readonly=True), + 'write_date': fields.datetime('Date Modified', readonly=True), + 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True), + 'res_model': fields.char('Attached Model', size=64), # readonly? + 'res_id': fields.integer('Attached ID'), + + # If ir.attachment contained any data before document is installed, preserve + # the data, don't drop the column! + 'db_datas': fields.binary('Data', oldname='datas'), + 'datas': fields.function(_data_get, method=True, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True), + + # Fields of document: 'user_id': fields.many2one('res.users', 'Owner', select=1), 'group_ids': fields.many2many('res.groups', 'document_group_rel', 'item_id', 'group_id', 'Groups'), # the directory id now is mandatory. It can still be computed automatically. 'parent_id': fields.many2one('document.directory', 'Directory', select=1), - 'file_size': fields.integer('File Size', required=True), - 'file_type': fields.char('Content Type', size=128), - # If ir.attachment contained any data before document is installed, preserve - # the data, don't drop the column! - 'db_datas': fields.binary('Data', oldname='datas'), 'index_content': fields.text('Indexed Content'), - 'write_date': fields.datetime('Date Modified', readonly=True), - 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True), - 'create_date': fields.datetime('Date Created', readonly=True), - 'create_uid': fields.many2one('res.users', 'Creator', readonly=True), - 'store_method': fields.selection([('db', 'Database'), ('fs', 'Filesystem'), ('link', 'Link')], "Storing Method"), - 'datas': fields.function(_data_get, method=True, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True), - 'url': fields.char('File URL',size=64), - 'store_fname': fields.char('Stored Filename', size=200), - 'res_model': fields.char('Attached Model', size=64), #res_model - 'res_id': fields.integer('Attached ID'), #res_id 'partner_id':fields.many2one('res.partner', 'Partner', select=1), - 'type':fields.selection([ - ('url','URL'), - ('binary','Binary'), - - ],'Type', help="Type is used to separate URL and binary File"), 'company_id': fields.many2one('res.company', 'Company'), + 'file_size': fields.integer('File Size', required=True), + 'file_type': fields.char('Content Type', size=128), + + # fields used for file storage + 'store_fname': fields.char('Stored Filename', size=200), } def __get_def_directory(self, cr, uid, context=None): @@ -109,8 +108,6 @@ class document_file(osv.osv): 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'ir.attachment', context=c), 'user_id': lambda self, cr, uid, ctx:uid, 'file_size': lambda self, cr, uid, ctx:0, - 'store_method': lambda *args: 'db', - 'type': 'binary', 'parent_id': __get_def_directory } _sql_constraints = [ -- cgit v1.2.3 From c11ad0047d1c6da4592c161e2e4a1ed6a5ad07c2 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Sun, 27 Jun 2010 23:18:13 +0300 Subject: Document: files are required to have a parent directory Or else, there is no storage for them. bzr revid: p_christ@hol.gr-20100627201813-y5gatb8w39jnxeux --- 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 c5315bf0574..dd48f7daf7f 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -89,7 +89,7 @@ class document_file(osv.osv): 'user_id': fields.many2one('res.users', 'Owner', select=1), 'group_ids': fields.many2many('res.groups', 'document_group_rel', 'item_id', 'group_id', 'Groups'), # the directory id now is mandatory. It can still be computed automatically. - 'parent_id': fields.many2one('document.directory', 'Directory', select=1), + 'parent_id': fields.many2one('document.directory', 'Directory', select=1, required=True), 'index_content': fields.text('Indexed Content'), 'partner_id':fields.many2one('res.partner', 'Partner', select=1), 'company_id': fields.many2one('res.company', 'Company'), -- cgit v1.2.3 From 85dc0b2fc6b86e54ad8449ff0da5e96550009b77 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Sun, 27 Jun 2010 23:18:57 +0300 Subject: Document: remove the ir.attachment.group_ids column At the review, it was decided that per document permissions is too much. bzr revid: p_christ@hol.gr-20100627201857-e0sw2sun1ttvnj32 --- 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 dd48f7daf7f..ec6c159f2b7 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -87,7 +87,7 @@ class document_file(osv.osv): # Fields of document: 'user_id': fields.many2one('res.users', 'Owner', select=1), - 'group_ids': fields.many2many('res.groups', 'document_group_rel', 'item_id', 'group_id', 'Groups'), + # 'group_ids': fields.many2many('res.groups', 'document_group_rel', 'item_id', 'group_id', 'Groups'), # the directory id now is mandatory. It can still be computed automatically. 'parent_id': fields.many2one('document.directory', 'Directory', select=1, required=True), 'index_content': fields.text('Indexed Content'), -- cgit v1.2.3 From 514f433c59e6778afad469a55d032e1e3da435a0 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 29 Jun 2010 17:00:40 +0300 Subject: Document: ir.attachment.res_model and res_id should be readonly for UI Changing them would require a wizard or something. bzr revid: p_christ@hol.gr-20100629140040-am61qng5pxfz2dxs --- addons/document/document.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index ec6c159f2b7..fb69b84e6a5 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -77,8 +77,8 @@ class document_file(osv.osv): 'create_uid': fields.many2one('res.users', 'Creator', readonly=True), 'write_date': fields.datetime('Date Modified', readonly=True), 'write_uid': fields.many2one('res.users', 'Last Modification User', readonly=True), - 'res_model': fields.char('Attached Model', size=64), # readonly? - 'res_id': fields.integer('Attached ID'), + 'res_model': fields.char('Attached Model', size=64, readonly=True), + 'res_id': fields.integer('Attached ID', readonly=True), # If ir.attachment contained any data before document is installed, preserve # the data, don't drop the column! -- cgit v1.2.3 From 11c5171326d8eba7d897843ab3182878ac3cdb8f Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:31 +0300 Subject: Draft api for document.write(parent_id: ...) If the parent directory for some document node changes, we may have a major change in the stored content, so an API is needed for that. Conflicts: document/nodes.py bzr revid: p_christ@hol.gr-20100701175131-ldt3b0er5a7tja0u --- addons/document/document.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index fb69b84e6a5..27bd9aa3520 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -28,6 +28,7 @@ import os import pooler import netsvc +from osv.orm import except_orm #import StringIO from psycopg2 import Binary @@ -153,7 +154,30 @@ class document_file(osv.osv): return False if not self._check_duplication(cr, uid, vals, ids, 'write'): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) - result = super(document_file, self).write(cr, uid, ids, vals, context=context) + if 'parent_id' in vals: + # perhaps this file is changing directory + nctx = nodes.get_node_context(cr,uid,context) + dirobj = self.pool.get('document.directory') + dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context) + ids2 = [] + result = False + for fbro in self.browse(cr, uid, ids, context=context): + if fbro.parent_id != vals['parent_id']: + fnode = nodes.node_file(None,None,nctx,fbro) + res = fnode.move_to(cr, fbro, dbro, True) + if isinstance(res, dict): + vals2 = vals.copy() + vals2.update(res) + wid = res.get('id', fbro.id) + result = super(document_file,self).write(cr,uid,wid,vals2,context=context) + # TODO: how to handle/merge several results? + elif res == True: + ids2.append(fbro.id) + elif res == False: + pass + ids = ids2 + if len(ids): + result = super(document_file,self).write(cr, uid, ids, vals, context=context) cr.commit() return result -- cgit v1.2.3 From 530932640babacde4973fd47f2a9632c1d70bd3d Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:32 +0300 Subject: Document: fix setting parent of document_file. There is some code that calls the 'move_to()' in case the document's parent (aka. directory) is changed. Fix notation there. bzr revid: p_christ@hol.gr-20100701175132-8ex94b3pdwkz4lq6 --- addons/document/document.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 27bd9aa3520..428425be930 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -120,7 +120,7 @@ class document_file(osv.osv): 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): + for file in self.browse(cr, uid, ids): # FIXME fields_only if not name: name = file.name if not parent_id: @@ -162,7 +162,7 @@ class document_file(osv.osv): ids2 = [] result = False for fbro in self.browse(cr, uid, ids, context=context): - if fbro.parent_id != vals['parent_id']: + if fbro.parent_id.id != vals['parent_id']: fnode = nodes.node_file(None,None,nctx,fbro) res = fnode.move_to(cr, fbro, dbro, True) if isinstance(res, dict): -- cgit v1.2.3 From 2c5082001e8d6379fa36dd34cf070575ffcb31b1 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:33 +0300 Subject: Document: use the new move_to() api, protect setting of file_size. bzr revid: p_christ@hol.gr-20100701175133-9prni6r0kspt27ku --- addons/document/document.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 428425be930..221c9680aa7 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -159,12 +159,13 @@ class document_file(osv.osv): nctx = nodes.get_node_context(cr,uid,context) dirobj = self.pool.get('document.directory') dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context) + dnode = nctx.get_dir_node(cr, dbro) ids2 = [] result = False for fbro in self.browse(cr, uid, ids, context=context): if fbro.parent_id.id != vals['parent_id']: - fnode = nodes.node_file(None,None,nctx,fbro) - res = fnode.move_to(cr, fbro, dbro, True) + fnode = nctx.get_file_node(cr, fbro) + res = fnode.move_to(cr, dnode, fbro, dbro, True) if isinstance(res, dict): vals2 = vals.copy() vals2.update(res) @@ -176,9 +177,11 @@ class document_file(osv.osv): elif res == False: pass ids = ids2 + if 'file_size' in vals: # only write that field using direct SQL calls + del vals['file_size'] if len(ids): result = super(document_file,self).write(cr, uid, ids, vals, context=context) - cr.commit() + cr.commit() # ? return result def create(self, cr, uid, vals, context=None): @@ -219,11 +222,15 @@ class document_file(osv.osv): else: datas = vals.get('datas', False) - vals['file_size'] = datas and len(datas) or 0 + if datas: + vals['file_size'] = len(datas) + else: + if vals.get('file_size'): + del vals['file_size'] if not self._check_duplication(cr, uid, vals): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) result = super(document_file, self).create(cr, uid, vals, context) - cr.commit() + cr.commit() # ? return result def unlink(self, cr, uid, ids, context={}): -- cgit v1.2.3 From c9f313dc218d1164f7133af2b4e3a7b8261110c6 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 1 Jul 2010 20:51:33 +0300 Subject: Document: isolate the partner_id auto-detection in a fn() When a document is created, some code tries to auto-detect the related partner_id from res_model. This should better be put in a function, and reused in other places. bzr revid: p_christ@hol.gr-20100701175133-6aq2tx9lkuskvedh --- addons/document/document.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 221c9680aa7..dbd4ec3f5b0 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -194,26 +194,10 @@ class document_file(osv.osv): vals['res_id'] = context.get('default_res_id', False) if not vals.get('res_model', False) and context.get('default_res_model', False): vals['res_model'] = context.get('default_res_model', False) - if vals.get('res_id', False) and vals.get('res_model', False): - obj_model = self.pool.get(vals['res_model']) - result = obj_model.read(cr, uid, [vals['res_id']], ['name', 'partner_id', 'address_id'], context=context) - if len(result): - obj = result[0] - if obj_model._name == 'res.partner': - vals['partner_id'] = obj['id'] - elif obj.get('address_id', False): - if isinstance(obj['address_id'], tuple) or isinstance(obj['address_id'], list): - address_id = obj['address_id'][0] - else: - address_id = obj['address_id'] - address = self.pool.get('res.partner.address').read(cr, uid, [address_id], context=context) - if len(address): - vals['partner_id'] = address[0]['partner_id'][0] or False - elif obj.get('partner_id', False): - if isinstance(obj['partner_id'], tuple) or isinstance(obj['partner_id'], list): - vals['partner_id'] = obj['partner_id'][0] - else: - vals['partner_id'] = obj['partner_id'] + if vals.get('res_id', False) and vals.get('res_model', False) \ + and not vals.get('partner_id', False): + vals['partner_id'] = __get_partner_id(cr, uid, \ + vals['res_model'], vals['res_id'], context) datas = None if vals.get('link', False) : @@ -233,6 +217,23 @@ class document_file(osv.osv): cr.commit() # ? return result + def __get_partner_id(self, cr, uid, res_model, res_id, context): + """ A helper to retrieve the associated partner from any res_model+id + It is a hack that will try to discover if the mentioned record is + clearly associated with a partner record. + """ + if False: + obj_model = self.pool.get(vals['res_model']) + if obj_model._name == 'res.partner': + return res_id + elif 'partner_id' in obj_model._columns and obj_model._columns['partner_id']._obj == 'res.partner': + bro = obj_model.browse(self, cr, uid, res_id, context=context) + return bro.partner_id.id + elif 'address_id' in obj_model._columns and obj_model._columns['address_id']._obj == 'res.partner.address': + bro = obj_model.browse(self, cr, uid, res_id, context=context) + return bro.address_id.partner_id.id + return False + def unlink(self, cr, uid, ids, context={}): stor = self.pool.get('document.storage') unres = [] -- cgit v1.2.3 From e8bf4a4f18fe70d52192f8893105ba9291abef4a Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Tue, 6 Jul 2010 15:10:45 +0300 Subject: Document: fix the get_partner_id functionality Was blocking document.create() bzr revid: p_christ@hol.gr-20100706121045-mblekyw8nlkiy1r0 --- addons/document/document.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index dbd4ec3f5b0..3dc84529d8d 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -196,7 +196,7 @@ class document_file(osv.osv): vals['res_model'] = context.get('default_res_model', False) if vals.get('res_id', False) and vals.get('res_model', False) \ and not vals.get('partner_id', False): - vals['partner_id'] = __get_partner_id(cr, uid, \ + vals['partner_id'] = self.__get_partner_id(cr, uid, \ vals['res_model'], vals['res_id'], context) datas = None @@ -222,16 +222,15 @@ class document_file(osv.osv): It is a hack that will try to discover if the mentioned record is clearly associated with a partner record. """ - if False: - obj_model = self.pool.get(vals['res_model']) - if obj_model._name == 'res.partner': - return res_id - elif 'partner_id' in obj_model._columns and obj_model._columns['partner_id']._obj == 'res.partner': - bro = obj_model.browse(self, cr, uid, res_id, context=context) - return bro.partner_id.id - elif 'address_id' in obj_model._columns and obj_model._columns['address_id']._obj == 'res.partner.address': - bro = obj_model.browse(self, cr, uid, res_id, context=context) - return bro.address_id.partner_id.id + obj_model = self.pool.get(res_model) + if obj_model._name == 'res.partner': + return res_id + elif 'partner_id' in obj_model._columns and obj_model._columns['partner_id']._obj == 'res.partner': + bro = obj_model.browse(self, cr, uid, res_id, context=context) + return bro.partner_id.id + elif 'address_id' in obj_model._columns and obj_model._columns['address_id']._obj == 'res.partner.address': + bro = obj_model.browse(self, cr, uid, res_id, context=context) + return bro.address_id.partner_id.id return False def unlink(self, cr, uid, ids, context={}): -- cgit v1.2.3 From 0d6e0a9a0286a0b240e77f47f3b8b36aaaa2b1b9 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Fri, 9 Jul 2010 11:23:16 +0300 Subject: Document: support Moving of files. bzr revid: p_christ@hol.gr-20100709082316-d8qedrjabckypt88 --- addons/document/document.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'addons/document/document.py') diff --git a/addons/document/document.py b/addons/document/document.py index 3dc84529d8d..6ab6cae5281 100644 --- a/addons/document/document.py +++ b/addons/document/document.py @@ -154,32 +154,39 @@ class document_file(osv.osv): return False if not self._check_duplication(cr, uid, vals, ids, 'write'): raise osv.except_osv(_('ValidateError'), _('File name must be unique!')) - if 'parent_id' in vals: - # perhaps this file is changing directory + if ('parent_id' in vals) or ('name' in vals): + # perhaps this file is renaming or changing directory nctx = nodes.get_node_context(cr,uid,context) dirobj = self.pool.get('document.directory') - dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context) - dnode = nctx.get_dir_node(cr, dbro) + if 'parent_id' in vals: + dbro = dirobj.browse(cr, uid, vals['parent_id'], context=context) + dnode = nctx.get_dir_node(cr, dbro) + else: + dbro = None + dnode = None ids2 = [] result = False for fbro in self.browse(cr, uid, ids, context=context): - if fbro.parent_id.id != vals['parent_id']: - fnode = nctx.get_file_node(cr, fbro) - res = fnode.move_to(cr, dnode, fbro, dbro, True) - if isinstance(res, dict): - vals2 = vals.copy() - vals2.update(res) - wid = res.get('id', fbro.id) - result = super(document_file,self).write(cr,uid,wid,vals2,context=context) - # TODO: how to handle/merge several results? - elif res == True: + if ('parent_id' not in vals or fbro.parent_id.id == vals['parent_id']) \ + and ('name' not in vals or fbro.name == vals['name']) : ids2.append(fbro.id) - elif res == False: - pass + continue + fnode = nctx.get_file_node(cr, fbro) + res = fnode.move_to(cr, dnode or fnode.parent, vals.get('name', fbro.name), fbro, dbro, True) + if isinstance(res, dict): + vals2 = vals.copy() + vals2.update(res) + wid = res.get('id', fbro.id) + result = super(document_file,self).write(cr,uid,wid,vals2,context=context) + # TODO: how to handle/merge several results? + elif res == True: + ids2.append(fbro.id) + elif res == False: + pass ids = ids2 if 'file_size' in vals: # only write that field using direct SQL calls del vals['file_size'] - if len(ids): + if len(ids) and len(vals): result = super(document_file,self).write(cr, uid, ids, vals, context=context) cr.commit() # ? return result -- cgit v1.2.3