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

Odoo14 Action Server Error - Unable to call fields of current model in context correctly

Tilmeld

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

Dette spørgsmål er blevet anmeldt
xmlwindow_actionserver_actionsv14
1 Svar
2895 Visninger
Avatar
Kahina

I am facing an issue while trying to define an action server in Odoo14. The objective is to call a Python method that returns a window action because I need to access fields in the current model and pass them to the context. Unfortunately, directly using a window action with a context that calls fields doesn't seem to be working as expected. Below is the code snippet I am using:


XML Code: 

<odoo>

<record id="action_add_supplier_payment_bank_statement_line_new" model="ir.actions.server">

    <field name="name">Créer un paiement</field>

    <field name="model_id" ref="account.model_account_bank_statement_line"/>

    <field name="binding_model_id" ref="account.model_account_bank_statement_line"/>

    <field name="state">code</field>

    <field name="binding_view_types">list</field>

    <field name="code">action = model.action_payment_bank_statement_line()</field>

</record>

</odoo>



Python Method:

def action_payment_bank_statement_line(self):
        action_ref = 'account.view_account_payment_form'
        print(action_ref)
        action = self.env['ir.actions.act_window']._for_xml_id(action_ref)
        action['context'] = {
            'default_payment_type': 'outbound',
            'default_partner_type': 'customer',
            'default_ref': self.payment_ref,
            'default_amount': self.amount,
            'default_date': datetime.strptime(self.date, '%Y-%m-%d')
        }
        action['view_mode'] = 'form'
        action['target'] = 'new'
        return action

However, I'm encountering the following error when I click on action button:

result = request.dispatch()
  File "/opt/odoo14/odoo/odoo/http.py", line 696, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo14/odoo/odoo/http.py", line 370, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo14/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo14/odoo/odoo/http.py", line 358, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo14/odoo/odoo/http.py", line 919, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo14/odoo/odoo/http.py", line 544, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo14/odoo/addons/web/controllers/main.py", line 1728, in run
    result = action.run()
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_actions.py", line 632, in run
    res = runner(run_self, eval_context=eval_context)
  File "/opt/odoo14/odoo/addons/website/models/ir_actions.py", line 61, in _run_action_code_multi
    res = super(ServerAction, self)._run_action_code_multi(eval_context)
  File "/opt/odoo14/odoo/odoo/addons/base/models/ir_actions.py", line 501, in _run_action_code_multi
    safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True)  # nocopy allows to return 'action'
  File "/opt/odoo14/odoo/odoo/tools/safe_eval.py", line 347, in safe_eval
    raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/odoo14/odoo/odoo/http.py", line 652, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo14/odoo/odoo/http.py", line 317, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ValueError: : "" while evaluating
'action = record.action_payment_bank_statement_line()'


I would appreciate any assistance in identifying and correcting the issue in the code, or any alternative suggestions for defining the action server correctly.

0
Avatar
Kassér
Avatar
Kahina
Forfatter Bedste svar

The issue was with how the action values were returned into python method. Here is the updated code: 
 


def action_payment_bank_statement_line(self):
        view_id = self.env.ref('account.view_account_payment_form').id
        ctx = {
                      'default_payment_type': 'inbound',
                      'default_partner_type': 'customer',
                      'default_ref': self.payment_ref,
                      'default_amount': self.amount,
                      'default_date': datetime.strptime(str(self.date), '%Y-%m-%d').date()
              }
        return {'type': 'ir.actions.act_window',
                'res_model': 'account.payment',
                'target': 'new',
                'view_mode': 'form',
                'views': [[view_id, 'form']],
                'context': ctx
        }


        

 


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
Odoo14 Action Server Error - Unable to Call Python Method Correctly
window_action server_actions v14
Avatar
0
jan. 24
95
Add button at header in tree view using xpath Løst
xml v14
Avatar
Avatar
1
sep. 24
3184
XML showing both result of t-if and t-else
xml v14
Avatar
Avatar
1
maj 23
3821
how to access key value from nested dictionary in xml qweb report odoo14?
xml v14
Avatar
Avatar
1
sep. 21
6370
Which addons have examples of python server actions (preferably stored in XML data files)?
xml server_actions
Avatar
Avatar
1
mar. 15
9017
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