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

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

Tilmeld

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

Dette spørgsmål er blevet anmeldt
defaultactionsdefaultscontextdefault_get
4 Besvarelser
20584 Visninger
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
Kassér
Avatar
Axel Mendoza
Bedste svar

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
Kassér
Mohamed Fouad (personal)
Forfatter

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)
Forfatter

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

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
How to set defaults dynamically, depending on last record?
default defaults context
Avatar
Avatar
1
mar. 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
4652
Proper syntax for passing the active id to a server action
create actions context
Avatar
0
mar. 18
5225
How to come out of Developer mode in openerp 7.0 ?
development default defaults
Avatar
Avatar
Avatar
2
mar. 15
5302
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