Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

Storing function field upon creation of resource in dependent model

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
transaction
2 Antwoorden
5524 Weergaven
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
Annuleer
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
Auteur

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
Beste antwoord

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
Annuleer
Avatar
Andreas Brueckl
Beste antwoord

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
Annuleer
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
how to change summernote toolbar language (web_editor)
transaction
Avatar
0
aug. 22
3281
Managing transactions between countries (Multi-currency)
transaction
Avatar
0
mrt. 15
4095
Inter company transfer
transaction intercompany
Avatar
Avatar
1
aug. 20
9176
How to remove all the transactions? Opgelost
warehouses transaction
Avatar
Avatar
Avatar
2
nov. 19
18139
accessing one record with two counters at once
transaction counter
Avatar
0
aug. 16
4327
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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