[IMP] Rather stable version
bzr revid: nicolas.vanhoren@openerp.com-20101122151015-vnrk4gf0v6bn0zxi
This commit is contained in:
parent
9bb58b85e2
commit
e98ba5b6fd
|
@ -18,11 +18,14 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
"""
|
||||
Module to handle publisher warranty contracts as well as notifications from
|
||||
OpenERP.
|
||||
"""
|
||||
|
||||
from osv import osv, fields
|
||||
import logging
|
||||
from tools.translate import _
|
||||
import tools.maintenance as tm
|
||||
import urllib
|
||||
from tools.safe_eval import safe_eval
|
||||
import pooler
|
||||
|
@ -32,9 +35,18 @@ import release
|
|||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class publisher_warranty_contract(osv.osv):
|
||||
"""
|
||||
Osv representing a publisher warranty contract.
|
||||
"""
|
||||
_name = "publisher_warranty.contract"
|
||||
|
||||
def _get_valid_contracts(self, cr, uid):
|
||||
"""
|
||||
Return the list of the valid contracts encoded in the system.
|
||||
|
||||
@return: A list of contracts
|
||||
@rtype: list of publisher_warranty.contract browse records
|
||||
"""
|
||||
return [contract for contract in self.browse(cr, uid, self.search(cr, uid, []))
|
||||
if contract.state == 'valid']
|
||||
|
||||
|
@ -57,18 +69,27 @@ class publisher_warranty_contract(osv.osv):
|
|||
valid_contract = valid_contracts[0]
|
||||
|
||||
try:
|
||||
rc = tm.remote_contract(cr, uid, valid_contract.name)
|
||||
|
||||
origin = 'client'
|
||||
dbuuid = self.pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
crm_case_id = rc.submit_6({
|
||||
'contract_name': valid_contract.name,
|
||||
|
||||
msg = {'contract_name': valid_contract.name,
|
||||
'tb': tb,
|
||||
'explanations': explanations,
|
||||
'remarks': remarks,
|
||||
'origin': origin,
|
||||
'dbname': cr.dbname,
|
||||
'dbuuid': dbuuid})
|
||||
'dbuuid': dbuuid}
|
||||
|
||||
uo = urllib.urlopen(config.get("publisher_warranty_url"),
|
||||
urllib.urlencode({'arg0': msg, "action": "send",}))
|
||||
try:
|
||||
submit_result = uo.read()
|
||||
finally:
|
||||
uo.close()
|
||||
|
||||
result = safe_eval(submit_result)
|
||||
|
||||
crm_case_id = result
|
||||
|
||||
if not crm_case_id:
|
||||
return False
|
||||
|
@ -83,6 +104,10 @@ class publisher_warranty_contract(osv.osv):
|
|||
return True
|
||||
|
||||
def check_validity(self, cr, uid, ids, context={}):
|
||||
"""
|
||||
Check the validity of a publisher warranty contract. This method just call send_ping() but checks
|
||||
some more things, so it can be called from a user interface.
|
||||
"""
|
||||
contract_id = ids[0]
|
||||
contract = self.browse(cr, uid, contract_id)
|
||||
state = contract.state
|
||||
|
@ -97,6 +122,13 @@ class publisher_warranty_contract(osv.osv):
|
|||
_("Please check your publisher warranty contract name and validity."))
|
||||
|
||||
def send_ping(self, cr, uid, ids, cron_mode=True, context={}):
|
||||
"""
|
||||
Send a message to OpenERP's publisher warranty server to check the validity of
|
||||
the contracts, get notifications, etc...
|
||||
|
||||
@param cron_mode: If true, catch all exceptions (appropriate for usage in a cron).
|
||||
@type cron_mode: boolean
|
||||
"""
|
||||
try:
|
||||
try:
|
||||
result = send_ping(cr, uid)
|
||||
|
@ -124,6 +156,14 @@ class publisher_warranty_contract(osv.osv):
|
|||
"interval_type": result["interval_type"],
|
||||
"interval_number": result["interval_number"],
|
||||
})
|
||||
|
||||
self.pool.get('res.log').create(cr, uid,
|
||||
{
|
||||
'name': result["message"],
|
||||
'res_model': "Maintenance Notifications",
|
||||
},
|
||||
context=context
|
||||
)
|
||||
except:
|
||||
_logger.debug("Exception while interpreting the result of a ping", exc_info=1)
|
||||
if cron_mode:
|
||||
|
@ -166,10 +206,18 @@ class maintenance_contract(osv.osv_memory):
|
|||
maintenance_contract()
|
||||
|
||||
class publisher_warranty_contract_wizard(osv.osv_memory):
|
||||
"""
|
||||
A wizard osv to help people entering a publisher warranty contract.
|
||||
"""
|
||||
_name = 'publisher_warranty.contract.wizard'
|
||||
|
||||
_columns = {
|
||||
'name' : fields.char('Contract Name', size=256, required=True ),
|
||||
'state' : fields.selection([("draft", "Draft"), ("finished", "Finished")])
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
"state": "draft",
|
||||
}
|
||||
|
||||
def action_validate(self, cr, uid, ids, context=None):
|
||||
|
@ -191,11 +239,17 @@ class publisher_warranty_contract_wizard(osv.osv_memory):
|
|||
|
||||
contract_osv.check_validity(cr, uid, [contract_id])
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
self.write(cr, uid, ids, {"state": "finished"})
|
||||
|
||||
return True
|
||||
|
||||
|
||||
publisher_warranty_contract_wizard()
|
||||
|
||||
def send_ping(cr, uid):
|
||||
"""
|
||||
Utility method to send a publisher warranty ping.
|
||||
"""
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
|
|
|
@ -91,14 +91,23 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Add Publisher Warranty Contract" col="2">
|
||||
<group col="1">
|
||||
<separator string="Add Publisher Warranty Contract" />
|
||||
<field name="name" width="250" />
|
||||
</group>
|
||||
<group colspan="4">
|
||||
<button type="object" string="_Cancel" icon="gtk-cancel" special="cancel"/>
|
||||
<button type="object" string="_Validate" icon="gtk-apply" name="action_validate"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<group states="draft">
|
||||
<group col="1">
|
||||
<separator string="Add Publisher Warranty Contract" />
|
||||
<field name="name" width="250" />
|
||||
</group>
|
||||
<group colspan="4">
|
||||
<button type="object" string="Cancel" icon="gtk-cancel" special="cancel"/>
|
||||
<button type="object" string="Validate" icon="gtk-apply" name="action_validate"/>
|
||||
</group>
|
||||
</group>
|
||||
<group states="finished">
|
||||
<label string="The contract was correctly added." colspan="4" />
|
||||
<group colspan="4">
|
||||
<button type="object" string="Ok" icon="gtk-apply" special="cancel"/>
|
||||
</group>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
@ -116,6 +125,19 @@
|
|||
action="action_publisher_warranty_contract_add_wizard"
|
||||
id="menu_publisher_warranty_contract_add"
|
||||
parent="publisher_warranty" />
|
||||
|
||||
<record id="publisher_warranty_res_log_act_window" model="ir.actions.act_window">
|
||||
<field name="name">Notifications</field>
|
||||
<field name="res_model">res.log</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="context">{'search_default_my': 1}</field>
|
||||
<field name="domain">[('res_model','=','Maintenance Notifications')]</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
action="publisher_warranty_res_log_act_window"
|
||||
id="menu_publisher_warranty_res_log"
|
||||
parent="publisher_warranty"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
# -*- 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import xmlrpclib
|
||||
import config
|
||||
import pooler
|
||||
|
||||
|
||||
class RemoteConnectionException(Exception):
|
||||
pass
|
||||
|
||||
class RemoteConnection:
|
||||
|
||||
def __init__(self, server, db, login, password):
|
||||
self._server = server.strip()
|
||||
if not self._server.endswith("/"):
|
||||
self._server += "/"
|
||||
self._db = db
|
||||
self._login = login
|
||||
self._password = password
|
||||
|
||||
rpc = xmlrpclib.ServerProxy(self._server + "xmlrpc/common")
|
||||
try:
|
||||
self._userid = rpc.login(self._db, self._login, self._password)
|
||||
except:
|
||||
raise RemoteConnectionException("Unable to contact the remote server")
|
||||
|
||||
if not self._userid:
|
||||
raise RemoteConnectionException("Unable to contact the remote server")
|
||||
|
||||
self._rpc = xmlrpclib.ServerProxy(self._server + "xmlrpc/object")
|
||||
|
||||
def get_remote_object(self, object):
|
||||
return RemoteObject(self, object)
|
||||
|
||||
class RemoteObject(object):
|
||||
|
||||
def __init__(self, connection, object):
|
||||
self._c = connection
|
||||
self._object = object
|
||||
|
||||
def __getattr__(self, fun):
|
||||
def remote_call(*args, **kwargs):
|
||||
return self._c._rpc.execute(self._c._db, self._c._userid,
|
||||
self._c._password, self._object, fun, *args, **kwargs)
|
||||
return remote_call
|
||||
|
||||
def __getitem__(self, item):
|
||||
return getattr(self, item)
|
||||
|
||||
class RemoteContractException(Exception): pass
|
||||
|
||||
def remote_contract(cr, uid, contract_id):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
|
||||
try:
|
||||
ro = RemoteConnection(config.config.get("maintenance_server"), config.config.get("maintenance_db"),
|
||||
config.config.get("maintenance_login"), config.config.get("maintenance_password")
|
||||
).get_remote_object('maintenance.maintenance')
|
||||
except:
|
||||
raise RemoteContractException("Unable to contact the migration server")
|
||||
|
||||
info = ro.check_contract_6({
|
||||
"contract_name": contract_id,
|
||||
"dbuuid": dbuuid,
|
||||
"dbname": cr.dbname})
|
||||
for n in info:
|
||||
setattr(ro, n, info[n])
|
||||
|
||||
return ro
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue