Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Wizard and context values in OpenERP 7

Subscribe

Get notified when there's activity on this post

This question has been flagged
wizardv7context
3 Replies
21387 Views
Avatar
Francesco OpenCode

When I read the context in the functions of a wizard, I found that active_id is the wizard id. In the old openerp version, this parameter was the form id when i call wizard! It'a a bug or a feature? There is a system to read the calling form id?

1
Avatar
Discard
Avatar
Francesco OpenCode
Author Best Answer

I found my problem!!! I created a multi-step wizard. After the first step, I forgot to pass context to new step. Therefore, the context was replaced by a standard context where active_id was wizard id. Now I've replaced my old code with this:

return {
 'type': 'ir.actions.act_window',
 'name': "Inserisci Ispezioni Settimanali",
 'res_model': 'gmc.inserisci_ispezioni_settimanali',
 'res_id': ids[0],
 'view_type': 'form',
 'view_mode': 'form',
 'view_id': view_id,
 'target': 'new',
 'nodestroy': True,
 'context' : context,
 }

and now work fine.

3
Avatar
Discard
Lucio

But...with this you are getting the id of the wizard, not the form id of the caller. I think I am understanding the answer incorrectly.

arsalan

Hi I am also having problem in calling form through my button . Plz help

Avatar
Lucio
Best Answer

I can not say if this is a bug or a feature actually, but to solve this I had to override the default_get function of the wizard.

E.g. Lets assume we want to set a field something of the caller.model object calling a wizard. In field called caller_id we will put the caller's id, not showing it in any view. Now let us assume that the function action_of_wizard is the one that does 'the magic' and is called when pressing a button.

Then in wizard .py:

_columns = {    
    ...
    something: fields.char("Data to write in the caller's field", required=True),
    caller_id: fields.integer('Caller ID', readonly=True),
    ...
}

def default_get(self, cr, uid, fields, context=None):
    ret = super(wizard_model_name,self).default_get(cr, uid, fields, context=context)
    caller_id = context.get('active_id',False)
    if caller_id:
        ret['caller_id'] = caller_id
    return ret

def action_of_wizard(self, cr, uid, ids, context=None):
    ...
    caller_pool = self.pool.get('caller.model')
    for wiz in self.browse(cr,uid,ids,contex=context):
        caller_pool.write(cr, uid, wiz.caller_id, {'caller_field': wiz.something})
        ...
    return {'type': 'ir.actions.act_window_close'}

There are some possible improvements to make to the code, of course, but I hope I made myself clear from the above example!

Hope this answer suits your enquiry!

5
Avatar
Discard
Francesco OpenCode
Author

This is not a solution for me because I need form id to write some datas in the record and not to set wizard field.

Lucio

I updated my answer to do what (I think is what) you want.

Mohammad Alhashash

I think you mean default_get(), not get_default()

Lucio

My bad! :P Sorry

Francesco OpenCode
Author

No guys. This is not my case. I need to write wizard datas in form fields. But i haven't the form id in wizard context.

Lucio

Exactly, you wont have it in the context once the wizard is loaded, but before (when calling default_get) you can access the ID of the form as stated in the answer, save it an integer field of the wizard and use it again when you need it. I can not see why this is not working, it does in my case at least.

Mohammad Alhashash

You do not need to override default_get() to set a field value. Just add default_FieldName to the context attribute.

Lucio

Yes, this is true, you can do it like this. It did not occur to me but this is probably simpler if the only thing you want to do is access the id of the caller. I did that way but because in my case I was doing other calculations as well. Thanks for pointing this

Avatar
Mohammad Alhashash
Best Answer

If you are using a button to open the wizard, you can control the default values of the wizard fields using context variables in the format default_FieldName.

So, If the wizard has a field called target_id; In your model, you should start the wizard using a method button like this:

def action_start_wizard(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    context.update({
        'default_target_id': len(ids) and ids[0] or False
    })
    return {
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'mymodule.mywizard',
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,
        'nodestroy': True,
    }

Then, use the target_id field in your methods instead of context['active_id']. Of course you should make target_id field invisible in the wizard view.

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

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

Sign up
Related Posts Replies Views Activity
field value in context
wizard fields v7 context
Avatar
0
Mar 15
4533
Force wizard dimension Solved
wizard v7
Avatar
1
Apr 24
9291
active_domain not found in context when using wizard
wizard context
Avatar
0
Aug 17
4078
Form not updating on button action
wizard v7
Avatar
Avatar
1
Mar 15
6735
Fetch values from dynamic view of a wizard
wizard v7
Avatar
Avatar
Avatar
2
Mar 15
5677
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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