Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
1376 Näkymät

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', [], [], {})
}

}

















Avatar
Hylkää
Paras vastaus

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


Avatar
Hylkää
Tekijä Paras vastaus

I have solved the issue as your suggestion.

Thank you very much

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
elok. 24
1058
1
maalisk. 23
3041
1
lokak. 20
3218
1
helmik. 20
6376
0
heinäk. 19
3011