Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Restauration & Hôtellerie
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brasserie
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Commerce
    • Bricoleur
    • Matériel informatique & support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Parcourir toutes les industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services pour partenaires
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

Active ids not getting in wizard selection field function in Odoo17

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
v17
1 Répondre
3409 Vues
Avatar
Anil Issac
I was using a function to load list in selection field. It was working in Odoo16. When I checked same code in Odoo17 It is not working. The code added below.



from odoo.exceptions import UserError
from odoo import models, api, _, fields
import logging

_logger = logging.getLogger(__name__)
class TestOrderShop(models.TransientModel):
    _name = 'test.shop.wizard'
    _description = 'Test Shop'
   
    @api.model
    def default_get(self, fields):
   
        res = super(TestOrderShop, self).default_get(fields)     

        selected_ids = self.env['sale.order']._context.get('active_ids', [])
        _logger.info('\n\n\n\n  selected_ids  =  %s \n\n\n\n' % (selected_ids) )     
       
        return res   
   
   
    def _get_radio_button(self):
        selection=[
            ('cancel', "Cancel"),
            ('pending', "Pending"),
            ('ready', "Ready"),
        ]
        selected_ids = self.env['sale.order']._context.get('active_ids', [])
        _logger.info('\n\n\n\n  selected_ids  =  %s \n\n\n\n' % (selected_ids) )   
        #Conext value worked in Odoo16 
        #Not getting Context value here in Odoo17
       
       
        order_id = self.env['sale.order'].sudo().search([('id', 'in', selected_ids)])
       
        _logger.info('\n\n\n\n  _get_selection  =  %s \n\n\n\n' % (order_id.id) )   
             
        if order_id:     
            if not order_id.custom_id:
                selection=[('new_order', "New Order"),]
                return selection

        return selection


    test_block_id = fields.Many2one('test.block')
    shop_selection = fields.Selection(_get_radio_button, string="Shop Action")
   



    def shop_selection_action(self):
        shop_id = self.test_block_id
        if self.shop_selection == "pending":
            self.env['sale.order'].shop_pending_order(shop_id)
        if self.shop_selection == "ready":
            self.env['sale.order'].shop_order_ready(shop_id)                           
        if self.shop_selection == "cancel":           
            self.env['sale.order'].shop_order_cancel(shop_id)

return


0
Avatar
Ignorer
Avatar
Kaushik Pathak
Meilleure réponse

In context you get both active_model and active_ids. You can use self._context.get('') or self.env.context.get('') to get appropriate values.

For example,

self.env['active_model'].search('id', 'in', self._context.get('active_ids'))

0
Avatar
Ignorer
Anil Issac
Auteur

shop_selection = fields.Selection(_get_radio_button, string="Shop Action")

I am using _get_radio_button() function to load the radio button values as per conditions.
Context gives correct values other functions.

But when using same context code in the _get_radio_button() to get the currently active id of the sale_order,
it just return empty in Odoo17 for me.

Kaushik Pathak

You have to pass context for sale order id in the action from where you are open a wizard and then you can use this context value in your relative method of wizard.

Anil Issac
Auteur

I tried passing sale order id in context of the action that calls the wizard. But the data not getting inside the _get_radio_button() function.
In other functions like default_get(), I can access the context data.

Kaushik Pathak

Please paste the opening wizard method code here.. If I'm not wrong you're opening that wizard sale order, Right?

Anil Issac
Auteur

I am opening the wizard from the sale order actions. Above code is the wizard code.

when printing action i get below result in log.
context data is getting in the default_get().
Not in the _get_radio_button() function which used to return radio button list as per condition.

{'id': 585,
'name': 'Test Shop',
'type': 'ir.actions.act_window',
'xml_id': 'my_test_shop.action_test_shop_actions_wizard',
'help': False,
'binding_model_id': False,
'binding_type': 'action',
'binding_view_types': 'list,form',
'display_name': 'Test Shop',
'create_uid': (1, 'OdooBot'),
'create_date': datetime.datetime(2024, 1, 9, 7, 32, 32, 966062),
'write_uid': (1, 'OdooBot'),
'write_date': datetime.datetime(2024, 1, 15, 6, 13, 30, 916019),
'view_id': (1549, 'test.shop.wizard.form.view'),
'domain': False,
'context': "{'test_block_id': 1, 'order_id': 1167}",
'res_id': 0,
'res_model': 'test.shop.wizard',
'target': 'new',
'view_mode': 'form',
'mobile_view_mode': 'kanban',
'usage': False,
'view_ids': [],
'views': [(1549, 'form')],
'limit': 80, 'groups_id': [],
'search_view_id': False,
'filter': False}

Kaushik Pathak

sale_ids = fields.many2many()

@api.model
def default_get(self, fields):

res = super(TestOrderShop, self).default_get(fields)

selected_ids = self.env['sale.order']._context.get('active_ids', [])
res['sale_ids'] = [(4, selected_ids)]
_logger.info('\n\n\n\n selected_ids = %s \n\n\n\n' % (selected_ids) )

return res

You can use sale_ids in radio button method.

Anil Issac
Auteur

I tried similar and this method. But seems _get_radio_button() function is calling before the default_get() function.
So in log the variable value showed unknown in _get_radio_button() function.

selected_ids = _unknown()

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
oct. 25
1465
How to add a new Many2one field in res.config.settings? Résolu
v17
Avatar
Avatar
Avatar
Avatar
4
oct. 25
4104
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
sept. 25
2655
How to disable Email notification - You have been assigned to Résolu
v17
Avatar
Avatar
Avatar
Avatar
4
sept. 25
8209
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
août 25
1448
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now