[attachment]

- implement a field function res_name that call the name_get for res_model, res_id
- remove preview field

bzr revid: hmo@tinyerp.com-20100527124311-snyrw2ja53xa8o5u
This commit is contained in:
KSA (OpenERP) 2010-05-27 18:13:11 +05:30 committed by Harry (Open ERP)
parent d573e7fe72
commit 8eb28e74b9
2 changed files with 27 additions and 36 deletions

View File

@ -230,7 +230,7 @@
</record> </record>
<menuitem id="next_id_6" name="Actions" parent="base.next_id_4"/> <menuitem id="next_id_6" name="Actions" parent="base.next_id_4"/>
<menuitem action="ir_sequence_actions" id="menu_ir_sequence_actions" parent="next_id_6"/> <menuitem action="ir_sequence_actions" id="menu_ir_sequence_actions" parent="next_id_6"/>
<!-- Filters form view--> <!-- Filters form view-->
<record id="ir_filters_view_form" model="ir.ui.view"> <record id="ir_filters_view_form" model="ir.ui.view">
@ -248,9 +248,9 @@
</form> </form>
</field> </field>
</record> </record>
<!-- Filters tree view--> <!-- Filters tree view-->
<record id="ir_filters_view_tree" model="ir.ui.view"> <record id="ir_filters_view_tree" model="ir.ui.view">
<field name="name">ir.filters.tree</field> <field name="name">ir.filters.tree</field>
<field name="model">ir.filters</field> <field name="model">ir.filters</field>
@ -265,7 +265,7 @@
</tree> </tree>
</field> </field>
</record> </record>
<!-- Filters action--> <!-- Filters action-->
<record id="actions_ir_filters_view" model="ir.actions.act_window"> <record id="actions_ir_filters_view" model="ir.actions.act_window">
@ -275,7 +275,7 @@
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_id" ref="ir_filters_view_tree"/> <field name="view_id" ref="ir_filters_view_tree"/>
</record> </record>
<!-- Filters view menu--> <!-- Filters view menu-->
<menuitem parent="base.next_id_6" name="Filters" <menuitem parent="base.next_id_6" name="Filters"
@ -674,16 +674,8 @@
<separator string="Attached To" colspan="2"/> <separator string="Attached To" colspan="2"/>
<field name="res_model" select="2"/> <field name="res_model" select="2"/>
<field name="res_id"/> <field name="res_id"/>
<field name="res_name"/>
</group> </group>
<separator string="Preview" colspan="4"/>
<field
name="preview"
widget="picture"
readonly="1"
nolabel="1"
colspan="4"
img_height="400"
img_width="800"/>
</page> </page>
<page string="Notes"> <page string="Notes">
<field colspan="4" name="description" nolabel="1"/> <field colspan="4" name="description" nolabel="1"/>

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# OpenERP, Open Source Management Solution # OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
# #
@ -15,7 +15,7 @@
# GNU Affero General Public License for more details. # GNU Affero General Public License for more details.
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
@ -25,7 +25,7 @@ import tools
class ir_attachment(osv.osv): class ir_attachment(osv.osv):
def check(self, cr, uid, ids, mode, context=None): def check(self, cr, uid, ids, mode, context=None):
if not ids: if not ids:
return return
ima = self.pool.get('ir.model.access') ima = self.pool.get('ir.model.access')
if isinstance(ids, (int, long)): if isinstance(ids, (int, long)):
@ -37,8 +37,8 @@ class ir_attachment(osv.osv):
def search(self, cr, uid, args, offset=0, limit=None, order=None, def search(self, cr, uid, args, offset=0, limit=None, order=None,
context=None, count=False): context=None, count=False):
ids = super(ir_attachment, self).search(cr, uid, args, offset=offset, ids = super(ir_attachment, self).search(cr, uid, args, offset=offset,
limit=limit, order=order, limit=limit, order=order,
context=context, count=False) context=context, count=False)
if not ids: if not ids:
if count: if count:
@ -66,7 +66,7 @@ class ir_attachment(osv.osv):
def write(self, cr, uid, ids, vals, context=None): def write(self, cr, uid, ids, vals, context=None):
self.check(cr, uid, ids, 'write', context=context) self.check(cr, uid, ids, 'write', context=context)
return super(ir_attachment, self).write(cr, uid, ids, vals, context) return super(ir_attachment, self).write(cr, uid, ids, vals, context)
def copy(self, cr, uid, id, default=None, context=None): def copy(self, cr, uid, id, default=None, context=None):
self.check(cr, uid, [id], 'write', context=context) self.check(cr, uid, [id], 'write', context=context)
return super(ir_attachment, self).copy(cr, uid, id, default, context) return super(ir_attachment, self).copy(cr, uid, id, default, context)
@ -84,37 +84,36 @@ class ir_attachment(osv.osv):
dataobj = self.pool.get('ir.model.data') dataobj = self.pool.get('ir.model.data')
data_id = dataobj._get_id(cr, 1, 'base', 'action_attachment') data_id = dataobj._get_id(cr, 1, 'base', 'action_attachment')
res_id = dataobj.browse(cr, uid, data_id, context).res_id res_id = dataobj.browse(cr, uid, data_id, context).res_id
return self.pool.get('ir.actions.act_window').read(cr, uid, res_id, [], context) return self.pool.get('ir.actions.act_window').read(cr, uid, res_id, [], context)
def _get_preview(self, cr, uid, ids, name, arg, context=None): def _name_get_resname(self, cr, uid, ids, object,method, context):
result = {} data = {}
if context is None: for attachment in self.browse(cr, uid, ids, context=context):
context = {} model_object = attachment.res_model
ctx = context.copy() res_id = attachment.res_id
ctx['bin_size'] = False if model_object and res_id:
for i in self.browse(cr, uid, ids, context=ctx): model_pool = self.pool.get(model_object)
result[i.id] = False res = model_pool.name_get(cr,uid,[res_id],context)
for format in ('png','jpg','jpeg','gif','bmp'): data[attachment.id] = res[0][1]
if (i.datas_fname and i.datas_fname.lower() or '').endswith(format): else:
result[i.id]= i.datas data[attachment.id] = False
break return data
return result
_name = 'ir.attachment' _name = 'ir.attachment'
_columns = { _columns = {
'name': fields.char('Attachment Name',size=64, required=True), 'name': fields.char('Attachment Name',size=64, required=True),
'datas': fields.binary('Data'), 'datas': fields.binary('Data'),
'preview': fields.function(_get_preview, type='binary', string='Image Preview', method=True),
'datas_fname': fields.char('Filename',size=64), 'datas_fname': fields.char('Filename',size=64),
'description': fields.text('Description'), 'description': fields.text('Description'),
# Not required due to the document module ! # Not required due to the document module !
'res_name': fields.function(_name_get_resname, type='char', string='Resource Name', method=True),
'res_model': fields.char('Resource Object',size=64, readonly=True), 'res_model': fields.char('Resource Object',size=64, readonly=True),
'res_id': fields.integer('Resource ID', readonly=True), 'res_id': fields.integer('Resource ID', readonly=True),
'link': fields.char('Link', size=256), 'link': fields.char('Link', size=256),
'create_date': fields.datetime('Date Created', readonly=True), 'create_date': fields.datetime('Date Created', readonly=True),
'create_uid': fields.many2one('res.users', 'Creator', readonly=True), 'create_uid': fields.many2one('res.users', 'Creator', readonly=True),
} }
ir_attachment() ir_attachment()