Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
1683 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore Risposta migliore

I have solved the issue as your suggestion.

Thank you very much

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
ago 24
1300
1
mar 23
3327
1
ott 20
3493
1
feb 20
6676
0
lug 19
3212