Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Where exactly is the date format filled from for a language?

By
Yenthe
on 1/7/15, 2:24 AM 1,676 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

 

1

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

there is only 10 kind of people the ones that understand binary ... and others

Bole
On 1/7/15, 3:03 AM

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

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.

Yenthe
on 1/7/15, 3:06 AM

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

Yenthe
on 1/7/15, 3:08 AM

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

Bole
on 1/7/15, 3:35 AM

@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?

Yenthe
on 1/7/15, 4:04 AM

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

Bole
on 1/7/15, 4:10 AM

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

Yenthe
on 1/7/15, 4:15 AM

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 : ) ....

Bole
on 1/7/15, 4:22 AM

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

Bole
on 1/7/15, 4:29 AM

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

Bole
on 1/7/15, 4:37 AM

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!

Yenthe
on 1/7/15, 4:43 AM

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

Bole
on 1/7/15, 4:46 AM

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

Yenthe
on 1/7/15, 4:55 AM

(beer) :)

Bole
on 1/7/15, 4:58 AM

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

Bole
on 1/7/15, 11:22 AM
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

Yenthe
on 1/8/15, 2:21 AM

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
on 1/8/15, 3:50 AM
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

Yenthe
on 1/8/15, 3:53 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/7/15, 2:24 AM
Seen: 1676 times
Last updated: 3/16/15, 8:10 AM