Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Služby pro partnery
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Storing function field upon creation of resource in dependent model

Odebírat

Get notified when there's activity on this post

This question has been flagged
transaction
2 Odpovědi
5525 Zobrazení
Avatar
Richard Lewis

I have a function field which is defined like this:

def _get_field_value(self, cr, uid, ids, field_name, args, context=None):
    return ...

def _get_related_others(self, cr, uid, other_ids, context=None):
    return self.pool.get('this.model').search(cr, uid,
                         [('other_id','in',other_ids)], context=None)

'field': fields.function(_get_field_value, ...,
    store={'other.model': (_get_related_others, ['other_field'], 10)}),

The idea is that when the user creates a new resource in the other.model an update of 'field' is triggered. The update is triggered without any problems, but the _get_related_others can't retrieve the given other_ids from other.model. It gets passed a list containing one id (of a new other.model resource), but self.pool.get('other.model').search() returns no IDs.

I can see that the newly created other.model resource is not in the database at the time that _get_related_others is called, but isn't this just because it's in a transaction that's yet to be committed? And shouldn't the self.pool.get('other.model').search() call be working with the same transaction? And therefore have access to he newly created other.model resource?

Otherwise, please explain how/whether this is possible.

EDIT

Apologies, I abstracted my actual problem incorrectly. I'm aware that the aim is to return a list of IDs on this.model that need to be updated, but the problem is that I want to select resources from this.model which are related to the resource(s) on other.model that changed.

this.model has a field, 'other_id', that points to other.model. In my _get_related_others method I intend to select all the this.model resources where other_id is in the list of other_ids that changed. However, I find that:

self.search(cr, uid, [('other_id','in',other_ids)], context=None)

is wrong because self is actually a other.model object (I expected it to be this.model). And

self.pool.get('this.model').search(cr, uid, [('other_id','in',other_ids)], context=None)

(as I've edited to above to now read) doesn't work as it returns an empty list. It should be returning resources on this.model whose other_id field points to the newly created resource on other.model.

I hope that's a bit clearer?

0
Avatar
Zrušit
Lucio

I am not sure what do you want to do, are you trying to look for the newly created id? Isn't that the id in other_ids?

Lucio

But if you just created the other.model, how is it that any of the this.model is related with it? If, on creation, you set the relation through other.model in, lets say, field first_model, you can access to it whit something like self.browse(cr,ids[0],context).first_model

Richard Lewis
Autor

Now, I have to apologise again. I've worked more on this today and found that the problem was very specifically to do with the actual models I was working with, and that my abstract version here would actually work fine. So I guess this question is either 'answered' or, better, 'asked in error'; not sure if there's a state for that.

Avatar
filsystem
Nejlepší odpověď

You have to return the id(s) of current model from _get_related_others, not id(s) from other.model. Try something like that:

def _get_related_others(self, cr, uid, other_ids, context=None):
    result = set()
    for om in self.pool.get('other.model').browse(cr, uid, other_ids):
        result.add(om.id)
    return list(result)
1
Avatar
Zrušit
Avatar
Andreas Brueckl
Nejlepší odpověď

In the function _get_related_others the variable other_ids contains the Ids of the model other.model.

The job of this function is to return Ids of the current model (do not know how the model is called in your example).

But returning Ids of the model other.model is not correct!

I know that this is confusing, but once you got it it will be more clear :-)

1
Avatar
Zrušit
Enjoying the discussion? Don't just read, join in!

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
how to change summernote toolbar language (web_editor)
transaction
Avatar
0
srp 22
3281
Managing transactions between countries (Multi-currency)
transaction
Avatar
0
bře 15
4095
Inter company transfer
transaction intercompany
Avatar
Avatar
1
srp 20
9176
How to remove all the transactions? Vyřešeno
warehouses transaction
Avatar
Avatar
Avatar
2
lis 19
18139
accessing one record with two counters at once
transaction counter
Avatar
0
srp 16
4327
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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