コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
12879 ビュー

Hello,

is there any addon or code by which I can embed a preview of pdf documents in a form view? Or if this is not possible, to embed an image in an form view. Optionally, this opens or increases by clicking.

I'm using Odoo 10. Thank you for your help.

アバター
破棄
最善の回答

Hi


Check out this video will helpful: 

https://youtu.be/Ozikktx0Ovs

アバター
破棄
最善の回答

odoo.define('module_name.image_widget_extend', function (require) {
"use strict";


    var core = require('web.core');
    var form_common = require('web.form_common');
    var imageWidget = core.form_widget_registry.get('image');
    var session = require('web.session');
    var utils = require('web.utils');
    var QWeb = core.qweb;

imageWidget.include({
    render_value: function() {
        var self = this;
        var url;
        this.session = session;
        if (this.get('value') && !utils.is_bin_size(this.get('value'))) {
            url = 'data:image/png;base64,' + this.get('value');
        } else if (this.get('value')) {
            var id = JSON.stringify(this.view.datarecord.id || null);
            var field = this.name;
            if (this.options.preview_image)
                field = this.options.preview_image;
            url = session.url('/web/image', {
                                        model: this.view.dataset.model,
                                        id: id,
                                        field: field,
                                        unique: (this.view.datarecord.__last_update || '').replace(/[^0-9]/g, ''),
            });
        } else {
            url = this.placeholder;
        }

        var record_id = this.getParent().get_fields_values()['id'];
        var current_model = this.getParent().model;
        var $img = $(QWeb.render("FieldBinaryImage-img", { widget: this, url: url }));
        $($img).click(function(e) {
            if(self.view.get("actual_mode") == "view") {

                var $button = $(".oe_form_button_edit");
                $button.openerpBounce();
                e.stopPropagation();
                window.location.href = "/web/image/" + current_model + "/" + record_id + "/image"
            }
        });
        this.$el.find('> img').remove();
        this.$el.prepend($img);
        $img.load(function() {
            if (! self.options.size)
                return;
            $img.css("max-width", "" + self.options.size[0] + "px");
            $img.css("max-height", "" + self.options.size[1] + "px");
        });
        $img.on('error', function() {
            self.on_clear();
            $img.attr('src', self.placeholder);
            self.do_warn(_t("Image"), _t("Could not display the selected image."));
        });
    },

});


});


Try to implement above. Hope this will help you.

アバター
破棄
関連投稿 返信 ビュー 活動
1
7月 17
6317
0
11月 22
3947
2
1月 25
3916
1
12月 22
5302
2
11月 21
4106