Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

Active ids not getting in wizard selection field function in Odoo17

Naroči se

Get notified when there's activity on this post

This question has been flagged
v17
1 Odgovori
3412 Prikazi
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
Opusti
Avatar
Kaushik Pathak
Best Answer

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
Opusti
Anil Issac
Avtor

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
Avtor

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
Avtor

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
Avtor

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()

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
okt. 25
1468
How to add a new Many2one field in res.config.settings? Solved
v17
Avatar
Avatar
Avatar
Avatar
4
okt. 25
4110
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
sep. 25
2659
How to disable Email notification - You have been assigned to Solved
v17
Avatar
Avatar
Avatar
Avatar
4
sep. 25
8218
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
avg. 25
1450
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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