Pular para o conteúdo
Odoo Menu
  • Entrar
  • Experimente grátis
  • Aplicativos
    Finanças
    • Financeiro
    • Faturamento
    • Despesas
    • Planilhas (BI)
    • Documentos
    • Assinar Documentos
    Vendas
    • CRM
    • Vendas
    • PDV Loja
    • PDV Restaurantes
    • Assinaturas
    • Locação
    Websites
    • Criador de Sites
    • e-Commerce
    • Blog
    • Fórum
    • Chat ao Vivo
    • e-Learning
    Cadeia de mantimentos
    • Inventário
    • Fabricação
    • PLM - Ciclo de Vida do Produto
    • Compras
    • Manutenção
    • Qualidade
    Recursos Humanos
    • Funcionários
    • Recrutamento
    • Folgas
    • Avaliações
    • Indicações
    • Frota
    Marketing
    • Redes Sociais
    • Marketing por E-mail
    • Marketing por SMS
    • Eventos
    • Automação de Marketing
    • Pesquisas
    Serviços
    • Projeto
    • Planilhas de Horas
    • Serviço de Campo
    • Central de Ajuda
    • Planejamento
    • Compromissos
    Produtividade
    • Mensagens
    • Aprovações
    • Internet das Coisas
    • VoIP
    • Conhecimento
    • WhatsApp
    Aplicativos de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Varejo
    • Loja de livros
    • Loja de roupas
    • Loja de móveis
    • Mercearia
    • Loja de ferramentas
    • Loja de brinquedos
    Comida e hospitalidade
    • Bar e Pub
    • Restaurante
    • Fast Food
    • Hospedagem
    • Distribuidor de bebidas
    • Hotel
    Imóveis
    • Imobiliária
    • Escritório de arquitetura
    • Construção
    • Administração de propriedades
    • Jardinagem
    • Associação de proprietários de imóveis
    Consultoria
    • Escritório de Contabilidade
    • Parceiro Odoo
    • Agência de marketing
    • Escritório de advocacia
    • Aquisição de talentos
    • Auditoria e Certificação
    Fabricação
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Presentes corporativos
    Saúde e Boa forma
    • Clube esportivo
    • Loja de óculos
    • Academia
    • Profissionais de bem-estar
    • Farmácia
    • Salão de cabeleireiro
    Comércio
    • Handyman
    • Hardware e Suporte de TI
    • Sistemas de energia solar
    • Sapataria
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência Ambiental
    • Aluguel de outdoors
    • Fotografia
    • Aluguel de bicicletas
    • Revendedor de software
    Navegar por todos os setores
  • Comunidade
    Aprenda
    • Tutoriais
    • Documentação
    • Certificações
    • Treinamento
    • Blog
    • Podcast
    Empodere a Educação
    • Programa de educação
    • Scale Up! Jogo de Negócios
    • Visite a Odoo
    Obtenha o Software
    • Baixar
    • Comparar edições
    • Releases
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Cadastre seu escritório contábil
    Obtenha os serviços
    • Encontre um parceiro
    • Encontre um Contador
    • Conheça um consultor
    • Serviços de Implementação
    • Referências de Clientes
    • Suporte
    • Upgrades
    Github YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Faça uma demonstração
  • Preços
  • Ajuda

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

  • CRM
  • e-Commerce
  • Financeiro
  • Inventário
  • PoS
  • Projeto
  • MRP
All apps
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
É necessário estar registrado para interagir com a comunidade.
Todas as publicações Pessoas Emblemas
Marcadores (Ver tudo)
odoo accounting v14 pos v15
Sobre este fórum
Ajuda

Custom Code: widget error - TypeError: can't convert undefined to object

Inscrever

Seja notificado quando houver atividade nesta publicação

Esta pergunta foi sinalizada
undefinedUncaughtPromiseError
2 Respostas
1350 Visualizações
Avatar
Neil Howard

I have an overlay widget with a toggle of pass fail, the toggle works in such that it toggles as expected but each time in generated the following error and nothing seems to fix it. The error is as follows and I'm using 

Odoo Client Error

UncaughtPromiseError > TypeError


Uncaught Promise > can't convert undefined to object


Occured on [redacted] on 2025-07-02 11:46:49 GMT


TypeError: can't convert undefined to object

    _preprocessPropertiesChanges@[redacted]/web/assets/debug/web.assets_web.js:57849:49

    _update@[redacted]/web/assets/debug/web.assets_web.js:58170:18

    update/<@[redacted]/web/assets/debug/web.assets_web.js:57185:24

    always@[redacted]/web/assets/debug/web.assets_web.js:41466:36

    promise callback*exec@[redacted]/web/assets/debug/web.assets_web.js:41472:33

    update@[redacted]/web/assets/debug/web.assets_web.js:57184:33

    togglePassFail@[redacted]/web/assets/debug/web.assets_web.js:248270:31

    template/hdlr2<@[redacted]/web/assets/debug/web.assets_web.js line 13745 > Function:27:27

    mainEventHandler@[redacted]/web/assets/debug/web.assets_web.js:14072:25

    listener@[redacted]/web/assets/debug/web.assets_web.js:8404:20

    EventListener.handleEvent*setup@[redacted]/web/assets/debug/web.assets_web.js:8408:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:9118:37

    mount@[redacted]/web/assets/debug/web.assets_web.js:9219:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:9131:35

    mount@[redacted]/web/assets/debug/web.assets_web.js:9027:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:9131:35

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:9131:35

    mount@[redacted]/web/assets/debug/web.assets_web.js:9027:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:9131:35

    mount@[redacted]/web/assets/debug/web.assets_web.js:9027:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:8483:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:9131:35

    mount@[redacted]/web/assets/debug/web.assets_web.js:9027:27

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:9501:28

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:10620:18

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    mount@[redacted]/web/assets/debug/web.assets_web.js:8035:24

    patch@[redacted]/web/assets/debug/web.assets_web.js:9179:36

  

This is the code im using:

/** @odoo-module **/


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

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

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

import { standardFieldProps } from "@web/views/fields/standard_field_props";


console.log("van_check_overlay.js loaded!", new Date().toISOString());


function extractM2O(val, fallbackName) {

    if (val && typeof val === "object" && val.target && Array.isArray(val.target)) {

        val = val.target;

    }

    if (Array.isArray(val)) return Array.from(val);

    let v = val, safety = 0;

    while (v && typeof v === "object" && typeof v.id !== "undefined" && v.id !== null && safety < 5) {

        if (typeof v.id === "object" && v.id !== null) {

            v = v.id;

            safety++;

        } else {

            return [v.id, v.display_name || v.name || fallbackName || ""];

        }

    }

    if (v && v.data && typeof v.data.id !== "undefined" && v.data.id !== null) {

        return [v.data.id, v.data.display_name || v.data.name || fallbackName || ""];

    }

    if (v && v.target && typeof v.target.id !== "undefined" && v.target.id !== null) {

        return [v.target.id, v.target.display_name || v.target.name || fallbackName || ""];

    }

    if (typeof v === "number" || typeof v === "string") {

        return [v, fallbackName || ""];

    }

    return false;

}


function safe(obj, key, fallback) {

    if (typeof obj[key] !== "undefined" && obj[key] !== null) return obj[key];

    return fallback;

}


class VanCheckOverlay extends Component {

    static props = { ...standardFieldProps };

    static supportedTypes = ["one2many"];


    setup() {

        this.orm   = useService("orm");

        this.state = useState({ template: null, trigger: 0 });

        this.imgRef = useRef("imgRef");


        onWillStart(async () => {

            const raw = this.props.record.data.template_id;

            const tplId = Array.isArray(raw) ? raw[0] : (raw?.id || raw);

            if (!tplId) return;


            const [tpl] = await this.orm.read(

                "van.weekly.checklist.template",

                [tplId],

                ["image", "line_template_ids"]

            );

            if (!tpl) return;


            tpl.line_template_ids = tpl.line_template_ids.length

                ? await this.orm.read(

                    "van.weekly.checklist.line.template",

                    tpl.line_template_ids,

                    ["id", "code", "name", "position_x", "position_y", "sequence"]

                  )

                : [];

            this.state.template = tpl;

        });

    }


    get imgSrc() {

        return this.state.template?.image

            ? `data:image/png;base64,${this.state.template.image}`

            : "/van_weekly_checklist/static/src/img/van.png";

    }


    get instanceLineMap() {

        const map = {};

        const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

        for (const rec of lines) {

            let data = rec.data || rec;

            let tli = data.template_line_id;

            let tid;

            if (tli && typeof tli === "object" && typeof tli.id !== "undefined" && tli.id !== null) {

                tid = tli.id;

            } else if (tli && tli.target && typeof tli.target.id !== "undefined" && tli.target.id !== null) {

                tid = tli.target.id;

            } else if (tli && tli.data && typeof tli.data.id !== "undefined" && tli.data.id !== null) {

                tid = tli.data.id;

            } else if (typeof tli === "object" && Array.isArray(tli.target)) {

                tid = tli.target[0];

            } else if (Array.isArray(tli)) {

                tid = tli[0];

            } else {

                tid = tli;

            }

            if (tid) map[tid] = rec;

        }

        return map;

    }


    get templateLines() {

        return this.state.template?.line_template_ids || [];

    }


    getInstanceLine(tline) {

        return this.instanceLineMap[tline.id];

    }


    spotClass(rec) {

        const data = rec?.data || rec;

        if (data?.pass_fail === "pass") return "van-check-spot pass";

        if (data?.pass_fail === "fail") return "van-check-spot fail";

        return "van-check-spot";

    }


    spotIcon(rec) {

        const data = rec?.data || rec;

        if (data?.pass_fail === "pass") return "✔️";

        if (data?.pass_fail === "fail") return "❌";

        return "";

    }


    async togglePassFail(tline) {

        const rec = this.getInstanceLine(tline);

        if (!rec) return;

        const data = rec.data || rec;

        const current = data.pass_fail || false;

        const next = current === "pass" ? "fail" : current === "fail" ? false : "pass";


        let rawM2O = data.template_line_id;

        let resolvedM2O = extractM2O(rawM2O, tline.name);

        if (!resolvedM2O || resolvedM2O[0] === undefined || resolvedM2O[0] === null) {

            resolvedM2O = [tline.id, tline.name || ""];

        }


        // Defensive: try id, but fallback to [id, name] for new records

        let isNew = !rec.res_id;

        let updateObj = {

            pass_fail: next,

            template_line_id: isNew ? resolvedM2O : resolvedM2O[0],

            code: safe(data, "code", safe(tline, "code", "")),

            name: safe(data, "name", safe(tline, "name", "")),

            position_x: typeof safe(data, "position_x", safe(tline, "position_x", 0)) === "number" ? safe(data, "position_x", safe(tline, "position_x", 0)) : 0,

            position_y: typeof safe(data, "position_y", safe(tline, "position_y", 0)) === "number" ? safe(data, "position_y", safe(tline, "position_y", 0)) : 0,

            sequence: typeof safe(data, "sequence", safe(tline, "sequence", 0)) === "number" ? safe(data, "sequence", safe(tline, "sequence", 0)) : 0,

        };


        // Final double-check: no undefined/null at all

        Object.keys(updateObj).forEach(field => {

            if (typeof updateObj[field] === "undefined" || updateObj[field] === null) {

                if (["position_x", "position_y", "sequence"].includes(field)) updateObj[field] = 0;

                else updateObj[field] = "";

            }

        });


        // Log every field & type for debug

        console.log("togglePassFail updateObj:");

        Object.entries(updateObj).forEach(([k, v]) => console.log(`  ${k}:`, v, typeof v));

        try {

            if (rec.update) {

                rec.update(updateObj);

            } else {

                throw new Error("rec.update missing, will patch manually");

            }

        } catch (e) {

            // Fallback: patch data directly

            data.pass_fail = next;

            data.template_line_id = isNew ? resolvedM2O : resolvedM2O[0];

            data.code = updateObj.code;

            data.name = updateObj.name;

            data.position_x = updateObj.position_x;

            data.position_y = updateObj.position_y;

            data.sequence = updateObj.sequence;

            console.warn("rec.update failed, patched data manually", e);

        }


        if (rec.res_id) {

            try {

                await this.orm.write("van.weekly.checklist.line", [rec.res_id], { pass_fail: next });

            } catch (err) {

                console.warn("ORM write failed:", err);

            }

        }


        if (this.props.record.update) {

            this.props.record.update();

        }

        this.state.trigger = Math.random();


        const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

        console.log("After update:", lines.map(l => l.data || l));

    }


    debug() {

        console.log("INSTANCE MAP", this.instanceLineMap);

        const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

        lines.forEach((line, i) => {

            let data = line.data || line;

            console.log(`Line ${i}:`, line, data);

        });

    }

}


VanCheckOverlay.template = xml`

  <div class="van-image-container" style="position:relative;">

    <button type="button" t-on-click="debug" style="margin-bottom:12px;">Debug</button>

    <img t-ref="imgRef" t-att-src="imgSrc" class="van-full-image"/>

    <t t-foreach="templateLines" t-as="tline" t-key="tline.id">

      <div

        t-att-class="spotClass(getInstanceLine(tline))"

        t-att-style="'left:' + (tline.position_x||0) + 'px; top:' + (tline.position_y||0) + 'px;'"

        style="cursor:pointer;"

        t-on-click="() => this.togglePassFail(tline)"

      >

        <span class="label" t-esc="tline.code"/>

        <span t-esc="tline.name"/>

        <t t-set="rec" t-value="getInstanceLine(tline)"/>

        <t t-if="rec">

          <span class="toggle-value" style="margin-left:10px;font-weight:bold;font-size:18px;">

            <t t-esc="spotIcon(rec)"/>

          </span>

        </t>

      </div>

    </t>

  </div>

`;


registry.category("fields").add("check_overlay", {

    component: VanCheckOverlay,

    fields: [

        "line_ids",

        "line_ids.template_line_id",

        "line_ids.code",

        "line_ids.name",

        "line_ids.position_x",

        "line_ids.position_y",

        "line_ids.pass_fail",

        "line_ids.sequence"

    ]

});


export default VanCheckOverlay;

0
Avatar
Cancelar
Avatar
D Enterprise
Melhor resposta

Hii

Update via record line_ids relation
Use this.props.record.update() and replace the entire line_ids field with a patched copy:

let currentLines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

let newLines = currentLines.map(line => {

    let data = line. data || line;

    let isThis = this.getInstanceLine(tline) === line;

    if (!isThis) return line;

    return {

        ...data,

        ...updateObj,

    };

});


// 2. Update entire line_ids field

this.props.record.update({

    line_ids: newLines,

});

This avoids directly calling .update() on individual lines — which OWL does not support by default, unless you're using useList() or OWL 2 advanced patterns.

update your code add this 
i hope it is use full

0
Avatar
Cancelar
Neil Howard
Autor

many thanks for the reply. i updated my js to the below but sadly no luck. i get a new error and the pass fail click toggle no longer works.

UncaughtPromiseError > TypeError

Uncaught Promise > can't convert undefined to object

Occured on [redacted] on 2025-07-02 12:46:50 GMT

TypeError: can't convert undefined to object

_preprocessPropertiesChanges@[redacted]/web/assets/debug/web.assets_web.js:57849:49

_update@[redacted]/web/assets/debug/web.assets_web.js:58170:18

update/<@[redacted]/web/assets/debug/web.assets_web.js:57185:24

always@[redacted]/web/assets/debug/web.assets_web.js:41466:36

/** @odoo-module **/

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

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

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

import { standardFieldProps } from "@web/views/fields/standard_field_props";

console.log("van_check_overlay.js loaded!", new Date().toISOString());

function extractM2O(val, fallbackName) {

if (!val) return [false, fallbackName || ""];

if (val && typeof val === "object" && val.target && Array.isArray(val.target)) {

val = val.target;

}

if (Array.isArray(val)) return Array.from(val);

let v = val, safety = 0;

while (v && typeof v === "object" && typeof v.id !== "undefined" && v.id !== null && safety < 5) {

if (typeof v.id === "object" && v.id !== null) {

v = v.id;

safety++;

} else {

return [v.id, v.display_name || v.name || fallbackName || ""];

}

}

if (v && v.data && typeof v.data.id !== "undefined" && v.data.id !== null) {

return [v.data.id, v.data.display_name || v.data.name || fallbackName || ""];

}

if (v && v.target && typeof v.target.id !== "undefined" && v.target.id !== null) {

return [v.target.id, v.target.display_name || v.target.name || fallbackName || ""];

}

if (typeof v === "number" || typeof v === "string") {

return [v, fallbackName || ""];

}

return [false, fallbackName || ""];

}

function safe(obj, key, fallback) {

if (typeof obj[key] !== "undefined" && obj[key] !== null) return obj[key];

return fallback;

}

class VanCheckOverlay extends Component {

static props = { ...standardFieldProps };

static supportedTypes = ["one2many"];

setup() {

this.orm = useService("orm");

this.state = useState({ template: null, trigger: 0 });

this.imgRef = useRef("imgRef");

onWillStart(async () => {

const raw = this.props.record.data.template_id;

const tplId = Array.isArray(raw) ? raw[0] : (raw?.id || raw);

if (!tplId) return;

const [tpl] = await this.orm.read(

"van.weekly.checklist.template",

[tplId],

["image", "line_template_ids"]

);

if (!tpl) return;

tpl.line_template_ids = tpl.line_template_ids.length

? await this.orm.read(

"van.weekly.checklist.line.template",

tpl.line_template_ids,

["id", "code", "name", "position_x", "position_y", "sequence"]

)

: [];

this.state.template = tpl;

});

}

get imgSrc() {

return this.state.template?.image

? `data:image/png;base64,${this.state.template.image}`

: "/van_weekly_checklist/static/src/img/van.png";

}

get instanceLineMap() {

const map = {};

const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

for (const rec of lines) {

let data = rec.data || rec;

let tli = data.template_line_id;

let tid = extractM2O(tli)[0];

if (tid) map[tid] = rec;

}

return map;

}

get templateLines() {

return this.state.template?.line_template_ids || [];

}

getInstanceLine(tline) {

return tline && tline.id ? this.instanceLineMap[tline.id] : undefined;

}

spotClass(rec) {

const data = rec?.data || rec;

if (data?.pass_fail === "pass") return "van-check-spot pass";

if (data?.pass_fail === "fail") return "van-check-spot fail";

return "van-check-spot";

}

spotIcon(rec) {

const data = rec?.data || rec;

if (data?.pass_fail === "pass") return "✔️";

if (data?.pass_fail === "fail") return "❌";

return "";

}

async togglePassFail(tline) {

if (!tline) return;

const rec = this.getInstanceLine(tline);

if (!rec) return;

const data = rec.data || rec;

const current = data.pass_fail || false;

const next = current === "pass" ? "fail" : current === "fail" ? false : "pass";

let rawM2O = data.template_line_id;

let resolvedM2O = extractM2O(rawM2O, tline.name);

if (!resolvedM2O || resolvedM2O[0] === false) {

resolvedM2O = [tline.id, tline.name || ""];

}

let isNew = !rec.res_id;

let updateObj = {

pass_fail: next,

template_line_id: isNew ? resolvedM2O : resolvedM2O[0],

code: safe(data, "code", safe(tline, "code", "")),

name: safe(data, "name", safe(tline, "name", "")),

position_x: Number(safe(data, "position_x", safe(tline, "position_x", 0))),

position_y: Number(safe(data, "position_y", safe(tline, "position_y", 0))),

sequence: Number(safe(data, "sequence", safe(tline, "sequence", 0))),

};

Object.keys(updateObj).forEach(field => {

if (typeof updateObj[field] === "undefined" || updateObj[field] === null) {

if (["position_x", "position_y", "sequence"].includes(field)) updateObj[field] = 0;

else updateObj[field] = "";

}

});

// SAFER: always update via record.update({ line_ids: [...] }) to avoid OWL/Proxy issues

let currentLines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

let newLines = currentLines.map(line => {

let lineData = line.data || line;

let isThis = this.getInstanceLine(tline) === line;

if (!isThis) return line;

// For new lines, update .data, for existing, update plain object

return rec.data ? { ...lineData, ...updateObj } : Object.assign({}, line, updateObj);

});

this.props.record.update({ line_ids: newLines });

if (rec.res_id) {

try {

await this.orm.write("van.weekly.checklist.line", [rec.res_id], { pass_fail: next });

} catch (err) {

console.warn("ORM write failed:", err);

}

}

if (this.props.record.update) {

this.props.record.update();

}

this.state.trigger = Math.random();

const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

console.log("After update:", lines.map(l => l.data || l));

}

debug() {

console.log("INSTANCE MAP", this.instanceLineMap);

const lines = this.props.record.data.line_ids?.records || this.props.record.data.line_ids || [];

lines.forEach((line, i) => {

let data = line.data || line;

console.log(`Line ${i}:`, line, data);

});

}

}

VanCheckOverlay.template = xml`

<div class="van-image-container" style="position:relative;">

<button type="button" t-on-click="debug" style="margin-bottom:12px;">Debug</button>

<img t-ref="imgRef" t-att-src="imgSrc" class="van-full-image"/>

<t t-foreach="templateLines" t-as="tline" t-key="tline.id">

<div

t-att-class="spotClass(getInstanceLine(tline))"

t-att-style="'left:' + (tline.position_x||0) + 'px; top:' + (tline.position_y||0) + 'px;'"

style="cursor:pointer;"

t-on-click="() => this.togglePassFail(tline)"

>

<span class="label" t-esc="tline.code"/>

<span t-esc="tline.name"/>

<t t-set="rec" t-value="getInstanceLine(tline)"/>

<t t-if="rec">

<span class="toggle-value" style="margin-left:10px;font-weight:bold;font-size:18px;">

<t t-esc="spotIcon(rec)"/>

</span>

</t>

</div>

</t>

</div>

`;

registry.category("fields").add("check_overlay", {

component: VanCheckOverlay,

fields: [

"line_ids",

"line_ids.template_line_id",

"line_ids.code",

"line_ids.name",

"line_ids.position_x",

"line_ids.position_y",

"line_ids.pass_fail",

"line_ids.sequence"

]

});

export default VanCheckOverlay;

D Enterprise

import { Component, xml, useRef, useState, onWillStart } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { registry } from "@web/core/registry";
import { standardFieldProps } from "@web/views/fields/standard_field_props";

function extractM2O(val, fallbackName) {
if (!val) return [false, fallbackName || ""];
if (val && typeof val === "object" && val.target && Array.isArray(val.target)) val = val.target;
if (Array.isArray(val)) return Array.from(val);

let v = val, safety = 0;
while (v && typeof v === "object" && typeof v.id !== "undefined" && v.id !== null && safety < 5) {
if (typeof v.id === "object" && v.id !== null) {
v = v.id;
safety++;
} else {
return [v.id, v.display_name || v.name || fallbackName || ""];
}
}

if (v?.data?.id !== undefined) return [v.data.id, v.data.display_name || fallbackName || ""];
if (v?.target?.id !== undefined) return [v.target.id, v.target.display_name || fallbackName || ""];
if (typeof v === "number" || typeof v === "string") return [v, fallbackName || ""];
return [false, fallbackName || ""];
}

function safe(obj, key, fallback) {
return (typeof obj[key] !== "undefined" && obj[key] !== null) ? obj[key] : fallback;
}

class VanCheckOverlay extends Component {
static props = { ...standardFieldProps };
static supportedTypes = ["one2many"];

setup() {
this.orm = useService("orm");
this.state = useState({ template: null, trigger: 0 });
this.imgRef = useRef("imgRef");

onWillStart(async () => {
const raw = this.props.record.data.template_id;
const tplId = Array.isArray(raw) ? raw[0] : (raw?.id || raw);
if (!tplId) return;

const [tpl] = await this.orm.read("van.weekly.checklist.template", [tplId], ["image", "line_template_ids"]);
if (!tpl) return;

tpl.line_template_ids = tpl.line_template_ids.length
? await this.orm.read("van.weekly.checklist.line.template", tpl.line_template_ids, ["id", "code", "name", "position_x", "position_y", "sequence"])
: [];

this.state.template = tpl;
});
}

get imgSrc() {
return this.state.template?.image
? `data:image/png;base64,${this.state.template.image}`
: "/van_weekly_checklist/static/src/img/van.png";
}

get instanceLineMap() {
const map = {};
const lines = this.props.record.data.line_ids?.records || [];
for (const rec of lines) {
const data = rec.data || rec;
const tid = extractM2O(data.template_line_id)[0];
if (tid) map[tid] = rec;
}
return map;
}

get templateLines() {
return this.state.template?.line_template_ids || [];
}

getInstanceLine(tline) {
return tline && tline.id ? this.instanceLineMap[tline.id] : undefined;
}

spotClass(rec) {
const data = rec?.data || rec;
if (data?.pass_fail === "pass") return "van-check-spot pass";
if (data?.pass_fail === "fail") return "van-check-spot fail";
return "van-check-spot";
}

spotIcon(rec) {
const data = rec?.data || rec;
if (data?.pass_fail === "pass") return "✔️";
if (data?.pass_fail === "fail") return "❌";
return "";
}

async togglePassFail(tline) {
if (!tline) return;

const rec = this.getInstanceLine(tline);
if (!rec) return;

const data = rec.data || rec;
const current = data.pass_fail || false;
const next = current === "pass" ? "fail" : current === "fail" ? false : "pass";

const isNew = !rec.res_id;
const resolvedM2O = extractM2O(data.template_line_id, tline.name)[0] || tline.id;

const updateObj = {
pass_fail: next,
template_line_id: resolvedM2O,
code: safe(data, "code", safe(tline, "code", "")),
name: safe(data, "name", safe(tline, "name", "")),
position_x: Number(safe(data, "position_x", safe(tline, "position_x", 0))),
position_y: Number(safe(data, "position_y", safe(tline, "position_y", 0))),
sequence: Number(safe(data, "sequence", safe(tline, "sequence", 0))),
};

try {
if (!isNew) {
await this.orm.write("van.weekly.checklist.line", [rec.res_id], { pass_fail: next });

this.props.record.update({
line_ids: [[1, rec.res_id, { pass_fail: next }]],
});
} else {
const currentLines = this.props.record.data.line_ids?.records || [];
const newLines = currentLines.map(line => {
return line === rec ? { ...data, ...updateObj } : line;
});
this.props.record.update({ line_ids: newLines });
}
} catch (err) {
console.warn("Toggle update failed:", err);
}

this.state.trigger = Math.random();
}

debug() {
console.log("INSTANCE MAP", this.instanceLineMap);
const lines = this.props.record.data.line_ids?.records || [];
lines.forEach((line, i) => {
let data = line.data || line;
console.log(`Line ${i}:`, line, data);
});
}
}

VanCheckOverlay.template = xml`
<div class="van-image-container" style="position:relative;">
<button type="button" t-on-click="debug" style="margin-bottom:12px;">Debug</button>
<img t-ref="imgRef" t-att-src="imgSrc" class="van-full-image"/>
<t t-foreach="templateLines" t-as="tline" t-key="tline.id">
<div
t-att-class="spotClass(getInstanceLine(tline))"
t-att-style="'left:' + (tline.position_x || 0) + 'px; top:' + (tline.position_y || 0) + 'px;'"
style="cursor:pointer;"
t-on-click="() => this.togglePassFail(tline)"
>
<span class="label" t-esc="tline.code"/>
<span t-esc="tline.name"/>
<t t-set="rec" t-value="getInstanceLine(tline)"/>
<t t-if="rec">
<span class="toggle-value" style="margin-left:10px;font-weight:bold;font-size:18px;">
<t t-esc="spotIcon(rec)"/>
</span>
</t>
</div>
</t>
</div>
`;

registry.category("fields").add("check_overlay", {
component: VanCheckOverlay,
fields: [
"line_ids",
"line_ids.template_line_id",
"line_ids.code",
"line_ids.name",
"line_ids.position_x",
"line_ids.position_y",
"line_ids.pass_fail",
"line_ids.sequence",
],
});

export default VanCheckOverlay;
please try i hope it will fix

Está gostando da discussão? Não fique apenas lendo, participe!

Crie uma conta hoje mesmo para aproveitar os recursos exclusivos e interagir com nossa incrível comunidade!

Inscreva-se
Publicações relacionadas Respostas Visualizações Atividade
Caused by: SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON - Uncaught Promise > An error occured in the owl lifecycle (see this Error's "cause" property) Resolvido
javascript UncaughtPromiseError
Avatar
1
dez. 24
4827
How can in configure Odoo to allow Purchasing to order "Rolls" of an Item, and Warehouse to receive "Yards" - the quantity will always be variable Resolvido
undefined UOM
Avatar
Avatar
1
mar. 20
6048
TypeError: v is undefined
typeerror undefined
Avatar
0
jan. 16
9931
My Sales orders have all went to undefined
salesorders undefined
Avatar
Avatar
1
mar. 15
4188
ERROR to Create Invoices: Uncaught TypeError: Cannot read property '1' of undefined
error undefined
Avatar
0
mar. 15
5547
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Open Source
  • Baixar
  • Github
  • Runbot
  • Traduções
Serviços
  • Odoo.sh Hosting
  • Suporte
  • Upgrade
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um Contador
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • Nossa empresa
  • Ativos da marca
  • Contato
  • Empregos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة 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 é um conjunto de aplicativos de negócios em código aberto que cobre todas as necessidades de sua empresa: CRM, comércio eletrônico, contabilidade, estoque, ponto de venda, gerenciamento de projetos, etc.

A proposta de valor exclusiva Odoo é ser, ao mesmo tempo, muito fácil de usar e totalmente integrado.

Site feito com

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