跳至内容
菜单
此问题已终结
2 回复
12868 查看

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
6287
0
11月 22
3942
2
1月 25
3910
1
12月 22
5299
2
11月 21
4101