Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2221 Weergaven

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.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
0
jan. 23
1575
2
mrt. 21
4143
0
aug. 20
1999
2
mrt. 15
4107
2
mrt. 15
9696