Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Custom field widget not working, showing default widget instead.

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
fieldswidget
3270 Vues
Avatar
Pablo A

Odoo 14 instance.

I am working on a custom field widget to hold , preview, and ultimately transform the bitmap representation of the rendered qweb template in ir.ui.view model.
Nothing too fancy but i am unable to actually test and see how it works because it doesn't work at all, when i load my module and head to the form, instead of showing my custom widget it shows the upload widget for the image field. I want it to show my widget instead of the upload button.

This is what my model be looking like:

class View(models.Model):

"""

This class extends 'ir.ui.view' to add bitmap-related functionality to views.

"""


_inherit = "ir.ui.view"


enable_bitmap = fields.Boolean(string='Enable Bitmap Field', help="Enable or disable the bitmap functionality.")

bitmap_image = fields.Binary(string='Bitmap Image', attachment=True, widget="bitmap_canvas", help="Binary field to store the generated bitmap image.")

bitmap_width = fields.Float(string="Bitmap Width (mm)", help="Width of the generated bitmap in millimeters.")

bitmap_height = fields.Float(string="Bitmap Height (mm)", help="Height of the generated bitmap in millimeters.")

dpi = fields.Integer(string="DPI", default=300)

bitmap_enabled = fields.Boolean(compute='_compute_bitmap_enabled', store=False, help="Computed field to determine if bitmap functionality is enabled.")

html_raw_qweb = fields.Html(compute='_compute_html_raw_qweb', store=False, help="HTML content generated from Arch Base XML.")


def get_html_as_text(self):

"""

Retrieve HTML content from 'html_raw_qweb' field as text.


:return: HTML content as text.

:rtype: str

"""

self.ensure_one()

return self.html_raw_qweb


@api.depends('arch_base')

def _compute_html_raw_qweb(self):

"""

Compute 'html_raw_qweb' field based on 'arch_base' and 'enable_bitmap' values.


- If 'enable_bitmap' is True and 'arch_base' is provided, perform the action.

- Render HTML content from 'arch_base' XML.

- Update 'html_raw_qweb' field with the rendered HTML.

- Otherwise, set 'html_raw_qweb' to False.

"""

for view in self:

if view.arch_base and view.enable_bitmap:

view.html_raw_qweb = self.env['ir.ui.view']._render_template(view.arch_base, values={})

else:

view.html_raw_qweb = False


def store_bitmap(self, bitmap_data):

"""

Store the provided bitmap data in the 'bitmap_image' field.


:param bytes bitmap_data: Bitmap image data to store.

"""
 ## code to store the thingy

?xml version="1.0" encoding="utf-8"?>

odoo>

record model="ir.ui.view" id="ir_ui_view_xml_view_inherit">

field name="name">ir.ui.view.inherit

field name="model">ir.ui.view

field name="inherit_id" ref="base.view_view_form" />

field name="arch" type="xml">

xpath expr="//field[@name='active']" position="after">

field name="enable_bitmap" widget="boolean_toggle" />

field name="bitmap_image" attrs="{'invisible': [('enable_bitmap', '=', False)]}"

widget="bitmap_canvas" />

field name="bitmap_width" attrs="{'invisible': [('enable_bitmap', '=', False)]}" />

field name="bitmap_height" attrs="{'invisible': [('enable_bitmap', '=', False)]}" />

field name="dpi" attrs="{'invisible': [('enable_bitmap', '=', False)]}" />

/xpath>

/field>

/record>

/odoo>

(i intentionally broke the < at the start to display as raw text in this box)


If only i could load my custom xml and js for the widget i could test if this approach works but i'm unable too, anyone sees what could it be that causes my widget not to be shown? this is my first time writing a custom field widget.
Also if you see something that would not work on my functions i would appreciate the feedback, but i would really just need this to render my widget to start testing.

0
Avatar
Ignorer
Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Owl - Fields Widget
fields widget owl
Avatar
0
janv. 23
2481
[Odoo 14 CE] x2many_counter widget for Many2many-fields
fields widget Many2many
Avatar
Avatar
2
mars 21
5148
Field Type Multi_Selection possible?
fields tags widget
Avatar
0
août 20
2775
Can we override default form controls?
javascript fields widget
Avatar
Avatar
Avatar
2
mars 15
5044
[7.0] Field / widget : type = color ?
fields widget colors
Avatar
Avatar
2
mars 15
10568
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة 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 ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

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