Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
1569 Переглядів

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

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
серп. 24
1218
1
бер. 23
3217
1
жовт. 20
3380
1
лют. 20
6552
0
лип. 19
3140