Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
9d0001f262 | ||
![]() |
a149f46dbb | ||
![]() |
3750a4b0f6 | ||
![]() |
89ad435e72 | ||
![]() |
51934f46bc | ||
![]() |
fa526fa69e | ||
![]() |
6aa9bb5325 | ||
![]() |
1286fa6f2f |
9 changed files with 56 additions and 8 deletions
|
@ -1,3 +1,6 @@
|
||||||
syntax: glob
|
syntax: glob
|
||||||
__pycache__/*
|
__pycache__/*
|
||||||
locale/convert_de2en.py
|
locale/convert_de2en.py
|
||||||
|
build/*
|
||||||
|
mds_cashbook_media.egg-info/*
|
||||||
|
dist/*
|
||||||
|
|
|
@ -14,6 +14,15 @@ Requires
|
||||||
Changes
|
Changes
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
*6.0.2 - 23.01.2023*
|
||||||
|
|
||||||
|
- add: show image in tab 'image/pdf'
|
||||||
|
|
||||||
|
*6.0.1 - 29.11.2022*
|
||||||
|
|
||||||
|
- fix: exception when image type unknown
|
||||||
|
|
||||||
*6.0.0 - 14.10.2022*
|
*6.0.0 - 14.10.2022*
|
||||||
|
|
||||||
- init
|
- init
|
||||||
|
|
||||||
|
|
29
line.py
29
line.py
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import mimetypes, magic
|
import mimetypes, magic
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from PIL import Image
|
from PIL import Image, UnidentifiedImageError
|
||||||
from trytond.model import fields
|
from trytond.model import fields
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.config import config
|
from trytond.config import config
|
||||||
|
@ -28,20 +28,38 @@ except :
|
||||||
image_limit = 2000
|
image_limit = 2000
|
||||||
|
|
||||||
|
|
||||||
|
STATES2 = {}
|
||||||
|
STATES2.update(STATES)
|
||||||
|
DEPENDS2 = []
|
||||||
|
DEPENDS2.extend(DEPENDS)
|
||||||
|
|
||||||
|
|
||||||
class Line(metaclass=PoolMeta):
|
class Line(metaclass=PoolMeta):
|
||||||
__name__ = 'cashbook.line'
|
__name__ = 'cashbook.line'
|
||||||
|
|
||||||
media = fields.Binary(string='Image of PDF', filename='media_name',
|
media = fields.Binary(string='Image of PDF', filename='media_name',
|
||||||
file_id='media_id', store_prefix=store_prefix,
|
file_id='media_id', store_prefix=store_prefix,
|
||||||
states=STATES, depends=DEPENDS)
|
states=STATES2, depends=DEPENDS2)
|
||||||
media_name = fields.Char(string='File name',
|
media_name = fields.Char(string='File name',
|
||||||
states={
|
states={
|
||||||
'required': Bool(Eval('media')),
|
'required': Bool(Eval('media')),
|
||||||
'readonly': STATES['readonly'],
|
'readonly': STATES2['readonly'],
|
||||||
}, depends=DEPENDS)
|
}, depends=DEPENDS2)
|
||||||
media_id = fields.Char(string='File ID', readonly=True)
|
media_id = fields.Char(string='File ID', readonly=True)
|
||||||
media_mime = fields.Char(string='MIME', readonly=True)
|
media_mime = fields.Char(string='MIME', readonly=True)
|
||||||
media_size = fields.Integer(string='File size', readonly=True)
|
media_size = fields.Integer(string='File size', readonly=True)
|
||||||
|
media_image = fields.Function(fields.Binary(string='Image', readonly=True,
|
||||||
|
states={
|
||||||
|
'invisible': ~Eval('media_mime', '').in_(['image/png', 'image/jpg', 'image/jpeg']),
|
||||||
|
}, depends=['media_mime']),
|
||||||
|
'on_change_with_media_image')
|
||||||
|
|
||||||
|
@fields.depends('media', 'media_mime')
|
||||||
|
def on_change_with_media_image(self, name=True):
|
||||||
|
""" return binary if its a image
|
||||||
|
"""
|
||||||
|
if (self.media_mime or '-').startswith('image/'):
|
||||||
|
return self.media
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _identify_file(cls, data, mime=True):
|
def _identify_file(cls, data, mime=True):
|
||||||
|
@ -65,7 +83,10 @@ class Line(metaclass=PoolMeta):
|
||||||
"""
|
"""
|
||||||
image_data2 = None
|
image_data2 = None
|
||||||
with BytesIO(image_data) as fhdl:
|
with BytesIO(image_data) as fhdl:
|
||||||
|
try :
|
||||||
image = Image.open(fhdl, 'r')
|
image = Image.open(fhdl, 'r')
|
||||||
|
except UnidentifiedImageError:
|
||||||
|
raise UserError(gettext('cashbook_media.msg_file_unknown_type'))
|
||||||
|
|
||||||
(width, height) = image.size
|
(width, height) = image.size
|
||||||
if (width > image_limit) or (height > image_limit):
|
if (width > image_limit) or (height > image_limit):
|
||||||
|
|
|
@ -14,6 +14,10 @@ msgctxt "model:ir.message,text:msg_file_invalid_mime"
|
||||||
msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
||||||
msgstr "Der Dateityp '%(fmime)s' des Datensatzes '%(recname)s' ist nicht zugelassen. (erlaubt: PNG, JPG, PDF)"
|
msgstr "Der Dateityp '%(fmime)s' des Datensatzes '%(recname)s' ist nicht zugelassen. (erlaubt: PNG, JPG, PDF)"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_file_unknown_type"
|
||||||
|
msgid "cannot identify image file"
|
||||||
|
msgstr "Bilddatei kann nicht identifiziert werden"
|
||||||
|
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# cashbook.line #
|
# cashbook.line #
|
||||||
|
@ -42,3 +46,6 @@ msgctxt "field:cashbook.line,media_size:"
|
||||||
msgid "File size"
|
msgid "File size"
|
||||||
msgstr "Dateigröße"
|
msgstr "Dateigröße"
|
||||||
|
|
||||||
|
msgctxt "field:cashbook.line,media_image:"
|
||||||
|
msgid "Image"
|
||||||
|
msgstr "Bild"
|
||||||
|
|
|
@ -10,6 +10,10 @@ msgctxt "model:ir.message,text:msg_file_invalid_mime"
|
||||||
msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
msgid "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
||||||
msgstr "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
msgstr "The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)"
|
||||||
|
|
||||||
|
msgctxt "model:ir.message,text:msg_file_unknown_type"
|
||||||
|
msgid "cannot identify image file"
|
||||||
|
msgstr "cannot identify image file"
|
||||||
|
|
||||||
msgctxt "view:cashbook.line:"
|
msgctxt "view:cashbook.line:"
|
||||||
msgid "Image/PDF"
|
msgid "Image/PDF"
|
||||||
msgstr "Image/PDF"
|
msgstr "Image/PDF"
|
||||||
|
|
|
@ -11,6 +11,9 @@ full copyright notices and license terms. -->
|
||||||
<record model="ir.message" id="msg_file_invalid_mime">
|
<record model="ir.message" id="msg_file_invalid_mime">
|
||||||
<field name="text">The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)</field>
|
<field name="text">The file type '%(fmime)s' of the record '%(recname)s' is not allowed. (allowed: PNG, JPG, PDF)</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="ir.message" id="msg_file_unknown_type">
|
||||||
|
<field name="text">cannot identify image file</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
[tryton]
|
[tryton]
|
||||||
version=6.0.0
|
version=6.0.2
|
||||||
depends:
|
depends:
|
||||||
cashbook
|
cashbook
|
||||||
xml:
|
xml:
|
||||||
message.xml
|
message.xml
|
||||||
line.xml
|
line.xml
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
cashbook;6.0.18;6.0.999;mds
|
cashbook;6.0.22;6.0.999;mds
|
||||||
|
|
|
@ -13,10 +13,10 @@ full copyright notices and license terms. -->
|
||||||
|
|
||||||
<label name="media_name"/>
|
<label name="media_name"/>
|
||||||
<field name="media_name"/>
|
<field name="media_name"/>
|
||||||
|
|
||||||
<label name="media_mime"/>
|
<label name="media_mime"/>
|
||||||
<field name="media_mime"/>
|
<field name="media_mime"/>
|
||||||
|
|
||||||
|
<field name="media_image" readonly="1" colspan="4" widget="image" xexpand="1" yexpand="1"/>
|
||||||
</page>
|
</page>
|
||||||
|
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
Loading…
Reference in a new issue