Add attachment preview

issue10203
review332271014
This commit is contained in:
Cédric Krier committed 2021-04-07 23:34:51 +02:00
1 parent fbdd94801b
commit ea57165a86
3 files changed
+25

No files matched your search

+12
View File
@@ -6,6 +6,7 @@ from sql.operators import Concat
from trytond.config import config
from trytond.i18n import lazy_gettext
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
from trytond.pyson import Eval
from trytond.tools import firstline
from trytond.transaction import Transaction
@@ -96,6 +97,17 @@ class Attachment(ResourceMixin, ModelSQL, ModelView):
def on_change_with_summary(self, name=None):
return firstline(self.description or '')
@classmethod
def fields_view_get(cls, view_id=None, view_type='form', level=None):
pool = Pool()
ModelData = pool.get('ir.model.data')
if not view_id:
if Transaction().context.get('preview'):
view_id = ModelData.get_id(
'ir', 'attachment_view_form_preview')
return super().fields_view_get(
view_id=view_id, view_type=view_type, level=level)
class AttachmentCopyMixin(
resource_copy(
+6
View File
@@ -8,6 +8,12 @@ this repository contains the full copyright notices and license terms. -->
<field name="type">form</field>
<field name="name">attachment_form</field>
</record>
<record model="ir.ui.view" id="attachment_view_form_preview">
<field name="model">ir.attachment</field>
<field name="type">form</field>
<field name="priority" eval="50"/>
<field name="name">attachment_form_preview</field>
</record>
<record model="ir.ui.view" id="attachment_view_tree">
<field name="model">ir.attachment</field>
<field name="type">tree</field>
@@ -0,0 +1,7 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<form col="1">
<field name="data" widget="document" readonly="1"/>
<label name="name" string="" xalign="0.5"/>
</form>