[IMP] wip
bzr revid: nicolas.vanhoren@openerp.com-20101118093412-czjcmcqupngfqjnt
This commit is contained in:
parent
b8551a5fcc
commit
d5debf686f
|
@ -18,3 +18,6 @@ bin/python2.6
|
|||
build/
|
||||
bin/yolk
|
||||
bin/pil*.py
|
||||
.project
|
||||
.pydevproject
|
||||
.settings
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
"""
|
||||
A module to store some configuration parameters relative to a whole database.
|
||||
"""
|
||||
|
||||
from osv import osv,fields
|
||||
|
||||
class ir_config_parameter(osv.osv):
|
||||
""" An osv to old configuration parameters for a given database.
|
||||
|
||||
To be short, it's just a global dictionnary of strings stored in a table. """
|
||||
|
||||
_name = 'ir.config_parameter'
|
||||
|
||||
_columns = {
|
||||
# The key of the configuration parameter.
|
||||
'key': fields.char('Key', size=256, required=True, select=1),
|
||||
# The value of the configuration parameter.
|
||||
'value': fields.text('Value', required=True),
|
||||
}
|
||||
|
||||
_sql_constraints = [
|
||||
('key_uniq', 'unique (key)', 'Key must be unique.')
|
||||
]
|
||||
|
||||
def get_param(self, cr, uid, key, context=None):
|
||||
""" Get the value of a parameter.
|
||||
|
||||
@param key: The key of the parameter.
|
||||
@type key: string
|
||||
@return: The value of the parameter, False if it does not exist.
|
||||
@rtype: string
|
||||
"""
|
||||
ids = self.search(cr, uid, [('key','=',key)], context=context)
|
||||
if not ids:
|
||||
return False
|
||||
param = self.browse(cr, uid, ids[0], context=context)
|
||||
value = param.value
|
||||
return value
|
||||
|
||||
def set_param(self, cr, uid, key, value, context=None):
|
||||
""" Set the value of a parameter.
|
||||
|
||||
@param key: The key of the parameter.
|
||||
@type key: string
|
||||
@param value: The value of the parameter.
|
||||
@type value: string
|
||||
@return: Return the previous value of the parameter of False if it did
|
||||
not existed.
|
||||
@rtype: string
|
||||
"""
|
||||
ids = self.search(cr, uid, [('key','=',key)], context=context)
|
||||
if ids:
|
||||
param = self.browse(cr, uid, ids[0], context=context)
|
||||
old = param.value
|
||||
self.write(cr, uid, ids, {'value': value}, context=context)
|
||||
return old
|
||||
else:
|
||||
self.create(cr, uid, {'key': key, 'value': value}, context=context)
|
||||
return False
|
||||
|
||||
ir_config_parameter()
|
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
"""
|
||||
A module to handle a database UUID. That uuid will be stored in the osv
|
||||
"ir.config_parameter" with key "database.uuid".
|
||||
"""
|
||||
|
||||
from osv import osv
|
||||
import uuid
|
||||
|
||||
class uuid_saver(osv.osv_memory):
|
||||
""" An empty osv memory to init the uuid of the database the first it is
|
||||
used. """
|
||||
|
||||
_name = 'maintenance.database_uuid_saver'
|
||||
|
||||
def init(self, cr):
|
||||
""" Checks that the database uuid was already created and create it if
|
||||
it not the case. """
|
||||
params = self.pool.get('ir.config_parameter')
|
||||
uniq = params.get_param(cr, 1, 'database.uuid')
|
||||
if not uniq:
|
||||
uniq = str(uuid.uuid1())
|
||||
params.set_param(cr, 1, 'database.uuid', uniq)
|
||||
|
||||
uuid_saver()
|
||||
|
|
@ -22,11 +22,13 @@
|
|||
from osv import osv, fields
|
||||
import time
|
||||
import netsvc
|
||||
|
||||
from tools.misc import ustr
|
||||
from tools.translate import _
|
||||
import tools.maintenance as tm
|
||||
|
||||
_nlogger = netsvc.Logger()
|
||||
_CHAN = __name__.split()[-1]
|
||||
|
||||
class maintenance_contract(osv.osv):
|
||||
_name = "maintenance.contract"
|
||||
_description = "Maintenance Contract"
|
||||
|
@ -35,6 +37,7 @@ class maintenance_contract(osv.osv):
|
|||
return [contract for contract in self.browse(cr, uid, self.search(cr, uid, [])) if contract.state == 'valid']
|
||||
|
||||
def status(self, cr, uid):
|
||||
""" Method called by the client to check availability of maintenance contract. """
|
||||
contracts = self._get_valid_contracts(cr, uid)
|
||||
return {
|
||||
'status': "full" if contracts else "none" ,
|
||||
|
@ -42,6 +45,7 @@ class maintenance_contract(osv.osv):
|
|||
}
|
||||
|
||||
def send(self, cr, uid, tb, explanations, remarks=None):
|
||||
""" Method called by the client to send a problem to the maintenance server. """
|
||||
if not remarks:
|
||||
remarks = ""
|
||||
|
||||
|
@ -63,7 +67,7 @@ class maintenance_contract(osv.osv):
|
|||
|
||||
origin = 'client'
|
||||
dbuuid = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
crm_case_id = rc.submit({
|
||||
crm_case_id = rc.submit_6({
|
||||
'contract_name': contract_name,
|
||||
'tb': tb,
|
||||
'explanations': explanations,
|
||||
|
@ -73,11 +77,11 @@ class maintenance_contract(osv.osv):
|
|||
'dbuuid': dbuuid})
|
||||
|
||||
except tm.RemoteContractException, rce:
|
||||
netsvc.Logger().notifyChannel('maintenance', netsvc.LOG_INFO, rce)
|
||||
_nlogger.notifyChannel(_CHAN, netsvc.LOG_INFO, rce)
|
||||
except osv.except_osv:
|
||||
raise
|
||||
except:
|
||||
pass # don't want to throw exceptions in exception handler
|
||||
pass # we don't want to throw exceptions in an exception handler
|
||||
|
||||
if not crm_case_id:
|
||||
return False
|
||||
|
|
|
@ -82,7 +82,7 @@ def remote_contract(cr, uid, contract_id):
|
|||
_logger.exception("Exception")
|
||||
raise RemoteContractException("Unable to contact the migration server")
|
||||
|
||||
info = ro.check_contract({
|
||||
info = ro.check_contract_6({
|
||||
"contract_name": contract_id,
|
||||
"dbuuid": dbuuid,
|
||||
"dbname": cr.dbname})
|
||||
|
|
Loading…
Reference in New Issue