1
# -*- encoding: utf-8 -*-
4
# @author Nicolas Bessi
5
# Copyright (c) 2009 CamptoCamp. All rights reserved.
6
##############################################################################
8
# WARNING: This program as such is intended to be used by professional
9
# programmers who take the whole responsability of assessing all potential
10
# consequences resulting from its eventual inadequacies and bugs
11
# End users who are looking for a ready-to-use solution with commercial
12
# garantees and support are strongly adviced to contract a Free Software
15
# This program is Free Software; you can redistribute it and/or
16
# modify it under the terms of the GNU General Public License
17
# as published by the Free Software Foundation; either version 2
18
# of the License, or (at your option) any later version.
20
# This program is distributed in the hope that it will be useful,
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
# GNU General Public License for more details.
25
# You should have received a copy of the GNU General Public License
26
# along with this program; if not, write to the Free Software
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29
##############################################################################
32
from osv import fields, osv
33
class res_company(osv.osv):
34
"""override company to add currency update"""
36
def _multi_curr_enable(self, cr, uid, ids, field_name, arg, context={}):
37
"check if multi company currency is enabled"
39
if self.pool.get('ir.model.fields').search(cr, uid, [('name', '=', 'company_id'), ('model', '=', 'res.currency')])==[]:
48
def button_refresh_currency(self, cr, uid, ids, context=None):
49
"""Refrech the currency !!for all the company
51
currency_updater_obj = self.pool.get('currency.rate.update')
53
currency_updater_obj.run_currency_update(cr, uid)
59
def _on_change_auto_currency_up(self, cr, uid, id, value):
60
"""handle the activation of the currecny update on compagnies.
61
There are two ways of implementing multi_company currency,
62
the currency is shared or not. The module take care of the two
63
ways. If the currency are shared, you will only be able to set
64
auto update on one company, this will avoid to have unusefull cron
66
If yours currency are not share you will be able to activate the
67
auto update on each separated company"""
73
enable = self.browse(cr, uid, id).multi_company_currency_enable
74
compagnies = self.search(cr, uid, [])
77
# this statement is here beacaus we do no want to save in case of error
78
self.write(cr, uid, id,{'auto_currency_up':value})
79
for comp in compagnies :
80
if self.browse(cr, uid, comp).auto_currency_up:
83
self.pool.get('currency.rate.update').save_cron(
86
{'active':activate_cron}
90
for comp in compagnies :
91
if comp != id and not enable:
92
if self.browse(cr, uid, comp).multi_company_currency_enable:
93
#we ensure taht we did not have write a true value
94
self.write(cr, uid, id,{'auto_currency_up':False})
97
'auto_currency_up':False
102
'message': 'Yon can not activate auto currency '+\
103
'update on more thant one company with this '+
104
'multi company configuration'
107
self.write(cr, uid, id,{'auto_currency_up':value})
108
for comp in compagnies :
109
if self.browse(cr, uid, comp).auto_currency_up:
111
self.pool.get('currency.rate.update').save_cron(
114
{'active':activate_cron}
120
def _on_change_intervall(self, cr, uid, id, interval) :
121
###Function that will update the cron
123
self.pool.get('currency.rate.update').save_cron(
126
{'interval_type':interval}
128
compagnies = self.search(cr, uid, [])
129
for comp in compagnies :
130
self.write(cr, uid, comp,{'interval_type':interval})
133
_inherit = "res.company"
135
### activate the currency update
136
'auto_currency_up': fields.boolean('Automatical update of the currency this company'),
137
'services_to_use' : fields.one2many(
138
'currency.rate.update.service',
140
'Currency update services'
142
###predifine cron frequence
143
'interval_type': fields.selection(
146
('weeks', 'Week(s)'),
147
('months', 'Month(s)')
149
'Currency update frequence',
150
help="""changing this value will
151
also affect other compagnies"""
153
###function field that allows to know the
154
###mutli company currency implementation
155
'multi_company_currency_enable' : fields.function(
159
string="Multi company currency",
160
help='if this case is not check you can'+\
161
' not set currency is active on two company'