跳至内容
菜单
此问题已终结
2 回复
1366 查看

Hi all,

I create my dashboard, I add a list box containing product list.

I load products from product_template model to the list box, all products are loaded successfully when I run dashboard. But when I select an item from the list box all items are removed.

I do not understand why. Help me please. 

Thank you very much

Below is my code:

import { registry } from "@web/core/registry"
import { loadJS } from "@web/core/assets"
import { useService } from "@web/core/utils/hooks"
const { Component, onWillStart, useState, onWillUpdateProps, useEffect, onWillUnmount } = owl
import { session } from "@web/session";

export class OwlApplicationDashboard extends Component {
setup(){
this.state = useState({
product: {},
})
this.orm = useService("orm")
this.actionService = useService("action")

onWillStart(async ()=>{
await this.fetchProduct()
})

}

async fetchProduct() {
this.state.product = await this.orm.silent.searchRead('product.template', [], [], {})
}

}

















形象
丢弃
最佳答案

Hello Ngoc,

You can load products from either of the way

1. Odoo OWL :
   Define state for or managing and saving selected products, you can define the selectedProduct state in this.state. You can exclude selected items and render non selected products in dropdown. 

onWillStart(async ()=>{
await this.fetchProduct()
})

You need to exclude the selected products stored in state while fetch products.

2.  Another easy way is to use many2many or selectionfield fields in your Python model for selection purposes. Python will automatically automatically handle selected products rendering behind the scene. 
Please refer odoo official document for the same
ORM API — Odoo 17.0 documentation

I hope this will help you !

Thanks,
Vimal Rughani (Founder and CTO)
Himanjali Intelligent Automation Pvt Ltd
Contact:
 +91- 972-606-7737
Emailhello@himanjali.com 
NewsletterThe Odoo Scoop
Websitewww.himanjali.co


形象
丢弃
编写者 最佳答案

I have solved the issue as your suggestion.

Thank you very much

形象
丢弃
相关帖文 回复 查看 活动
1
8月 24
1046
1
3月 23
3022
1
10月 20
3214
1
2月 20
6368
0
7月 19
3006