Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Property Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Personnalisation du widget Binary.

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentconfirmationbinarybinaryfieldWidgetsDialog
1 Reply
1348 Views
Avatar
Jonathan Raffin

Bonjour,


Je suis actuellement en plein travail sur la version 18 d'Odoo. Je découvre l'outil depuis quelques semaines. J'ai découvert le champ « Binary » qui permet d'importer des fichiers. Une fois un fichier chargé, il y a plusieurs icônes qui apparaissent. Dont une poubelle pour supprimer le fichier. J'aimerais avoir une boite de dialogue qui demande la confirmation d'être sûr de vouloir supprimer le fichier. J'ai réussi à faire ceci dans le code source en le modifiant. Mais pour être plus propre et modulable, il serait mieux d'avoir un module personnalisé qui me permettrait de faire ceci. Sauf que j'ai beau tenter plusieurs choses, rien ne fonctionne. Je n'ai pas forcément d'erreurs. Quand j'ai des erreurs, j'arrive à les corriger. En plus de ceci, j'utilise un autre module (https://apps.odoo.com/apps/modules/17.0/ps_binary_field_attachment_preview) qui me permet de visualiser les fichiers. Je ne sais pas s'il peut y avoir une sorte de conflit entre les modules.

Merci de votre aide !


Voici le code source modifié comme je le souhaite avec la 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
Jonathan Raffin
Author Best Answer

J'ai réussi à utiliser le patch Odoo JS qui modifie le widget de base.

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
Customising the Binary widget.
development confirmation binary dialog binaryfield 18.0 Dialog
Avatar
Avatar
2
Jul 25
3562
Odoo 12 - Binary Field get Binary Data from that Field Solved
binary binaryfield
Avatar
Avatar
2
Feb 23
11500
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
Jul 16
5564
[Odoo 11] Error uploading a file through custom model Solved
binary binaryfield odoo
Avatar
1
Jan 18
6809
How to Automatically Apply Watermarks to Images/PDFs on Download (JS/Python in Odoo)
development dms attachments binary download binaryfield watermark attachement odoo15CE
Avatar
Avatar
1
May 25
1728
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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