[IMP]project_timesheet:added method for setting default type of invoicing
[odoo/odoo.git] / addons / base_setup / base_setup.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import simplejson
23 import cgi
24 import pooler
25 import tools
26 from osv import fields, osv
27 from tools.translate import _
28 from lxml import etree
29
30 # Specify Your Terminology will move to 'partner' module
31 class specify_partner_terminology(osv.osv_memory):
32     _name = 'base.setup.terminology'
33     _inherit = 'res.config'
34     _columns = {
35         'partner': fields.selection([
36             ('Customer','Customer'),
37             ('Client','Client'),
38             ('Member','Member'),
39             ('Patient','Patient'),
40             ('Partner','Partner'),
41             ('Donor','Donor'),
42             ('Guest','Guest'),
43             ('Tenant','Tenant')
44         ], 'How do you call a Customer', required=True ),
45     }
46     _defaults={
47         'partner' :'Customer',
48     }
49
50     def make_translations(self, cr, uid, ids, name, type, src, value, res_id=0, context=None):
51         trans_obj = self.pool.get('ir.translation')
52         user_obj = self.pool.get('res.users')
53         context_lang = user_obj.browse(cr, uid, uid, context=context).lang
54         existing_trans_ids = trans_obj.search(cr, uid, [('name','=',name), ('lang','=',context_lang), ('type','=',type), ('src','=',src), ('res_id','=',res_id)])
55         if existing_trans_ids:
56             trans_obj.write(cr, uid, existing_trans_ids, {'value': value}, context=context)
57         else:
58             create_id = trans_obj.create(cr, uid, {'name': name,'lang': context_lang, 'type': type, 'src': src, 'value': value , 'res_id': res_id}, context=context)
59         return {}
60
61     def execute(self, cr, uid, ids, context=None):
62         def _case_insensitive_replace(ref_string, src, value):
63             import re
64             pattern = re.compile(src, re.IGNORECASE)
65             return pattern.sub(_(value), _(ref_string))
66         trans_obj = self.pool.get('ir.translation')
67         fields_obj = self.pool.get('ir.model.fields')
68         menu_obj = self.pool.get('ir.ui.menu')
69         act_window_obj = self.pool.get('ir.actions.act_window')
70         for o in self.browse(cr, uid, ids, context=context):
71             #translate label of field
72             field_ids = fields_obj.search(cr, uid, [('field_description','ilike','Customer')])
73             for f_id in fields_obj.browse(cr ,uid, field_ids, context=context):
74                 field_ref = f_id.model_id.model + ',' + f_id.name
75                 self.make_translations(cr, uid, ids, field_ref, 'field', f_id.field_description, _case_insensitive_replace(f_id.field_description,'Customer',o.partner), context=context)
76             #translate help tooltip of field
77             for obj in self.pool.models.values():
78                 for field_name, field_rec in obj._columns.items():
79                     if field_rec.help.lower().count('customer'):
80                         field_ref = obj._name + ',' + field_name
81                         self.make_translations(cr, uid, ids, field_ref, 'help', field_rec.help, _case_insensitive_replace(field_rec.help,'Customer',o.partner), context=context)
82             #translate menuitems
83             menu_ids = menu_obj.search(cr,uid, [('name','ilike','Customer')])
84             for m_id in menu_obj.browse(cr, uid, menu_ids, context=context):
85                 menu_name = m_id.name
86                 menu_ref = 'ir.ui.menu' + ',' + 'name'
87                 self.make_translations(cr, uid, ids, menu_ref, 'model', menu_name, _case_insensitive_replace(menu_name,'Customer',o.partner), res_id=m_id.id, context=context)
88             #translate act window name
89             act_window_ids = act_window_obj.search(cr, uid, [('name','ilike','Customer')])
90             for act_id in act_window_obj.browse(cr ,uid, act_window_ids, context=context):
91                 act_ref = 'ir.actions.act_window' + ',' + 'name'
92                 self.make_translations(cr, uid, ids, act_ref, 'model', act_id.name, _case_insensitive_replace(act_id.name,'Customer',o.partner), res_id=act_id.id, context=context)
93             #translate act window tooltips
94             act_window_ids = act_window_obj.search(cr, uid, [('help','ilike','Customer')])
95             for act_id in act_window_obj.browse(cr ,uid, act_window_ids, context=context):
96                 act_ref = 'ir.actions.act_window' + ',' + 'help'
97                 self.make_translations(cr, uid, ids, act_ref, 'model', act_id.help, _case_insensitive_replace(act_id.help,'Customer',o.partner), res_id=act_id.id, context=context)
98         return {}
99
100 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: