Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivoustarvikkeet
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Tutoriaalit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

Set default duration in res_config

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
defaultv7
3 Vastaukset
11629 Näkymät
Avatar
Lucio

I have a module that has, a creation date (of course, the day it was created) and a deadline date.

The thing is that I want to be able to set a default value to this deadline date according to the date it was created. But I want to be able to configurate this dynamically from (lets say) res_config.

e.g.

If I configured the default values in res_config to 5 days, I want the default value for the deadline date to be populated with a date 5 days ahead of the creation date.

Is this possible?

Thank you

1
Avatar
Hylkää
Avatar
Lucio
Tekijä Paras vastaus

I managed to do this using the model ir.configure_parameter.

In res_config.py:

class my_configuration(osv.osv_memory):
    _inherit = ['res.confi.settings']
    _columns = {
       'default_deadline' : fields.integer('Days per default', help="""Help field"""),
    }
    ...
    def set_default_deadline(self, cr, uid, ids, context=None):
        config = self.browse(cr, uid, ids)
        config = config and config[0]
        val = '%s' %(config.default_deadline) or '10'
        self.pool.geet('ir.config_parameter').set_param(cr,uid, 'key_value', val)
        return True

Whit this we have created a system parameter. It is actually created as a mapping from 'key_value' to val that is a string, so we will have to cast it to the desired type when necessary. In my case, y created a function to get the deadline date in my module:

def _get_deadline_date(self, cr, uid, context=None):
    val = self.pool.get('ir.config_parameter').get_param(cr, uid, 'key_value')
    try:
        val = int(val)
    except: 
        # Just in case...
        val = 30
    return (datetime.now() + timedelta(days=val)).strftime('%Y,%m,%d')

_defaults = {
    'deadline_date': lambda s, cr, uid, c: s._get_deadline_date(self, cr, uid,     context=c),
}

Thank you, hope it helps!

1
Avatar
Hylkää
Turkesh Patel (tpa)

you will need to give only default_model='' " in field ..then no req to over write get and set method ..it should work automatically..whre ever u want to set deadline there you have to get this value and set deadline

Lucio
Tekijä

Sorry, but I don't know what you mean with the field 'default_model'. Where is it? Actually, my idea wasn't to over write the get/set method, it is just a function to get the default value for the field (maybe the name picking was not the most accurate!). Thanks!

Avatar
Turkesh Patel (tpa)
Paras vastaus

yes this is possible using resconfig.you can define defaultdeadline field.

0
Avatar
Hylkää
Lucio
Tekijä

I did not find the way to do that using this, because is not like I want a fix date, I want the deadline date to be, for example, 4 days after the creation date.

Can you explain to me if you know how to do this?

Avatar
Mike Telahun
Paras vastaus

To expand on Turky's comment: You don't need to write your own functions to set and get the default value. It is enough that you add the 'default_model' parameter to your column definition:

class my_configuration(osv.osv_memory):
    _inherit = ['res.config.settings']
    _columns = {
       'default_deadline' : fields.integer('Days', default_model='object.name'),
    }

For this to work correctly you will need:

  • a field named 'deadline' in your 'object.name' object
  • the column providing the default value in your res.config.settings class must begin with default_
0
Avatar
Hylkää
Lucio
Tekijä

Good one! I did not know that! Nevertheless, the thing is that I am actually setting a numeric value, representing the numbers of days for default for a the objects of my model, so, the default value for deadline_date must be (x days + cration_date) where x is the integer that you can set in my_configuration.

Mike Telahun

As long as the field type for the default value in res.config and the field type in your object are the same. OpenERP will do the right thing.

Lucio
Tekijä

Yes, that's the thing in my case, they where not! Because I wanted to set a date "on the fly", adding a time delta to the creation date. Setting a date as default will just set in all records the field with the value in res.config. Hope I am not missing something here!

Mike Telahun

I'm not sure if I understand correctly, but here goes: In your main object you should have three fields: begin_date, deadline_date and deadline_delta. The begine_date and deadline_date fields are date fields and deadline_delta would be an integer field. Then in res.config you would have a field called default_deadline_delta, which is an integer. Then in your main object you would have an onchange method on the begin_date field, which when triggered would change the value of deadline_date by adding deadline_delta to begin_date. I hope I have correctly understood what you want to do.

Lucio
Tekijä

Yes, the answer you are giving me fit my requirements perfectly! The thing is that, by doing so, I would create a field in the database for every record of my model, that is to be filled on creation time and never to be modified again. (If you want to change the deadline_date you should change it directly not changing the deadline_delta). Thanks for your concern! :D

Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
How to send a default model_id in a view? (old api)
default v7
Avatar
0
huhtik. 15
4765
Add an item passing relation as default?
default create v7
Avatar
0
maalisk. 15
4180
Default values for Users Ratkaistu
default v7 location
Avatar
Avatar
1
helmik. 24
14495
How to set default time for date_stop in calendar view?
calendar default v7
Avatar
Avatar
1
maalisk. 15
9677
How to calculate new function field on module update? Ratkaistu
default v7 update
Avatar
Avatar
1
maalisk. 15
8485
Yhteisö
  • Tutoriaalit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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