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

what is the difference between default_get method and default parameter in fields ?

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
defaultactionsdefaultscontextdefault_get
4 Antwoorden
20585 Weergaven
Avatar
Mohamed Fouad (personal)

what is the major difference between inherit default_get method  with super and using default parameter in the required field, 

also I'm using default_get in in res. partner and it's not working if there is a condition before values 
here is it 

@api.model
def default_get(self, fields_list):
res = super(ataa_partner, self).default_get(fields_list)
asha = self.env.ref('mf_ataa.income_asha').id
kesaa = self.env.ref('mf_ataa.income_kesaa').id
water = self.env.ref('mf_ataa.income_water').id
if self.is_mostafeed:
vals = [(0, 0, {'outcome_amount': 900, 'type': asha}),
(0, 0, {'outcome_amount': 150, 'type': kesaa}),
(0, 0, {'outcome_amount': 140, 'type': water})]
res.update({'outcomes': vals})

the method its not working if I set the condition on it otherwise the field is_mostafeed is already true with the context in action 


0
Avatar
Annuleer
Avatar
Axel Mendoza
Beste antwoord

The default_get method is the way Odoo collect the default values for all the fields when creating a new record to be able to edit for example in a Form view. That method will collect the default values from field definitions, per company related values and ir.defaults records to build the dict of values that you could extend by providing your own version of the default_get method and obtaining that dict of values when calling to super.

But the important thing here is that the default_get method wouldn't being calling on a recordset or a record so your condition `if self.is_mostafeed:` will always be False because self is not a recordset and also don't have a proper value for it's fields.

You could get the default value of the field is_mostafeed from the res dict returned by the super call and make your condition against that value to make it work or also put a value in the action context and check against that value using self.env.context.get('is_mostafeed', False) to make it work

*** Solution examples ***

1- Using res dict returned from super call

@api.model
def default_get(self, fields_list):
res = super(ataa_partner, self).default_get(fields_list)
asha = self.env.ref('mf_ataa.income_asha').id
kesaa = self.env.ref('mf_ataa.income_kesaa').id
water = self.env.ref('mf_ataa.income_water').id
if res.get('is_mostafeed', False):
vals = [(0, 0, {'outcome_amount': 900, 'type': asha}),
(0, 0, {'outcome_amount': 150, 'type': kesaa}),
(0, 0, {'outcome_amount': 140, 'type': water})]
res.update({'outcomes': vals})

2- Using context

@api.model
def default_get(self, fields_list):
res = super(ataa_partner, self).default_get(fields_list)
asha = self.env.ref('mf_ataa.income_asha').id
kesaa = self.env.ref('mf_ataa.income_kesaa').id
water = self.env.ref('mf_ataa.income_water').id
if self.env.context.get('default_is_mostafeed', False):
vals = [(0, 0, {'outcome_amount': 900, 'type': asha}),
(0, 0, {'outcome_amount': 150, 'type': kesaa}),
(0, 0, {'outcome_amount': 140, 'type': water})]
res.update({'outcomes': vals})
1
Avatar
Annuleer
Mohamed Fouad (personal)
Auteur

how my method can be done, i can't understand exactly your explanation

Axel Mendoza

I can't say how your method could be done because I don't have a definition about the field is_mostafeed and how you expect that the value of that field get True to apply your condition. Provide me with that info so I could give you an example

Mohamed Fouad (personal)
Auteur

it's just a boolean field

is_mostafeed = fields.Boolean(string="مستفيد",)

and i set it as true with action conext

<field name="context">{'default_customer':1,'search_default_is_motafeed':1, 'default_is_mostafeed': True}</field>

Axel Mendoza

I have updated my answer with 2 solution examples based on your last comment

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 set defaults dynamically, depending on last record?
default defaults context
Avatar
Avatar
1
mrt. 15
5616
[v9] How to hava a default depending on another field?
default defaults
Avatar
0
apr. 16
3957
Default value of a field depending on a field of parent model
defaults default_get
Avatar
0
jul. 15
4655
Proper syntax for passing the active id to a server action
create actions context
Avatar
0
mrt. 18
5225
How to come out of Developer mode in openerp 7.0 ?
development default defaults
Avatar
Avatar
Avatar
2
mrt. 15
5302
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