u/Salty_Draft_9907

▲ 2 r/Odoo

Using image_data_uri on the img tag source property to get an image from the documents app

Hello odooers.

I am trying to get an image to show in an XML report using the img tag. To place the image in there I uploaded it in the documents module.

From there how to add the image in the sec property of the img tag to be displayed in the report?

reddit.com
u/Salty_Draft_9907 — 3 days ago
▲ 1 r/Odoo

Wizard presisting data problem when applying changes to other models

Hello Odooers,

I have a problem when saving changes made in a wizard to a model record in the system.

The structure is as follows:

  1. Wizard model
  2. Wizard line model (this model contains the desired changes)

However, when saving, the data from the wizard line model seems to be erased/reset, which prevents correct updates/inserts into the database.

Here is the model structure:

from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
import logging

_logger = logging.getLogger(__name__)

# =========================================================
# Wizard Line
# =========================================================

class DemoAssignmentWizardLine(models.TransientModel):
    _name = 'demo.assignment.wizard.line'
    _description = 'Demo Assignment Wizard Line'

    item_id = fields.Many2one(
        'demo.item',
        string='Item',
        readonly=True,
    )

    already_linked = fields.Boolean(
        string='Already Linked',
        readonly=True,
    )

    selected = fields.Boolean(
        string='Select',
    )


# =========================================================
# Wizard
# =========================================================

class DemoAssignmentWizard(models.TransientModel):
    _name = 'demo.assignment.wizard'
    _description = 'Demo Assignment Wizard'

    parent_id = fields.Many2one(
        'demo.parent',
        string='Parent',
        required=True,
        readonly=True,
    )

    available_group_ids = fields.Many2many(
        'demo.group',
        compute='_compute_available_groups',
        string='Available Groups',
    )

    group_id = fields.Many2one(
        'demo.group',
        string='Group',
        required=True,
        domain="[('id', 'in', available_group_ids)]",
    )

    available_item_ids = fields.Many2many(
        'demo.item',
        'demo_assignment_item_rel',
        compute='_compute_available_items',
        string='Available Items',
        store=True,
    )

    line_ids = fields.Many2many(
        'demo.assignment.wizard.line',
        'demo_assignment_wizard_line_rel',
        string='Lines',
    )

    # =========================================================
    # DEFAULTS
    # =========================================================

    @api.model
    def default_get(self, fields_list):
        res = super().default_get(fields_list)

        parent_id = self.env.context.get('default_parent_id')

        if parent_id:
            res['parent_id'] = parent_id

        return res

    # =========================================================
    # COMPUTE AVAILABLE GROUPS
    # =========================================================

    @api.depends('parent_id')
    def _compute_available_groups(self):
        for rec in self:

            if not rec.parent_id:
                rec.available_group_ids = False
                continue

            parent_item_ids = rec.parent_id.item_ids.ids

            if not parent_item_ids:
                rec.available_group_ids = False
                continue

            groups = self.env['demo.group'].search([])

            available = groups.filtered(
                lambda g: bool(
                    set(g.allowed_item_ids.ids)
                    & set(parent_item_ids)
                )
            )

            rec.available_group_ids = available

    # =========================================================
    # COMPUTE AVAILABLE ITEMS
    # =========================================================

    @api.depends('parent_id', 'group_id')
    def _compute_available_items(self):
        for rec in self:

            if not rec.parent_id or not rec.group_id:
                rec.available_item_ids = False
                continue

            parent_item_ids = rec.parent_id.item_ids.ids
            group_item_ids = rec.group_id.allowed_item_ids.ids

            available_items = self.env['demo.item'].search([
                ('id', 'in', parent_item_ids),
                ('id', 'in', group_item_ids),
            ])

            rec.available_item_ids = available_items

    # =========================================================
    # ONCHANGE GROUP
    # =========================================================

    @api.onchange('group_id')
    def _onchange_group_id(self):
        for rec in self:

            if not rec.parent_id or not rec.group_id:
                rec.line_ids = [(5, 0, 0)]
                continue

            lines = []

            for item in rec.available_item_ids:

                line = self.env[
                    'demo.assignment.wizard.line'
                ].create({
                    'item_id': item.id,
                    'already_linked': False,
                    'selected': False,
                })

                existing_link = self.env[
                    'demo.link'
                ].search([
                    ('group_id', '=', rec.group_id.id),
                    ('item_id', '=', item.id),
                ], limit=1)

                is_linked = (
                    existing_link.parent_id == rec.parent_id
                )

                line.already_linked = is_linked
                line.selected = is_linked

                lines.append(line.id)

            rec.line_ids = [(6, 0, lines)]

    # =========================================================
    # ACTION APPLY
    # =========================================================

    def action_apply(self):
        self.ensure_one()

        if not self.parent_id or not self.group_id:
            raise ValidationError(
                _('Parent and Group are required.')
            )

        link_model = self.env['demo.link']

        for line in self.line_ids:

            existing_link = link_model.search([
                ('group_id', '=', self.group_id.id),
                ('item_id', '=', line.item_id.id),
            ], limit=1)

            if line.selected:

                if existing_link:
                    existing_link.parent_id = self.parent_id.id

                else:
                    link_model.create({
                        'group_id': self.group_id.id,
                        'item_id': line.item_id.id,
                        'parent_id': self.parent_id.id,
                    })

            else:

                if (
                    existing_link
                    and existing_link.parent_id == self.parent_id
                ):
                    existing_link.parent_id = False

        return {
            'type': 'ir.actions.act_window_close'
        }

What could be wrong here?

I know Odoo deletes transient records and resets them, but I thought that should happen only after the wizard closes, not during the action.

reddit.com
u/Salty_Draft_9907 — 5 days ago
▲ 1 r/Odoo

Missing required field error when trying to change configurations in settings

Hello odooers, hope you are doing well.

Whenever I try changing anything in the settings it keeps popping the missing required field error.

What could possibly cause that? I tried looking up required studio fields but didn't manage to find any.

How should I start looking around for this field the message is ambiguous.

I am using Odoo19 Saas.

reddit.com
u/Salty_Draft_9907 — 11 days ago
▲ 1 r/Odoo

Hello odooers.

I am using Odoo SaaS so no python customizations.

In this project the client wants the allocated_hours field to show the days between the given date ranges which is done no problems.

But when setting the value to allocated_hours field it runs computations that set the field to a different value.

I already added a new field to have the days value in but it doesn't factor into the remaining days calculation of the tasks yet.

The question is. Is it wise to make any changes to the allocated_hours field or should I just leave it as it is and use the new added field?

reddit.com
u/Salty_Draft_9907 — 24 days ago