This question has been flagged
1 Reply
6985 Views

Hi guys

I've been looking at languages and the date formats / time formats.
If I look in the code I can see the language being fetched from the settings of your Ubuntu machine from the file misc.py under /openerp/tools/misc.py
I've modified the locales file for en_US under /usr/share/i18n/locales/en_US and the same for nl_NL like this:

en_US:
% Appropriate date representation (%x)
%       "%d/%m/%Y"
d_fmt   "<U0025><U0064><U002F><U0025><U006D><U002F><U0025><U0059>"

nl_NL:
d_fmt   "<U0025><U0064><U002D><U0025><U006D><U002D><U0025><U0079>"

Yet my date format when creating a new Odoo db is still wrong. I will get %m/%d/%Y for en_US and %d-%m-%Y for nl_NL..


Can anybody tell me where exactly I should set the date format for a specific format? I've been trying some things for hours but nothing succeeds.
NOTE: I'm not talking about modifying the date format manually under settings > Languages but I'm talking about setting the dateformat without accessing the languages menu, so by code.

With kind regards
Yenthe

 

Avatar
Discard
Best Answer

Settings -> Languages

number, date, time and simmilar formats are defined there.. 
hope it helps : )
 

to do it by code... define some base module and put yml file in (and in __openerp__.py just like any test yml)
( modify yml to your needs) :

-
  I force the installation of Croatian language
-
  !python {model: base.language.install}: |
    lang_ids = self.pool.get('res.lang').search(cr, uid, [('code', '=', 'hr_HR')], limit=1, context=context)
    if not lang_ids:
      wizard_id = self.create(cr, uid, {'lang': 'hr_HR'}, context)
      self.lang_install(cr, uid, [wizard_id], context)
-
  I make Croatian as default language if installed
-
  !python {model: res.lang}: |
    if self.search(cr, uid, [('code', '=', 'hr_HR')], limit=1):
      value_obj = self.pool.get('ir.values')
      ids = value_obj.search(cr, uid, [
        ('name', '=', 'lang'),
        ('key', '=', 'default'),
        ('model', '=', 'res.partner'),
      ], limit=1, context=context)
      vals = {
        'name': 'lang',
        'key': 'default',
        'key2': False,
        'model': 'res.partner',
        'object': False,
        'value_unpickle': 'hr_HR',
      }
      if ids:
        value_obj.write(cr, uid, ids, vals, context)
      else:
        value_obj.create(cr, uid, vals, context)
-
  I correct all formats for Croatian language
-
  !python {model: res.lang}: |
    lang_ids = self.search(cr, uid, [('code', '=', 'hr_HR')], limit=1)
    if lang_ids:
      self.write(cr, uid, lang_ids, {
        'grouping': '[3,0]',
        'decimal_point': ',',
        'thousands_sep': '.',
        'name': 'Croatian / Hrvatski',
        'date_format': '%d.%m.%Y',
        'time_format': '%H:%M:%S',
      }, context)

 

 hope this helps ;)

Avatar
Discard
Author

Hi Bole that is exactly what I want to surpass. I want this date format to be filled in correctly automaticly. Every language installed should by default have the date format d%/m%/Y%, or atleast for the Dutch / Nederlands language.

Author

I've added a note for this in my post as this might have not been clear enough, sorry about that.

here , adited my previous answer according to your needs ;) hope this helps

Author

@Bole alright this looks very interesting! What is the best (already existing) module to place this extra file in? And I can only add in the last part from !python {model: res.lang}: | right?

you can put it in any module that you install on database... i ususaly put it in custom account_template module (because i rarely use standard localization modules l10n_xx) or any other module... and yes, you can modifiy yml file to your needs, the firt part is just to make 100% sure i have desired lang installed before i make any modifications

Author

Okay I get the concept but not 100% how to do it. So I can create a new module with scaffold and then simply add one file (languages.yml for example) in the folder, add it to the __openerp__.py file and done? How would this ever be triggered on installation of a language for example then? :s

yml files are usefull, just grep/search for yml files in standard addons and look for examples... it can execute tests, but also it can execute python code during instalation of module... it is not trigered on instalation of languge... that comes later... but what you can do is use standard english lang for basic instalation, and then trigger instalation of desired languages troug module ( copy paste entire code) and do it for avery language you want installed and set acording to your needs : ) ....

additional note: I use this on v7, haven't test it on v8, also.. can't actualy debug yml file.... it is only interpreter for some actions... so you need to get the concept and try until it works as wanted ;)

note2: to find out other yml options check: openerp.tools.yaml_tag.py & openerp.tools.yaml_import.py

Author

I've added your dateformat block under the module l10n_be in the already existing file account_chart_template.yml but I get errors.. raise YamlImportException("Can not process YAML block: %s" % node) Any ideas Bole? Would you want to share this custom module of you by the way? This concept is very interesting!

yml idea fo4r languages is copied from here: https://github.com/apollet/smile_openerp_addons_7.0/tree/master/smile_base chek that module...

Author

Awesome! This is simply amazing. Strange that it isn't documented anywhere. Thanks Bole, accepted & upvoted.

(beer) :)

Huh... just found another interesting usage for yml files.... in v8.. check stock module... stock_data.yml ....

Hmmm interesting! Those yml have quite some options so it seems and nobody uses them.
By the way, your idea of just writing on the id and setting to true is working perfect. (from Linkedin)

Thanks
Yenthe

2015-01-07 17:22 GMT+01:00 Bole <bole-dajmi5-com@mail.odoo.com>:

Huh... just found another interesting usage for yml files.... in v8.. check stock module... stock_data.yml ....

--
Bole
Sent by Odoo S.A. using Odoo about Forum Post False

well.. in v7 i noticed yml files beeing used mostly for tests.. in v8 the more i look the more usage i notice... it is indeed very usefull tool, because you can execute some py methods during instalation of modules, meaning you can decide what to install , what data to import based on current database setup... i see this as wery fleksible tool..

Hey Bole

Yeah indeed it is a very flexible and handy way to add/modify some stuff.
I'm already using it to install languages, change formats, change automated actions etc..

Thank you for pointing this out to me, this is a gem to automate stuff.

With kind regards
Yenthe

2015-01-08 9:50 GMT+01:00 Bole <bole-dajmi5-com@mail.odoo.com>:

well.. in v7 i noticed yml files beeing used mostly for tests.. in v8 the more i look the more usage i notice... it is indeed very usefull tool, because you can execute some py methods during instalation of modules, meaning you can decide what to install , what data to import based on current database setup... i see this as wery fleksible tool..

--
Bole
Sent by Odoo S.A. using Odoo about Forum Post False