Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

populate wizard form dynamically

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
wizard
6 Besvarelser
22274 Visninger
Avatar
Drew

I'm relatively new to OpenERP development but I think I can gain much understanding if I could get a rough example of how to do the following (in OpenERP version 7):

I created a wizard. In a view I have a button to open the wizard form:

This opens up correctly the window (dialog) and I can call methods to do stuff from buttons within this wizard form defined in the wizard object.

I want to be able to populate the form view dynamically using records from another model (and then do other stuff upon saving form).

For example in "purchase orders" and for a specific purchase order, I want to get all the products linked to this purchase order (that would be displayed in the tree view).

If I have the button (to launch window/dialog form) placed within the view of the purchase order, the main thing I would like to be able to do is populate the form for the given purchase order with the products for this purchase order.

My question is how do I instantiate the wizard form with the id of the current purchase order, then access the product items for this purchase order.

I've looked into other examples but with older version of OpenERP.

Any help/pointers is appreciated!

1
Avatar
Kassér
Avatar
Brett Lehrer
Bedste svar

The ID of the record you're coming from is in the context, context['active_id']. You'll also have context['active_ids'], which is a list of the IDs you came from, which is used if you're coming from a list where more than one record is checked.

To load those in automatically, add a field for that ID (or those IDs) and set a default value in the wizard to a function that reads context for the active_id or active_ids. Something like:

def _get_active_id(self, cr, uid, ids, context=None):
    if context is None: context = {}
    return context.get('active_id', False)

_columns = {
    'purchase_id': fields.many2one('purchase.order', 'Purchase Order'),
}

_defaults = {
    'purchase_id': _get_active_id,
}

def onchange_purchase(self, cr, uid, ids, purchase_id, context=None):
    if context is None: context = {}
    res = {}
    if purchase_id:
        # Do extra stuff here now that you have the ID loaded
        # res['field_name'] = important_value
    return {'value': res}

An alternative method you might want to use instead is to create the wizard record FIRST, and then load the popup with all of the values in place (there are some technical reasons why that's nice but I'll let you find out why). Your button from the original form would be an object type rather than an action type, and the function it calls would be something like this:

def open_wizard(self, cr, uid, ids, context=None):
    if context is None: context = {}
    # generic error checking
    if not ids: return False
    if not isinstance(ids, list): ids = [ids]

    wizard_id = self.pool['my.wizard'].create(cr, uid, vals={'purchase_id':ids[0]}, context)
    return {
        'name': 'Purchase Wizard',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'my.wizard',
        'res_id': wizard_id,
        'type': 'ir.actions.act_window',
        'target': 'new',
        'context': context,
    }
2
Avatar
Kassér
Drew
Forfatter

great, thank you. I will get back on my results.

Slim BHIRI

This solutions don't work for me.

Salim Rahal

it works in my context. Odoo8. Opening a wizard with default values - customer payment.

Avatar
Salim Rahal
Bedste svar

This solution works in my context: Custome rpayment, add a button that opens a wizard. This wizard have default values set in place when you have instantiate the wizrd.

0
Avatar
Kassér
Avatar
Omar Torres
Bedste svar

Maybe this solution can help you, work for odoo 11 ...


XML file:

<record id="purchase_wizard_server_action" model="ir.actions.server">
    <field name="name">Purchase Wizard</field>
    <field name="type">ir.actions.server</field>
    <field name="model_id" ref="model_purchase_wizard"/>
    <field name="state">code</field>
    <field name="code">action = env['purchase.wizard'].create_wizard()</field> 
</record>
<menuitem id="purchase_wizard_menu" name="Purchase Wizard" action="purchase_wizard_server_action"/>


Model file:

from odoo import fields, models, api 
class PurchaseWizard(models.TransientModel):
    _name = 'purchase.wizard'
    @api.multi
    def create_wizard(self):

        wizard_id = self.create({})

        # YOUR POPULATION CODE HERE

        return {
            'name': 'Purchase Wizard',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'purchase.wizard',
            'res_id': wizard_id.id,
            'type': 'ir.actions.act_window',
            'target': 'new',
            'context': self.env.context
        }


0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Load currnet record values when calling wizard Løst
wizard
Avatar
Avatar
1
dec. 22
4193
What is wizard ? Løst
wizard
Avatar
Avatar
Avatar
3
nov. 23
34179
Close wizard in onchange
wizard
Avatar
Avatar
4
jul. 25
5559
IntegrityError: null value in column "res_model" violates not-null constraint Løst
wizard
Avatar
Avatar
2
dec. 23
18508
How To call wizard from python in odoo10 Løst
wizard
Avatar
Avatar
5
dec. 23
18987
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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