Skip to Content
Odoo เมนู
  • ลงชื่อเข้าใช้
  • ทดลองใช้ฟรี
  • แอป
    การเงิน
    • ระบบบัญชี
    • ระบบการออกใบแจ้งหนี้
    • ระบบบัญชีรายจ่าย
    • ระบบการจัดการข้อมูลผ่านสเปรดชีต (BI)
    • เอกสาร
    • ระบบลงลายเซ็น
    การขาย
    • ลูกค้าสัมพันธ์
    • การขาย
    • POS ร้านค้า
    • POS ร้านอาหาร
    • ระบบสมัครสมาชิก
    • การเช่า
    การจัดการเว็บไซต์
    • เครื่องมือสร้างเว็บไซต์
    • ระบบการขายออนไลน์
    • บล็อก
    • ฟอรั่ม
    • ไลฟ์แชท
    • ระบบการอบรมออนไลน์
    ซัพพลายเชน
    • คลังสินค้า
    • ระบบการผลิต
    • PLM
    • ระบบการจัดซื้อ
    • การซ่อมบำรุง
    • ระบบจัดการคุณภาพ
    ทรัพยากรบุคคล
    • ข้อมูลพนักงาน
    • ระบบสรรหาบุคลากร
    • ระบบการลา
    • การประเมิน
    • ระบบการแนะนำพนักงาน
    • ระบบจัดการยานพาหนะ
    การตลาด
    • โซเชียลมาร์เก็ตติ้ง
    • การตลาดผ่านอีเมล
    • ระบบการตลาดผ่าน SMS
    • ระบบการจัดงานอีเวนต์
    • การตลาดแบบอัตโนมัติ
    • ระบบแบบสำรวจ
    การบริการ
    • โปรเจกต์
    • ระบบบันทึกเวลา
    • ระบบการจัดการบริการภาคสนาม
    • ระบบดูแลช่วยเหลือ
    • การวางแผน
    • การนัดหมาย
    ประสิทธิผล
    • ระบบแสดงความคิดเห็น
    • ระบบการอนุมัติ
    • ไอโอที
    • VoIP
    • คลังข้อมูล
    • WhatsApp
    แอปพลิเคชันของบุคคลที่สาม Odoo สตูดิโอ แพลตฟอร์มคลาวด์ของ Odoo
  • อุตสาหกรรม
    การค้าปลีก
    • ร้านขายหนังสือ
    • ร้านขายเสื้อผ้า
    • ร้านขายเฟอร์นิเจอร์
    • ร้านขายของชำ
    • ร้านขายฮาร์ดแวร์
    • ร้านขายของเล่น
    Food & Hospitality
    • บาร์และผับ
    • ร้านอาหาร
    • อาหารฟาสต์ฟู้ด
    • Guest House
    • ตัวแทนจำหน่ายเครื่องดื่ม
    • Hotel
    อสังหาริมทรัพย์
    • Real Estate Agency
    • บริษัทสถาปัตยกรรม
    • บริษัทรับเหมา
    • การจัดการอสังหาริมทรัพย์
    • การจัดสวน
    • สมาคมเจ้าของอสังหาริมทรัพย์
    ปรึกษา
    • สำนักงานบัญชี
    • Odoo พาร์ทเนอร์
    • เอเจนซี่การตลาด
    • สำนักงานกฎหมาย
    • บริการสรรหาบุคลากร
    • การตรวจสอบและการรับรอง
    ระบบการผลิต
    • Textile
    • เหล็ก
    • เฟอร์นิเจอร์
    • อาหาร
    • Brewery
    • ของขวัญขององค์กร
    สุขภาพ & ฟิตเนส
    • ชมรมกีฬา
    • ร้านขายแว่นตา
    • ฟิตเนส
    • ผู้ประกอบวิชาชีพด้านสุขภาพ
    • ร้านขายยา
    • ร้านทำผม
    Trades
    • ช่างซ่อม
    • ฮาร์ดแวร์และการสนับสนุนด้านไอที
    • ระบบพลังงานแสงอาทิตย์
    • ช่างทำรองเท้า
    • บริการทำความสะอาด
    • HVAC Services
    อื่น ๆ
    • Nonprofit Organization
    • สำนักงานสิ่งแวดล้อม
    • ร้านเช่าป้ายโฆษณา
    • การถ่ายภาพ
    • ร้านเช่าจักรยาน
    • ตัวแทนจำหน่ายซอฟต์แวร์
    Browse all Industries
  • คอมมูนิตี้
    ศึกษา
    • บทเรียน
    • เอกสารกำกับโปรแกรม
    • การรับรอง
    • การฝึกอบรม
    • บล็อก
    • พอดแคสต์
    เพิ่มศักยภาพให้กับการศึกษา
    • โปรแกรมการศึกษา
    • Scale Up! Business Game
    • เยี่ยมชม Odoo
    รับซอฟต์แวร์
    • ดาวน์โหลด
    • เปรียบเทียบรุ่น
    • เผยแพร่
    ทำงานร่วมกัน
    • Github
    • ฟอรั่ม
    • ระบบการจัดงานอีเวนต์
    • การแปล
    • ร่วมเป็นพาร์ทเนอร์
    • Services for Partners
    • ลงทะเบียนเพื่อสร้างบัญชีบริษัทของคุณ
    รับบริการ
    • ค้นหาพาร์ทเนอร์
    • ค้นหานักบัญชี
    • พบกับที่ปรึกษา
    • บริการติดตั้งระบบเพื่อใช้งาน
    • ข้อมูลอ้างอิงลูกค้า
    • การสนับสนุน
    • อัปเกรด
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    รับการสาธิต
  • ราคา
  • ช่วยเหลือ

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

  • ลูกค้าสัมพันธ์
  • e-Commerce
  • ระบบบัญชี
  • สินค้าคงคลัง
  • PoS
  • โปรเจกต์
  • MRP
All apps
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
All Posts คน เหรียญรางวัล
แท็ก (View all)
odoo accounting v14 pos v15
เกี่ยวกับฟอรั่มนี้
ช่วยเหลือ

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

ติดตาม

รับการแจ้งเตือนเมื่อมีกิจกรรมในโพสต์นี้

คำถามนี้ถูกตั้งค่าสถานะ
undefinedUncaughtPromiseError
2 ตอบกลับ
1348 มุมมอง
อวตาร
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
อวตาร
ละทิ้ง
อวตาร
D Enterprise
คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
Neil Howard
ผู้เขียน

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

สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!

สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!

ลงชื่อ
Related Posts ตอบกลับ มุมมอง กิจกรรม
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) แก้ไขแล้ว
javascript UncaughtPromiseError
อวตาร
1
ธ.ค. 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 แก้ไขแล้ว
undefined UOM
อวตาร
อวตาร
1
มี.ค. 20
6047
TypeError: v is undefined
typeerror undefined
อวตาร
0
ม.ค. 16
9930
My Sales orders have all went to undefined
salesorders undefined
อวตาร
อวตาร
1
มี.ค. 15
4188
ERROR to Create Invoices: Uncaught TypeError: Cannot read property '1' of undefined
error undefined
อวตาร
0
มี.ค. 15
5547
คอมมูนิตี้
  • บทเรียน
  • เอกสารกำกับโปรแกรม
  • ฟอรั่ม
โอเพนซอร์ส
  • ดาวน์โหลด
  • Github
  • Runbot
  • การแปล
บริการ
  • โฮสติ้ง odoo.sh เซิร์ฟเวอร์
  • การสนับสนุน
  • อัปเกรด
  • การพัฒนาที่กำหนดเอง
  • การศึกษา
  • ค้นหานักบัญชี
  • ค้นหาพาร์ทเนอร์
  • ร่วมเป็นพาร์ทเนอร์
เกี่ยวกับเรา
  • บริษัทของเรา
  • ทรัพย์สินในรูปของเครื่องหมายการค้า
  • ติดต่อเรา
  • งาน
  • ระบบการจัดงานอีเวนต์
  • พอดแคสต์
  • บล็อก
  • ลูกค้า
  • กฎหมาย • ความเป็นส่วนตัว
  • ความปลอดภัย
الْعَرَبيّة 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 เป็นชุดแอปธุรกิจแบบเปิดที่ครอบคลุมทุกความต้องการของบริษัทของคุณ อาธิ CRM eCommerce ระบบบัญชี ระบบสินค้าคงคลัง ระบบการขายหน้าร้าน โปรเจกต์ และ อีกมากมาย

ความเหนือกว่าอันเป็นเอกลักษณ์ของ Odoo คือการใช้งานที่ง่ายดายและผสานการทำงานอย่างสมบูรณ์แบบในเวลาเดียวกัน

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