moment.js 未在 odoo 模块中定义

问题描述 投票:0回答:1

当我尝试在 odoo 模块中使用 moment 时,它遇到了如下错误:

以下模块是其他模块所需要的,但尚未定义,它们可能不存在于正确的资源包中: 片刻 无法加载以下模块,因为它们具有未满足的依赖关系,这是一个次要错误,可能是由上述问题之一引起的:

@my_dashboard/组件/sales_dashboard

import { registry } from "@web/core/registry"
import { KpiCard } from "./kpi_card/kpi_card"
import { ChartRenderer } from "./chart_renderer/chart_renderer"
import { loadJS } from "@web/core/assets"
import moment from 'moment';
import { useService } from "@web/core/utils/hooks"
const { Component, onWillStart, useRef, onMounted, useState } = owl

export class OwlSalesDashboard extends Component {
    setup(){
        this.state=useState({
            quotations:{
                value:10,
                percentage:6,
            },
            period:90,
        })
        this.orm=useService("orm")
        onWillStart(async() => {
            await this.getQuotations()
        })
    }
    onChangePeriod() {
        console.log(this.state.period)
        console.log(moment().format())
    }
    async getQuotations(){
        const data = await this.orm.searchCount("sale.order",[['state','in',['send','draft']]])
        this.state.quotations.value = data
    }
}

OwlSalesDashboard.template = "owl.OwlSalesDashboard"
OwlSalesDashboard.components = { KpiCard, ChartRenderer }

registry.category("actions").add("owl.sales_dashboard", OwlSalesDashboard)

错误截图

sales_dashboard.js

瞬间安装成功

请给出正确答案

python odoo chart.js momentjs odoo-17
1个回答
0
投票

moment
推荐使用
luxon
,它已经在Odoo

中可用

Luxon 可以被认为是 Moment 的进化

Odoo 迁移(Odoo 16):

moment().format()  

致(Odoo 17):

DateTime.now().toFormat("yyyy-MM-dd'T'HH:mm:ssZZ")
© www.soinside.com 2019 - 2024. All rights reserved.