我想在POS中添加一个产品线,但我遇到了一些错误

这是我的代码

                const productId = 293;
                const sel_product = await this.rpc({
                    model: "product.product",
                    method: "read",
                    args: [[productId]],
                });

                console.log("sel_product :", sel_product[0]);
                const newItem = {
                    id: productId,
                    product: sel_product[0],
                    qty: 1,
                    price: -300,
                };

                var Orderline = models.Orderline;
                var line = new Orderline({}, {
                      pos: this.env.pos,
                      order: this.env.pos.get_order(),
                      product: newItem.product});

                line.set_quantity(newItem.qty);
                this.env.pos.get_order().add_product(line);

我面临着一些错误

error fetching promotions: TypeError: this.product.get_unit is not a function
    at Orderline.get_unit 
    at Orderline.set_quantity

有人能在这件事上帮我吗?

推荐答案

我找到了一个解决方案

使用此代码

var product = this.env.pos.db.get_product_by_id(productId);
var order = this.env.pos.get_order();
if (product) {
    order.add_product(product);
} else {
    console.error("Error Not there");
}

Javascript相关问答推荐

如何访问react路由v6加载器函数中的查询参数/搜索参数

成帧器运动中的运动组件为何以收件箱开始?

React 17与React 18中的不同setState行为

Chrome是否忽略WebAuthentication userVerification设置?""

嵌套异步JavaScript(微任务和macrotask队列)

为什么这个JS模块在TypeScript中使用默认属性导入?""

Next.js(react)使用moment或不使用日期和时间格式

单击ImageListItemBar的IconButton后,在Material—UI对话框中显示图像

切换时排序对象数组,切换不起作用

将旋转的矩形zoom 到覆盖它所需的最小尺寸&S容器

引用在HTMLAttributes<;HTMLDivElement>;中不可用

如何在Vue 3中创建自定义 Select 组件,并将选项作为HTML而不是props 传递?

在open shadow—root中匹配时,使用jQuery删除一个封闭的div类

保持物品顺序的可变大小物品分配到平衡组的算法

我在Django中的视图中遇到多值键错误

使用NextJS+MongoDB+Prisma ORM获取无效请求正文,无法发布错误

如何在和IF语句中使用||和&;&;?

如何使用Astro优化大图像?

Node.js API-queryAll()中的MarkLogic数据移动

如何在单击Search按钮时更新Reaction组件?