Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
1648 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis Jawaban Terbai

I have solved the issue as your suggestion.

Thank you very much

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Agu 24
1266
1
Mar 23
3289
1
Okt 20
3461
1
Feb 20
6633
0
Jul 19
3194