Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Using both ref and active_id at once in record field?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
refrencecontextactive_ideval
1 Atsakyti
9072 Rodiniai
Portretas
Lekhnath Rijal

In `xml` I want to use both `active_id` and `ref` as `context` field's value at once while defining `record` for model `ir.actions.act_window`. But I am able to use only one as shown in below code snippets:

Method 1. Using only `ref` with `eval`:
```xml
<record id="some_identifier" model="ir.actions.act_window">
<field name="name">Name</field>
...
<field name="context" eval="{'some_key': ref('module_name.ext_id')}" />
</record>
```

Method 2. Using only `active_id`:
```xml
<record id="some_identifier" model="ir.actions.act_window">
<field name="name">Name</field>
...
<field name="context">{'search_default_employee_id': active_id}</field>
</record>
```

When I try using `active_id` in *Method 1.* or include `ref` in *Method 2.* above I get an error message saying **`active_id` is not defined** in first case and **`ref` is not defined** in second case.

What I would like to achieve is to be able to use both `ref` method and `active_id` variable at once. Something like below:

```xml
<record id="some_identifier" model="ir.actions.act_window">
<field name="name">Name</field>
...xml
<field name="context" eval="{'some_key': ref('module_name.ext_id'), 'search_default_employee_id': active_id}" /> <!-- NOTE: Raises an exception -->
</record>
```

```xml
<record id="some_identifier" model="ir.actions.act_window">
<field name="name">Name</field>
...
<field name="context">{'some_key': ref('module_name.ext_id'), 'search_default_employee_id': active_id}</field> <!-- NOTE: Raises an exception -->
</record>
```

0
Portretas
Atmesti
Lekhnath Rijal
Autorius

I solved this myself. See my answer below or at Stackoverflow => https://stackoverflow.com/q/59545188/2071612

Ravi Gadhia

that's great. but what was the traceback and why eval could not work for both at the same time?

Portretas
Lekhnath Rijal
Autorius Best Answer

Starting from v12 Odoo supports calling model method for evaluating field value. We can utilize this technique to use both `ref` method and `active_id` variable at once in `context` field's value in following way.

Define a method as follow in any `model` you want.

```python
from odoo import models, api
from odoo.tools.misc import unquote

class SomeClass(models.Model):
_inherit = 'some_module.model.name'

@api.model
def _using_both_ref_and_active_id(self):
ref = self.env.ref
active_id = unquote("active_id")

return {
'using_ref': ref('external.identifier').id,
'search_default_whatever_filter_name': [active_id],
'default_whatever_field_name': active_id
}
```

And then in `xml` access this `method` as follows:

```xml
<record id="action_view_som_id" model="ir.actions.act_window">
<field name="name">Files</field>
...
<field name="context" model="some_module.model.name" eval="obj()._using_both_ref_and_active_id()" />
</record>
```

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

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

Registracija
Related Posts Replies Rodiniai Veikla
How to pass active id to a popup Solved
context 7.0 active_id
Portretas
Portretas
2
kov. 15
15551
Not getting selected records from active_ids, returns empty list
pdf context active_id env
Portretas
0
rugs. 23
2000
How to get Active_id after url action
action context url active_id Actions
Portretas
Portretas
1
bal. 24
2590
how to pass context from XML to JavaScript?
javascript xml context active_id pass
Portretas
Portretas
Portretas
2
gruod. 23
13598
How to pass a context value to a filter Solved
project filter domain context active_id
Portretas
Portretas
2
liep. 19
10815
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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