Skip to Content
Odoo मेन्यू
  • Sign in
  • मुफ़्त में आज़माएं
  • ऐप्लिकेशन
    फ़ाइनेंस
    • अकाउंटिंग
    • इनवॉइसिंग
    • एक्सपेंस
    • स्प्रेडशीट (बीआई)
    • डॉक्यूमेंट्स
    • साइन
    सेल्स
    • सीआरएम
    • सेल्स
    • पीओएस शॉप
    • पीओएस रेस्टोरेंट
    • सब्सक्रिप्शन
    • रेंटल
    वेबसाइट
    • वेबसाइट बिल्डर
    • ई-कॉमर्स
    • ब्लॉग
    • फ़ोरम
    • लाइव चैट
    • ई-लर्निंग
    सप्लाई चेन
    • इन्वेंट्री
    • मैन्युफ़ैक्चरिंग
    • पीएलएम
    • परचेज़
    • मेंटेनेंस
    • क्वालिटी
    मानव संसाधन
    • कर्मचारी
    • रिक्रूटमेंट
    • टाइम ऑफ़
    • अप्रेज़ल
    • रेफ़रल
    • फ़्लीट
    मार्केटिंग
    • सोशल मार्केटिंग
    • ईमेल मार्केटिंग
    • एसएमएस मार्केटिंग
    • इवेंट
    • मार्केटिंग ऑटोमेशन
    • सर्वे
    सेवाएं
    • प्रोजेक्ट
    • टाइमशीट
    • फ़ील्ड सर्विस
    • हेल्पडेस्क
    • प्लानिंग
    • अपॉइंटमेंट
    प्रॉडक्टिविटी
    • डिस्कस
    • अप्रूवल
    • आईओटी
    • वीओआईपी
    • नॉलेज
    • WhatsApp
    तीसरे पक्ष के ऐप्लिकेशन Odoo स्टूडियो Odoo क्लाउड प्लेटफ़ॉर्म
  • इंडस्ट्री
    रीटेल
    • बुक स्टोर
    • क्लोदिंग स्टोर
    • फ़र्नीचर स्टोर
    • ग्रॉसरी स्टोर
    • हार्डवेयर स्टोर
    • टॉय स्टोर
    Food & Hospitality
    • बार और पब
    • रेस्टोरेंट
    • फ़ास्ट फ़ूड
    • Guest House
    • बेवरिज डिस्ट्रीब्यूटर
    • होटल
    रियल एस्टेट
    • Real Estate Agency
    • आर्किटेक्चर फ़र्म
    • कंसट्रक्शन
    • Property Management
    • गार्ड्निंग
    • प्रॉपर्टी ओनर असोसिएशन
    कंसल्टिंग
    • अकाउंटिंग फ़र्म
    • Odoo पार्टनर
    • मार्केटिंग एजेंसी
    • लॉ फ़र्म
    • टैलेंट ऐक्विज़िशन
    • ऑडिट & सर्टिफ़िकेशन
    मैन्युफ़ैक्चरिंग
    • टेक्सटाइल
    • Metal
    • फ़र्नीचर
    • फ़ूड
    • Brewery
    • कॉर्पोरेट गिफ़्ट
    हेल्थ & फिटनेस
    • स्पोर्ट्स क्लब
    • आईवियर स्टोर
    • फिटनेस सेंटर
    • वेलनेस प्रैक्टिशनर
    • फॉर्मेसी
    • हेयर सैलून
    Trades
    • Handyman
    • आईटी हॉर्डवेयर और सपोर्ट
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    अन्य
    • Nonprofit Organization
    • एन्वायरमेंटल एजेंसी
    • बिलबोर्ड रेंटल
    • फ़ोटोग्राफी
    • बाइक लीजिंग
    • सॉफ़्टवेयर रीसेलर
    Browse all Industries
  • कम्यूनिटी
    सीखें
    • ट्यूटोरियल्स
    • दस्तावेज़
    • सर्टिफ़िकेशन
    • ट्रेनिंग
    • ब्लॉग
    • पॉडकास्ट
    शिक्षा को बढ़ावा दें
    • एजुकेशन प्रोग्राम
    • स्केल अप! बिजनेस गेम
    • Odoo के ऑफ़िस में आएं
    सॉफ़्टवेयर पाएं
    • डाउनलोड
    • वर्शन की तुलना करें
    • रिलीज़
    साथ मिलकर काम करें
    • Github
    • फ़ोरम
    • इवेंट
    • अनुवाद
    • पार्टनर बनें
    • Services for Partners
    • अपना अकाउंटिंग फ़र्म रजिस्टर करें
    सेवाएं पाएं
    • पार्टनर ढूंढें
    • अकाउंटेंट खोजें
    • सलाहकार की मदद लें
    • इम्प्लिमेंटेशन सेवाएं
    • कस्टमर रेफ़रेंस
    • सहायता
    • अपग्रेड
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    डेमो देखें
  • कीमत
  • सहायता
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
टैग (View all)
odoo accounting v14 pos v15
About this forum
Help

Customising the Binary widget.

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentconfirmationbinarydialogbinaryfield18.0Dialog
2 Replies
3560 Views
Avatar
Jonathan Raffin

Hello,


I'm currently working on version 18 of Odoo. I've only been using the tool for a few weeks. I discovered the ‘Binary’ field which allows you to import files. Once a file has been loaded, several icons appear. One of them is a bin for deleting the file. I'd like to have a dialogue box asking for confirmation that I'm sure I want to delete the file. I've managed to do this in the source code by modifying it. But to be cleaner and more modular, it would be better to have a custom module that would allow me to do this. Except that no matter how hard I try, nothing works. I don't necessarily get errors. When I do have errors, I manage to correct them. In addition to this, I use another module called ‘Binary Field Attachment Preview’ from Pysquad Informatics LLP which allows me to view the files. I don't know whether there might be some sort of conflict between the modules.


Thanks for your help!



Here's the source code modified as I want it, with confirmation:

import { registry } from "@web/core/registry";

import { useService } from "@web/core/utils/hooks";

import { isBinarySize, toBase64Length } from "@web/core/utils/binary";

import { download } from "@web/core/network/download";

import { standardFieldProps } from "../standard_field_props";

import { FileUploader } from "../file_handler";

import { _t } from "@web/core/l10n/translation";

import { Component, xml } from "@odoo/owl";


import { Dialog } from "@web/core/dialog/dialog";


export const MAX_FILENAME_SIZE_BYTES = 0xFF;  // filenames do not exceed 255 bytes on Linux/Windows/MacOS


export class BinaryField extends Component {

    static template = "web.BinaryField";

    static components = {

        FileUploader,

    };

    static props = {

        ...standardFieldProps,

        acceptedFileExtensions: { type: String, optional: true },

        fileNameField: { type: String, optional: true },

    };

    static defaultProps = {

        acceptedFileExtensions: "*",

    };


    setup() {

        this.notification = useService("notification");

        this.dialog = useService("dialog");

    }


    get fileName() {

        return (

            this.props.record.data[this.props.fileNameField] ||

            this.props.record.data[this.props.name] ||

            ""

        ).slice(0, toBase64Length(MAX_FILENAME_SIZE_BYTES));

    }


    update({ data, name }) {

        const { fileNameField, record } = this.props;

        const changes = { [this.props.name]: data || false };

        if (fileNameField in record.fields && record.data[fileNameField] !== name) {

            changes[fileNameField] = name || '';

        }

        return this.props.record.update(changes);

    }


    getDownloadData() {

        return {

            model: this.props.record.resModel,

            id: this.props.record.resId,

            field: this.props.name,

            filename_field: this.fileName,

            filename: this.fileName || "",

            download: true,

            data: isBinarySize(this.props.record.data[this.props.name])

                ? null

                : this.props.record.data[this.props.name],

        };

    }


    onClickDelete() {

        this.dialog.add(ConfirmDeleteDialog, {

            onConfirmCallback: () => this.update({}),

        });        

    }    


    async onFileDownload() {

        await download({

            data: this.getDownloadData(),

            url: "/web/content",

        });

    }

}


export class ListBinaryField extends BinaryField {

    static template = "web.ListBinaryField";

}


export const binaryField = {

    component: BinaryField,

    displayName: _t("File"),

    supportedOptions: [

        {

            label: _t("Accepted file extensions"),

            name: "accepted_file_extensions",

            type: "string",

        },

    ],

    supportedTypes: ["binary"],

    extractProps: ({ attrs, options }) => ({

        acceptedFileExtensions: options.accepted_file_extensions,

        fileNameField: attrs.filename,

    }),

};


export const listBinaryField = {

    ...binaryField,

    component: ListBinaryField,

};


class ConfirmDeleteDialog extends Component {

    static template = xml`

        <Dialog title="'Confirmation de suppression'">

            <div>

                Êtes-vous sûr de vouloir supprimer ce fichier ?

            </div>

            <t t-set-slot="footer">

                <button class="btn btn-danger" t-on-click="onConfirm">Supprimer</button>

                <button class="btn btn-secondary" t-on-click="props.close">Annuler</button>

            </t>

        </Dialog>

    `;

    static components = { Dialog };

    static props = ['close', 'onConfirmCallback'];


    onConfirm() {

        this.props.onConfirmCallback(); // Appel du callback

        this.props.close(); // Fermeture manuelle du dialog

    }

}




registry.category("fields").add("binary", binaryField);

registry.category("fields").add("list.binary", listBinaryField);



<?xml version="1.0" encoding="UTF-8"?>

<templates xml:space="preserve">


    <t t-name="web.BinaryField">

        <t t-if="!props.readonly">

            <t t-if="props.record.data[props.name]">

                <div class="w-100 d-inline-flex gap-1">

                    <FileUploader

                        acceptedFileExtensions="props.acceptedFileExtensions"

                        onUploaded.bind="update"

                    >

                        <t name="download" t-if="props.record.resId and !props.record.dirty">

                            <button

                                class="btn btn-link btn-sm lh-1 fa fa-download o_download_file_button"

                                data-tooltip="Download"

                                aria-label="Download"

                                t-on-click="onFileDownload"

                            >

                            </button>

                        </t>

                        <t t-set-slot="toggler">

                            <input type="text" class="o_input" t-att-value="fileName" readonly="readonly" />

                            <button

                                class="btn btn-link btn-sm lh-1 fa fa-pencil o_select_file_button"

                                data-tooltip="Edit"

                                aria-label="Edit"

                            >

                            </button>

                        </t>

                        <button

                            class="btn btn-link btn-sm lh-1 fa fa-trash o_clear_file_button"

                            data-tooltip="Clear"

                            aria-label="Clear"

                            t-on-click="onClickDelete"

                        />

                        <!-- </button> -->

                    </FileUploader>

                </div>

            </t>

            <t t-else="">

                <label class="o_select_file_button btn btn-primary">

                    <FileUploader

                        acceptedFileExtensions="props.acceptedFileExtensions"

                        onUploaded.bind="update"

                    >

                        <t t-set-slot="toggler">

                            Upload your file

                        </t>

                    </FileUploader>

                </label>

            </t>

        </t>

        <t t-elif="props.record.resId and props.record.data[props.name]">

            <a class="o_form_uri" href="#" t-on-click.prevent="onFileDownload">

                <span class="fa fa-download me-2" />

                <t t-if="fileName" t-esc="fileName" />

            </a>

        </t>

    </t>


    <t t-name="web.ListBinaryField" t-inherit="web.BinaryField">

        <xpath expr="//label[hasclass('o_select_file_button')]" position="replace">

            <label class="o_select_file_button btn btn-sm btn-link p-0">

                <FileUploader

                    acceptedFileExtensions="props.acceptedFileExtensions"

                    onUploaded.bind="update"

                >

                    <t t-set-slot="toggler">

                        <i class="fa fa-upload fa-fw"/> Upload your file

                    </t>

                </FileUploader>

            </label>

        </xpath>

    </t>


</templates>



0
Avatar
Discard
Avatar
SARATH V C
Best Answer

Hai,

I have made a custom widget for this purpose. In addition to this it consist of additional feature too. Please check it out. https://apps.odoo.com/apps/modules/16.0/cbu_advance_m2m_binary_widget

0
Avatar
Discard
Avatar
Jonathan Raffin
Author Best Answer

I succeeded by using the Odoo JS patch which modifies the basic widget.

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Personnalisation du widget Binary.
development confirmation binary binaryfield Widgets Dialog
Avatar
1
मई 25
1346
Custom code: crm.lead activity_ids not shown in list [via optional=show] Solved
development 18.0
Avatar
Avatar
2
जून 25
1483
Odoo 12 - Binary Field get Binary Data from that Field Solved
binary binaryfield
Avatar
Avatar
2
फ़र॰ 23
11498
How to write back data table into Excel file after modifying on the table which is read out from a Excel file?
binary binaryfield
Avatar
0
जुल॰ 16
5562
is it possible to show confirmation dialog if a condition is met in odoo 13?
confirmation dialog odoo
Avatar
Avatar
Avatar
2
सित॰ 22
6340
कम्यूनिटी
  • ट्यूटोरियल्स
  • दस्तावेज़
  • फ़ोरम
ओपन सोर्स
  • डाउनलोड
  • Github
  • रनबॉट
  • अनुवाद
सेवाएं
  • Odoo.sh Hosting
  • सहायता
  • अपग्रेड
  • कस्टम डेवलपमेंट्स
  • शिक्षा
  • अकाउंटेंट खोजें
  • पार्टनर ढूंढें
  • पार्टनर बनें
हमारे बारे में
  • हमारी कंपनी
  • ब्रांड ऐसेट
  • संपर्क करें
  • नौकरियां
  • इवेंट
  • पॉडकास्ट
  • ब्लॉग
  • ग्राहक
  • लीगल • गोपनीयता
  • सुरक्षा
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo, बिज़नेस से जुड़े ऐप्लिकेशन का एक कलेक्शन है जो ओपन सोर्स पर आधारित है. इसमें आपकी कंपनी की हर ज़रूरत के लिए ऐप्लिकेशन हैं. जैसे, सीआरएम, ई-कॉमर्स, अकाउंटिंग, इन्वेंट्री, पॉइंट ऑफ़ सेल, प्रोजेक्ट मैनेजमेंट वगैरह.

Odoo की सबसे बड़ी खासियत है कि यह इस्तेमाल करने में बहुत आसान है और यह पूरी तरह से इंटिग्रेट किया हुआ है.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now