İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
3011 Görünümler

Hello everyone, 

I am using Odoo v12 and I am trying to create a function that if an item is not available it can't be selected or is removed from the list right after it is selected.

I want to show the warning message if an unavailable item is selected and also not allow the item to get added to the list.

As of right now, the item will still get added to the list and the message will pop up. I was able to clear the whole list using the commented out code [r.items = ' '], but I wanted to remove just the item that is unavailable.

Any ideas?

items = fields.Many2many('blockbuster.inventory', required=True)

@api.onchange('items') def _verify_movie_availability(self): for r in self: for t in r.items: get_item_id = t.id if get_item_id: get_movie = self.env['blockbuster.inventory'].search([('id', '=', get_item_id)]) if get_movie.available <= 0: # r.items = '' return { 'warning': { 'title': 'Item Unavailable', 'message': f'Sorry, "{get_movie.name}" is not available. Please remove it from the items list.', }, }
Avatar
Vazgeç
En İyi Yanıt

Hi,

You can pass domain in onchange function in odoo 12. If you are upgrading to higher versions like odoo 14 , this method of passing domain is deprecated.

@api.onchange('items')

def _verify_movie_availability(self):

    get_movies_list = []

    get_movie_ids = self.env['blockbuster.inventory'].search([]) 

    for movie_id in get_movie_ids.filtered(lambda l: l.available > 0):

        get_movies_list.append(movie_id.id)

    return {'domain': {'items': [('id', 'in', get_movies_list)]}}  

And then you can select only the items with available greater than zero.


Hope it helps,

Thanks

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Şub 19
3559
0
Tem 20
3318
0
Oca 20
6411
3
Mar 19
8811
2
Oca 18
4188