Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
undefinedUncaughtPromiseError
2 Odgovori
1346 Prikazi
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
Opusti
Avatar
D Enterprise
Best Answer

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
Opusti
Neil Howard
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
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) Solved
javascript UncaughtPromiseError
Avatar
1
dec. 24
4820
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 Solved
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
4186
ERROR to Create Invoices: Uncaught TypeError: Cannot read property '1' of undefined
error undefined
Avatar
0
mar. 15
5547
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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