diff --git a/.bzrignore b/.bzrignore index 5581ee20f94..f67a6e2c6b6 100644 --- a/.bzrignore +++ b/.bzrignore @@ -18,3 +18,6 @@ bin/python2.6 build/ bin/yolk bin/pil*.py +.project +.pydevproject +.settings diff --git a/bin/addons/base/__init__.py b/bin/addons/base/__init__.py index bf315934c6d..fe483c40602 100644 --- a/bin/addons/base/__init__.py +++ b/bin/addons/base/__init__.py @@ -22,7 +22,7 @@ import ir import module import res -import maintenance +import publisher_warranty # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/addons/base/__openerp__.py b/bin/addons/base/__openerp__.py index d57a8878199..eefaf9f4442 100644 --- a/bin/addons/base/__openerp__.py +++ b/bin/addons/base/__openerp__.py @@ -71,11 +71,12 @@ 'res/ir_property_view.xml', 'security/base_security.xml', - 'maintenance/maintenance_view.xml', + 'publisher_warranty/publisher_warranty_view.xml', 'security/ir.model.access.csv', 'res/res_widget_view.xml', 'res/res_widget_data.xml', + 'publisher_warranty/publisher_warranty_data.xml', ], 'demo_xml': [ 'base_demo.xml', diff --git a/bin/addons/base/ir/__init__.py b/bin/addons/base/ir/__init__.py index 145a167fdc2..9b4eb96df5f 100644 --- a/bin/addons/base/ir/__init__.py +++ b/bin/addons/base/ir/__init__.py @@ -34,6 +34,7 @@ import ir_exports import workflow import ir_rule import wizard +import ir_config_parameter import osv_memory_autovacuum # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/bin/addons/base/ir/ir_config_parameter.py b/bin/addons/base/ir/ir_config_parameter.py new file mode 100644 index 00000000000..b1688b9a669 --- /dev/null +++ b/bin/addons/base/ir/ir_config_parameter.py @@ -0,0 +1,101 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# +# 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 . +# +############################################################################## +""" +A module to store some configuration parameters relative to a whole database. +""" + +from osv import osv,fields +import uuid +import datetime +from tools import misc + +""" +A dictionary holding some configuration parameters to be initialized when the database is created. +""" +_default_parameters = { + "database.uuid": lambda: str(uuid.uuid1()), + "database.create_date": lambda: datetime.datetime.now().strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT), +} + +class ir_config_parameter(osv.osv): + """ An osv to old configuration parameters for a given database. + + To be short, it's just a global dictionary 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 init(self, cr): + """ + Initializes the parameters listed in _default_parameters. + """ + for key, func in _default_parameters.iteritems(): + ids = self.search(cr, 1, [('key','=',key)]) + if not ids: + self.set_param(cr, 1, key, func()) + + 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() diff --git a/bin/addons/base/ir/ir_cron.py b/bin/addons/base/ir/ir_cron.py index 7e5a73b4aba..391833d2fbe 100644 --- a/bin/addons/base/ir/ir_cron.py +++ b/bin/addons/base/ir/ir_cron.py @@ -144,7 +144,8 @@ class ir_cron(osv.osv, netsvc.Agent): def restart(self, dbname): self.cancel(dbname) - self._poolJobs(dbname) + # Reschedule cron processing job asap, but not in the current thread + self.setAlarm(self._poolJobs, time.time(), dbname, dbname) def create(self, cr, uid, vals, context=None): res = super(ir_cron, self).create(cr, uid, vals, context=context) diff --git a/bin/addons/base/maintenance/maintenance.py b/bin/addons/base/maintenance/maintenance.py deleted file mode 100644 index 389d915512f..00000000000 --- a/bin/addons/base/maintenance/maintenance.py +++ /dev/null @@ -1,206 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# OpenERP, Open Source Management Solution -# Copyright (C) 2004-2009 Tiny SPRL (). -# -# 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 . -# -############################################################################## - -from osv import osv, fields -import pooler -import time -import netsvc - -from tools.misc import debug -from tools.misc import ustr -from tools.translate import _ -import tools.maintenance as tm - -class maintenance_contract_module(osv.osv): - _name ="maintenance.contract.module" - _description = "maintenance contract modules" - _columns = { - 'name' : fields.char('Name', size=128, required=True), - 'version': fields.char('Version', size=64,), - } - -maintenance_contract_module() - -class maintenance_contract(osv.osv): - _name = "maintenance.contract" - _description = "Maintenance Contract" - - def _get_valid_contracts(self, cr, uid): - return [contract for contract in self.browse(cr, uid, self.search(cr, uid, [])) if contract.state == 'valid'] - - def status(self, cr, uid): - covered_modules, uncovered_modules = set(), set() - - status = 'none' - for contract in self._get_valid_contracts(cr, uid): - covered_modules.update([m.name for m in contract.module_ids]) - - if covered_modules: - modobj = self.pool.get('ir.module.module') - modids = modobj.search(cr, uid, [('state', '=', 'installed')]) - uncovered_modules = set(m.name for m in modobj.browse(cr, uid, modids)) - covered_modules - status = ['full', 'partial'][len(uncovered_modules) > 0] - - return { - 'status': status, - 'uncovered_modules': list(uncovered_modules), - } - - def send(self, cr, uid, tb, explanations, remarks=None): - status = self.status(cr, uid) - if status['status'] != 'full': - raise osv.except_osv(_('Error'), _("Your can't submit bug reports due to uncovered modules: %s") % (', '.join(status['uncovered_modules']),)) - - dbmsg = _('This error occurs on database %s') % (cr.dbname,) - if not remarks: - remarks = dbmsg - else: - remarks += '\n\n-----\n' + dbmsg - - valid_contracts = self._get_valid_contracts(cr, uid) - - crm_case_id = None - rc = None - try: - for contract in valid_contracts: - rc = tm.remote_contract(contract.name, contract.password) - if rc.id: - break - rc = None - - if not rc: - raise osv.except_osv(_('Error'), _('Unable to find a valid contract')) - - origin = 'client' - crm_case_id = rc.submit(rc.id, tb, explanations, remarks or '', origin) - - except tm.RemoteContractException, rce: - netsvc.Logger().notifyChannel('maintenance', netsvc.LOG_INFO, rce) - except osv.except_osv: - raise - except: - pass - - cid = rc and rc.name or valid_contracts[0].name - try: - # as backup, put it also in another database... - import urllib - args = urllib.urlencode({ - 'contract_id': cid, - 'crm_case_id': crm_case_id or 0, - 'explanation': explanations, - 'remark': remarks or '', - 'tb': tb, - }) - uo = urllib.urlopen('http://www.openerp.com/scripts/maintenance.php', args) - submit_result = uo.read() - debug(submit_result) - uo.close() - except: - if not crm_case_id: - # TODO schedule a retry (ir.cron) - return False - return True - - def _valid_get(self, cr, uid, ids, field_name, arg, context=None): - res = {} - for contract in self.browse(cr, uid, ids, context=context): - res[contract.id] = ("unvalid", "valid")[contract.date_stop >= time.strftime('%Y-%m-%d')] - return res - - _columns = { - 'name' : fields.char('Contract ID', size=256, required=True, readonly=True), - 'password' : fields.char('Password', size=64, invisible=True, required=True, readonly=True), - 'date_start' : fields.date('Starting Date', readonly=True), - 'date_stop' : fields.date('Ending Date', readonly=True), - 'module_ids' : fields.many2many('maintenance.contract.module', 'maintenance_contract_module_rel', 'contract_id', 'module_id', 'Covered Modules', readonly=True), - 'state' : fields.function(_valid_get, method=True, string="State", type="selection", selection=[('valid', 'Valid'),('unvalid', 'Unvalid')], readonly=True), - 'kind' : fields.selection([('full', 'Full'),('partial', 'Partial')], 'Kind', required=True, readonly=True), - } - _defaults = { - 'password' : lambda obj,cr,uid,context={} : '', - } - _sql_constraints = [ - ('uniq_name', 'unique(name)', "Your maintenance contract is already subscribed in the system !") - ] - -maintenance_contract() - - -class maintenance_contract_wizard(osv.osv_memory): - _name = 'maintenance.contract.wizard' - - _columns = { - 'name' : fields.char('Contract ID', size=256, required=True ), - 'password' : fields.char('Password', size=64, required=True), - 'state' : fields.selection([('draft', 'Draft'),('validated', 'Validated'),('unvalidated', 'Unvalidated')], 'States'), - } - - _defaults = { - 'state' : lambda *a: 'draft', - } - - def action_validate(self, cr, uid, ids, context=None): - if not ids: - return False - - module_proxy = self.pool.get('ir.module.module') - module_ids = module_proxy.search(cr, uid, [('state', '=', 'installed')]) - modules = module_proxy.read(cr, uid, module_ids, ['name', 'installed_version']) - - contract = self.read(cr, uid, ids, ['name', 'password'])[0] - - try: - contract_info = tm.remote_contract(contract['name'], contract['password'], modules) - except tm.RemoteContractException, rce: - raise osv.except_osv(_('Error'), ustr(rce)) - - is_ok = contract_info['status'] in ('partial', 'full') - if is_ok: - module_ids = [] - if contract_info['modules_with_contract']: - for name, version in contract_info['modules_with_contract']: - contract_module = self.pool.get('maintenance.contract.module') - res = contract_module.search(cr, uid, [('name', '=', name),('version', '=', version)]) - if not res: - id = contract_module.create(cr, uid, { 'name' : name, 'version' : version } ) - else: - id = res[0] - module_ids.append(id) - - self.pool.get('maintenance.contract').create( - cr, - uid, { - 'name' : contract['name'], - 'password' : contract['password'], - 'date_start' : contract_info['date_from'], - 'date_stop' : contract_info['date_to'], - 'kind' : contract_info['status'], - 'module_ids' : [(6,0,module_ids)], - } - ) - - return self.write(cr, uid, ids, {'state' : ('unvalidated', 'validated')[is_ok] }, context=context) - -maintenance_contract_wizard() - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/bin/addons/base/maintenance/maintenance_security.xml b/bin/addons/base/maintenance/maintenance_security.xml deleted file mode 100644 index 04b7d6dc2cf..00000000000 --- a/bin/addons/base/maintenance/maintenance_security.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/bin/addons/base/maintenance/maintenance_view.xml b/bin/addons/base/maintenance/maintenance_view.xml deleted file mode 100644 index 836344a52df..00000000000 --- a/bin/addons/base/maintenance/maintenance_view.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - - - - maintenance.contract.tree - maintenance.contract - tree - - - - - - - - - - - - maintenance.contract.form - maintenance.contract - form - -
- - - - - - - - - - - - - - - -
- - - maintenance.contract.search - maintenance.contract - search - - - - - - - - - - - maintenance.contract.calendar - maintenance.contract - calendar - - - - - - - - - - Maintenance Contracts - ir.actions.act_window - maintenance.contract - form - tree,form,calendar - - - - - - - - - maintenance.contract.add.wizard - maintenance.contract.wizard - form - -
- - - - - - - - - - - - - - -