Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

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

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
undefinedUncaughtPromiseError
2 Besvarelser
1349 Visninger
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
Kassér
Avatar
D Enterprise
Bedste svar

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
Kassér
Neil Howard
Forfatter

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
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) Løst
javascript UncaughtPromiseError
Avatar
1
dec. 24
4822
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 Løst
undefined UOM
Avatar
Avatar
1
mar. 20
6047
TypeError: v is undefined
typeerror undefined
Avatar
0
jan. 16
9930
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
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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